[NO ISSUE][TEST] Change OptimiserTest to compare full plans

- user model changes: no
- storage format changes: no
- interface changes: no

Details:
- Change all the previous physical plans to full plans.

Ext-ref: MB-64874
Change-Id: I15db7717fbebae7a4966e91a997f381a1be9d01b
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/19319
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Ali Alsuliman <ali.al.solaiman@gmail.com>
diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestHelper.java b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestHelper.java
index 8d7f188..6688ad8 100644
--- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestHelper.java
+++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestHelper.java
@@ -67,6 +67,8 @@
     private static final String[] TEST_DIRS = new String[] { "txnLogDir", "IODevice", "spill_area", "config" };
     private static final String PATTERN_VAR_ID_PREFIX = "\\$\\$";
     private static final Pattern PATTERN_VAR_ID = Pattern.compile(PATTERN_VAR_ID_PREFIX + "(\\d+)");
+    private static final Map<Integer, Integer> EXPECTED = new HashMap<>();
+    private static final Map<Integer, Integer> ACTUAL = new HashMap<>();
     private static final ObjectMapper SORTED_MAPPER = new ObjectMapper();
     private static final ObjectWriter PRETTY_SORTED_WRITER;
 
@@ -314,10 +316,20 @@
         return objectMapper;
     }
 
+    public static void comparePlansWithoutCost(List<String> linesExpected, List<String> linesActual, File queryFile)
+            throws Exception {
+        comparePlans(linesExpected, linesActual, queryFile, TestHelper::planLineEqualsWithoutCosts);
+    }
+
     public static void comparePlans(List<String> linesExpected, List<String> linesActual, File queryFile)
             throws Exception {
-        int varBaseExpected = findBaseVarId(linesExpected);
-        int varBaseActual = findBaseVarId(linesActual);
+        comparePlans(linesExpected, linesActual, queryFile, TestHelper::planLineEquals);
+    }
+
+    public static void comparePlans(List<String> linesExpected, List<String> linesActual, File queryFile,
+            LineComparator lineComparator) throws Exception {
+        int varBaseExpected = findBaseVarId(linesExpected, EXPECTED);
+        int varBaseActual = findBaseVarId(linesActual, ACTUAL);
 
         Iterator<String> readerExpected = linesExpected.iterator();
         Iterator<String> readerActual = linesActual.iterator();
@@ -330,7 +342,7 @@
             }
             lineActual = readerActual.next();
 
-            if (!planLineEquals(lineExpected, varBaseExpected, lineActual, varBaseActual)) {
+            if (!lineComparator.equalLines(lineExpected, varBaseExpected, lineActual, varBaseActual)) {
                 throw TestExecutor.createLineChangedException(queryFile, lineExpected, lineActual, num);
             }
             ++num;
@@ -343,13 +355,20 @@
 
     private static boolean planLineEquals(String lineExpected, int varIdBaseExpected, String lineActual,
             int varIdBaseActual) {
-        String lineExpectedNorm = normalizePlanLine(lineExpected, varIdBaseExpected);
-        String lineActualNorm = normalizePlanLine(lineActual, varIdBaseActual);
+        String lineExpectedNorm = normalizePlanLine(lineExpected, varIdBaseExpected, EXPECTED);
+        String lineActualNorm = normalizePlanLine(lineActual, varIdBaseActual, ACTUAL);
+        return lineExpectedNorm.equals(lineActualNorm);
+    }
+
+    private static boolean planLineEqualsWithoutCosts(String lineExpected, int varIdBaseExpected, String lineActual,
+            int varIdBaseActual) {
+        String lineExpectedNorm = normalizePlanLine(removeCost(lineExpected), varIdBaseExpected, EXPECTED);
+        String lineActualNorm = normalizePlanLine(removeCost(lineActual), varIdBaseActual, ACTUAL);
         return lineExpectedNorm.equals(lineActualNorm);
     }
 
     // rewrite variable ids in given plan line: $$varId -> $$(varId-varIdBase)
-    private static String normalizePlanLine(String line, int varIdBase) {
+    private static String normalizePlanLine(String line, int varIdBase, Map<Integer, Integer> varMap) {
         if (varIdBase == Integer.MAX_VALUE) {
             // plan did not contain any variables -> no rewriting necessary
             return line;
@@ -358,23 +377,43 @@
         StringBuilder sb = new StringBuilder(line.length());
         while (m.find()) {
             int varId = Integer.parseInt(m.group(1));
-            int newVarId = varId - varIdBase;
+            Integer newVarId = varMap.get(varId);
+            if (newVarId == null) {
+                throw new IllegalStateException("no new var id mapped for " + varId);
+            }
             m.appendReplacement(sb, PATTERN_VAR_ID_PREFIX + newVarId);
         }
         m.appendTail(sb);
         return sb.toString();
     }
 
-    private static int findBaseVarId(Collection<String> plan) {
+    private static int findBaseVarId(Collection<String> plan, Map<Integer, Integer> map) {
         int varIdBase = Integer.MAX_VALUE;
+        map.clear();
+        int counter = 1;
         Matcher m = PATTERN_VAR_ID.matcher("");
         for (String line : plan) {
             m.reset(line);
             while (m.find()) {
                 int varId = Integer.parseInt(m.group(1));
+                Integer previouslyMapped = map.putIfAbsent(varId, counter);
+                if (previouslyMapped == null) {
+                    counter++;
+                }
                 varIdBase = Math.min(varIdBase, varId);
             }
         }
         return varIdBase;
     }
+
+    private static String removeCost(String originalStr) {
+        int i = originalStr.indexOf(" [cardinality: ");
+        return i >= 0 ? originalStr.substring(0, i) : originalStr;
+    }
+
+    @FunctionalInterface
+    private interface LineComparator {
+        boolean equalLines(String lineExpected, int varIdBaseExpected, String lineActual, int varIdBaseActual);
+
+    }
 }
diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/optimizer/OptimizerTest.java b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/optimizer/OptimizerTest.java
index 6a85e0c..922a4c9 100644
--- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/optimizer/OptimizerTest.java
+++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/optimizer/OptimizerTest.java
@@ -34,6 +34,8 @@
 import org.apache.asterix.compiler.provider.ILangCompilationProvider;
 import org.apache.asterix.om.base.IAObject;
 import org.apache.asterix.test.common.TestHelper;
+import org.apache.asterix.translator.ExecutionPlans;
+import org.apache.asterix.translator.SessionConfig;
 import org.apache.commons.io.FileUtils;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.api.client.IHyracksClientConnection;
@@ -83,14 +85,17 @@
                     (ICcApplicationContext) integrationUtil.cc.getApplicationContext(), hcc, new StringReader(query),
                     plan, provider, statementExecutorFactory, storageComponentProvider);
             asterix.setStatementParameters(queryParams);
-            asterix.compile(true, false, false, true, true, false, false);
+            asterix.compile(true, false, true, true, false, false, false, SessionConfig.PlanFormat.STRING);
+            ExecutionPlans executionPlans = asterix.getExecutionPlans();
+            String planStr = executionPlans.getOptimizedLogicalPlan();
+            plan.write(planStr);
         } catch (AlgebricksException e) {
             throw new Exception("Compile ERROR for " + queryFile + ": " + e.getMessage(), e);
         }
 
         List<String> linesActual = Files.readAllLines(actualFile.toPath(), StandardCharsets.UTF_8);
         List<String> linesExpected = getExpectedLines();
-        TestHelper.comparePlans(linesExpected, linesActual, queryFile);
+        TestHelper.comparePlansWithoutCost(linesExpected, linesActual, queryFile);
     }
 
     protected List<String> getExpectedLines() throws IOException {
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ASTERIXDB-2402.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ASTERIXDB-2402.plan
index efd14f7..a35120d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ASTERIXDB-2402.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ASTERIXDB-2402.plan
@@ -1,182 +1,346 @@
+distribute result [$$212]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$212])
     -- STREAM_PROJECT  |PARTITIONED|
-      -- SUBPLAN  |PARTITIONED|
-              {
+      subplan {
+                aggregate [$$212] <- [listify($$211)]
                 -- AGGREGATE  |LOCAL|
+                  assign [$$211] <- [{"channelExecutionTime": $$242, "result": $$243, "BrokerEndpoint": $$BrokerEndpoint}]
                   -- ASSIGN  |LOCAL|
-                    -- MICRO_PRE_CLUSTERED_GROUP_BY[$$215]  |LOCAL|
-                            {
+                    group by ([$$BrokerEndpoint := $$215]) decor ([$$242 := $$244; $$243 := $$245]) {
+                              aggregate [] <- []
                               -- AGGREGATE  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                            }
+                           }
+                    -- MICRO_PRE_CLUSTERED_GROUP_BY[$$215]  |LOCAL|
+                      order (ASC, $$215)
                       -- MICRO_STABLE_SORT [$$215(ASC)]  |LOCAL|
+                        assign [$$215] <- [$$sub.getField("BrokerEndpoint")]
                         -- ASSIGN  |LOCAL|
+                          unnest $$sub <- scan-collection($$204)
                           -- UNNEST  |LOCAL|
-                            -- SUBPLAN  |LOCAL|
-                                    {
+                            subplan {
+                                      aggregate [$$204] <- [listify($$203)]
                                       -- AGGREGATE  |LOCAL|
+                                        assign [$$203] <- [{"sub": $$sub}]
                                         -- ASSIGN  |LOCAL|
+                                          unnest $$sub <- scan-collection($$241)
                                           -- UNNEST  |LOCAL|
+                                            nested tuple source
                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                    }
+                                   }
+                            -- SUBPLAN  |LOCAL|
+                              nested tuple source
                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-              }
+             }
+      -- SUBPLAN  |PARTITIONED|
+        project ([$$245, $$244, $$241])
         -- STREAM_PROJECT  |PARTITIONED|
+          commit
           -- COMMIT  |PARTITIONED|
+            project ([$$245, $$244, $$241, $$199])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                insert into channels.EmergenciesNearMeChannelResults from record: $$216 partitioned by [$$199]
                 -- INSERT_DELETE  |PARTITIONED|
+                  exchange
                   -- HASH_PARTITION_EXCHANGE [$$199]  |PARTITIONED|
+                    assign [$$245, $$244, $$241, $$199] <- [$$216.getField("result"), $$216.getField("channelExecutionTime"), $$216.getField("brokerSubIds"), $$216.getField(0)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$216])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$216] <- [cast(check-unknown(object-merge-ignore-duplicates($$197, {"resultId": create-uuid()})))]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$197])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$197] <- [{"result": $$result, "channelExecutionTime": current-datetime(), "channelSubId": $$251, "deliveryTime": current-datetime(), "brokerSubIds": $$196}]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$196, $$result, $$251])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- PRE_CLUSTERED_GROUP_BY[$$252]  |PARTITIONED|
-                                          {
+                                  group by ([$$254 := $$252]) decor ([$$result; $$251]) {
+                                            aggregate [$$196] <- [listify({"BrokerEndPoint": $$238, "brokerSubId": $$223})]
                                             -- AGGREGATE  |LOCAL|
+                                              select (not(is-missing($$253)))
                                               -- STREAM_SELECT  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                         }
+                                  -- PRE_CLUSTERED_GROUP_BY[$$252]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$252)
                                       -- STABLE_SORT [$$252(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$252]  |PARTITIONED|
+                                          project ([$$result, $$251, $$238, $$223, $$253, $$252])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              left outer join (eq($$222, $$251))
                                               -- HYBRID_HASH_JOIN [$$251][$$222]  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  running-aggregate [$$252] <- [create-query-uid()]
                                                   -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                    project ([$$result, $$251])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      unnest $$result <- scan-collection($$176)
                                                       -- UNNEST  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- PRE_CLUSTERED_GROUP_BY[$$313]  |PARTITIONED|
-                                                                  {
+                                                          group by ([$$251 := $$313]) decor ([]) {
+                                                                    aggregate [$$176] <- [listify({"report": $$309, "shelters": $$166})]
                                                                     -- AGGREGATE  |LOCAL|
-                                                                      -- MICRO_PRE_CLUSTERED_GROUP_BY[$$315, $$316]  |LOCAL|
-                                                                              {
+                                                                      group by ([$$247 := $$315; $$248 := $$316]) decor ([$$309; $$310; $$311; $$305; $$306; $$307; $$313; $$308]) {
+                                                                                aggregate [$$166] <- [listify({"location": $$217})]
                                                                                 -- AGGREGATE  |LOCAL|
+                                                                                  select (not(is-missing($$221)))
                                                                                   -- STREAM_SELECT  |LOCAL|
+                                                                                    nested tuple source
                                                                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                              }
+                                                                             }
+                                                                      -- MICRO_PRE_CLUSTERED_GROUP_BY[$$315, $$316]  |LOCAL|
+                                                                        select (and(not(is-missing($$312)), not(is-missing($$314))))
                                                                         -- STREAM_SELECT  |LOCAL|
+                                                                          nested tuple source
                                                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                  }
+                                                                 }
+                                                          -- PRE_CLUSTERED_GROUP_BY[$$313]  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              order (ASC, $$313) (ASC, $$315) (ASC, $$316)
                                                               -- STABLE_SORT [$$313(ASC), $$315(ASC), $$316(ASC)]  |PARTITIONED|
+                                                                exchange
                                                                 -- HASH_PARTITION_EXCHANGE [$$313]  |PARTITIONED|
+                                                                  union ($$304, $$279, $$217) ($$227, $$227, $$305) ($$228, $$228, $$306) ($$229, $$229, $$307) ($$237, $$237, $$308) ($$r, $$r, $$309) ($$u, $$u, $$310) ($$sub, $$sub, $$311) ($$249, $$249, $$312) ($$218, $$218, $$313) ($$250, $$250, $$314) ($$219, $$219, $$315) ($$220, $$220, $$316) ($$302, $$277, $$221)
                                                                   -- UNION_ALL  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      project ([$$304, $$227, $$228, $$229, $$237, $$r, $$u, $$sub, $$249, $$218, $$250, $$219, $$220, $$302])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        select (spatial-intersect($$304, $$229)) retain-untrue ($$221 <- MISSING)
                                                                         -- STREAM_SELECT  |PARTITIONED|
+                                                                          project ([$$218, $$sub, $$227, $$219, $$r, $$228, $$237, $$249, $$220, $$u, $$250, $$229, $$277, $$302, $$304])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            assign [$$304] <- [$$303.getField(1)]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                -- BTREE_SEARCH (channels.Shelters.Shelters)  |PARTITIONED|
+                                                                                left-outer-unnest-map [$$302, $$303] <- index-search("Shelters", 0, "channels", "Shelters", true, false, 1, $$277, 1, $$277, true, true, true)
+                                                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    project ([$$218, $$sub, $$227, $$219, $$r, $$228, $$237, $$249, $$220, $$u, $$250, $$229, $$277])
                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                        split ($$278)
                                                                                         -- SPLIT  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                            project ([$$218, $$sub, $$227, $$219, $$r, $$228, $$237, $$249, $$220, $$u, $$250, $$229, $$273, $$274, $$277, $$278])
                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                              exchange
                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                -- RTREE_SEARCH (channels.Shelters.s_location)  |PARTITIONED|
+                                                                                                left-outer-unnest-map [$$273, $$274, $$275, $$276, $$277, $$278] <- index-search("s_location", 1, "channels", "Shelters", true, true, 4, $$269, $$270, $$271, $$272)
+                                                                                                -- RTREE_SEARCH  |PARTITIONED|
+                                                                                                  exchange
                                                                                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                                    assign [$$269, $$270, $$271, $$272] <- [create-mbr($$229, 2, 0), create-mbr($$229, 2, 1), create-mbr($$229, 2, 2), create-mbr($$229, 2, 3)]
                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                      exchange
                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                        left outer join (and(spatial-intersect($$228, $$229), eq($$220, $$227)))
                                                                                                         -- NESTED_LOOP  |PARTITIONED|
+                                                                                                          exchange
                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                            left outer join (true)
                                                                                                             -- NESTED_LOOP  |PARTITIONED|
+                                                                                                              exchange
                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                assign [$$227] <- [$$sub.getField("param0")]
                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                  exchange
                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                    -- DATASOURCE_SCAN (channels.EmergenciesNearMeChannelChannelSubscriptions)  |PARTITIONED|
+                                                                                                                    data-scan []<-[$$218, $$sub] <- channels.EmergenciesNearMeChannelChannelSubscriptions
+                                                                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                      exchange
                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                        empty-tuple-source
                                                                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                              exchange
                                                                                                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                                                assign [$$249] <- [true]
                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                  select (gt($$237, numeric-subtract(current-datetime(), day_time_duration: {PT10S })))
                                                                                                                   -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                    assign [$$228, $$237] <- [$$r.getField(2), $$r.getField(3)]
                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                      exchange
                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                        -- BTREE_SEARCH (channels.Reports.Reports)  |PARTITIONED|
+                                                                                                                        unnest-map [$$219, $$r] <- index-search("Reports", 0, "channels", "Reports", false, false, 1, $$259, 1, $$259, true, true, true)
+                                                                                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                                                                                          exchange
                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                            order (ASC, $$259)
                                                                                                                             -- STABLE_SORT [$$259(ASC)]  |PARTITIONED|
+                                                                                                                              exchange
                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                project ([$$259])
                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                  exchange
                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                    -- BTREE_SEARCH (channels.Reports.report_time)  |PARTITIONED|
+                                                                                                                                    unnest-map [$$258, $$259] <- index-search("report_time", 0, "channels", "Reports", false, false, 1, $$257, 0, false, true, false)
+                                                                                                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                                                                                                      exchange
                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                        assign [$$257] <- [numeric-subtract(current-datetime(), day_time_duration: {PT10S })]
                                                                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                                                                          empty-tuple-source
                                                                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                          exchange
                                                                                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                                            assign [$$250, $$229] <- [true, $$u.getField(0)]
                                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                                              exchange
                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                -- DATASOURCE_SCAN (channels.UserLocations)  |PARTITIONED|
+                                                                                                                data-scan []<-[$$220, $$u] <- channels.UserLocations
+                                                                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                  exchange
                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                    empty-tuple-source
                                                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      project ([$$279, $$227, $$228, $$229, $$237, $$r, $$u, $$sub, $$249, $$218, $$250, $$219, $$220, $$277])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        select (spatial-intersect($$279, $$229)) retain-untrue ($$221 <- MISSING)
                                                                         -- STREAM_SELECT  |PARTITIONED|
+                                                                          project ([$$218, $$sub, $$227, $$219, $$r, $$228, $$237, $$249, $$220, $$u, $$250, $$229, $$277, $$279])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            assign [$$279] <- [create-point($$273, $$274)]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              project ([$$218, $$sub, $$227, $$219, $$r, $$228, $$237, $$249, $$220, $$u, $$250, $$229, $$273, $$274, $$277])
                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  split ($$278)
                                                                                   -- SPLIT  |PARTITIONED|
+                                                                                    exchange
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                      project ([$$218, $$sub, $$227, $$219, $$r, $$228, $$237, $$249, $$220, $$u, $$250, $$229, $$273, $$274, $$277, $$278])
                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                        exchange
                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                          -- RTREE_SEARCH (channels.Shelters.s_location)  |PARTITIONED|
+                                                                                          left-outer-unnest-map [$$273, $$274, $$275, $$276, $$277, $$278] <- index-search("s_location", 1, "channels", "Shelters", true, true, 4, $$269, $$270, $$271, $$272)
+                                                                                          -- RTREE_SEARCH  |PARTITIONED|
+                                                                                            exchange
                                                                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                              assign [$$269, $$270, $$271, $$272] <- [create-mbr($$229, 2, 0), create-mbr($$229, 2, 1), create-mbr($$229, 2, 2), create-mbr($$229, 2, 3)]
                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                exchange
                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                  left outer join (and(spatial-intersect($$228, $$229), eq($$220, $$227)))
                                                                                                   -- NESTED_LOOP  |PARTITIONED|
+                                                                                                    exchange
                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                      left outer join (true)
                                                                                                       -- NESTED_LOOP  |PARTITIONED|
+                                                                                                        exchange
                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                          assign [$$227] <- [$$sub.getField("param0")]
                                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                                            exchange
                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                              -- DATASOURCE_SCAN (channels.EmergenciesNearMeChannelChannelSubscriptions)  |PARTITIONED|
+                                                                                                              data-scan []<-[$$218, $$sub] <- channels.EmergenciesNearMeChannelChannelSubscriptions
+                                                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                exchange
                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                  empty-tuple-source
                                                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                        exchange
                                                                                                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                                          assign [$$249] <- [true]
                                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                                            select (gt($$237, numeric-subtract(current-datetime(), day_time_duration: {PT10S })))
                                                                                                             -- STREAM_SELECT  |PARTITIONED|
+                                                                                                              assign [$$228, $$237] <- [$$r.getField(2), $$r.getField(3)]
                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                exchange
                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                  -- BTREE_SEARCH (channels.Reports.Reports)  |PARTITIONED|
+                                                                                                                  unnest-map [$$219, $$r] <- index-search("Reports", 0, "channels", "Reports", false, false, 1, $$259, 1, $$259, true, true, true)
+                                                                                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                                                                                    exchange
                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                      order (ASC, $$259)
                                                                                                                       -- STABLE_SORT [$$259(ASC)]  |PARTITIONED|
+                                                                                                                        exchange
                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                          project ([$$259])
                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                            exchange
                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                              -- BTREE_SEARCH (channels.Reports.report_time)  |PARTITIONED|
+                                                                                                                              unnest-map [$$258, $$259] <- index-search("report_time", 0, "channels", "Reports", false, false, 1, $$257, 0, false, true, false)
+                                                                                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                                                                                exchange
                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                  assign [$$257] <- [numeric-subtract(current-datetime(), day_time_duration: {PT10S })]
                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                    empty-tuple-source
                                                                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                    exchange
                                                                                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                                      assign [$$250, $$229] <- [true, $$u.getField(0)]
                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                        exchange
                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                          -- DATASOURCE_SCAN (channels.UserLocations)  |PARTITIONED|
+                                                                                                          data-scan []<-[$$220, $$u] <- channels.UserLocations
+                                                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                            exchange
                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                              empty-tuple-source
                                                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$222]  |PARTITIONED|
+                                                  assign [$$253] <- [true]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$223, $$222, $$238])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        join (and(eq($$233, $$224), eq($$235, $$225)))
                                                         -- HYBRID_HASH_JOIN [$$233, $$235][$$224, $$225]  |PARTITIONED|
+                                                          exchange
                                                           -- HASH_PARTITION_EXCHANGE [$$233, $$235]  |PARTITIONED|
+                                                            project ([$$223, $$222, $$233, $$235])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$235, $$233] <- [$$bs.getField("BrokerName"), $$bs.getField("DataverseName")]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- DATASOURCE_SCAN (channels.EmergenciesNearMeChannelBrokerSubscriptions)  |PARTITIONED|
+                                                                  data-scan []<-[$$222, $$223, $$bs] <- channels.EmergenciesNearMeChannelBrokerSubscriptions
+                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      empty-tuple-source
                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            project ([$$238, $$224, $$225])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$238] <- [$$b.getField("BrokerEndPoint")]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- DATASOURCE_SCAN (channels.Broker)  |PARTITIONED|
+                                                                  data-scan []<-[$$224, $$225, $$b] <- channels.Broker
+                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      empty-tuple-source
                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/array_agg/array_agg.1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/array_agg/array_agg.1.plan
index bb0f33b..fbd03b5 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/array_agg/array_agg.1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/array_agg/array_agg.1.plan
@@ -1,6 +1,12 @@
+distribute result [$$r]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    order (ASC, $$r)
     -- STABLE_SORT [$$r(ASC)]  |UNPARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+        unnest $$r <- range(1, 2)
         -- UNNEST  |UNPARTITIONED|
+          empty-tuple-source
           -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.10.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.10.plan
index 21bd922..0b00b15 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.10.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.10.plan
@@ -1,35 +1,67 @@
+distribute result [$$74]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$74])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$74] <- [{"g": $$g, "count_distinct_x": $$77, "sum_distinct_x": $$78}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$g(ASC) ]  |PARTITIONED|
-          -- PRE_CLUSTERED_GROUP_BY[$$g]  |PARTITIONED|
-                  {
+          group by ([$$g := $$g]) decor ([]) {
+                    aggregate [$$77, $$78] <- [agg-sql-count($$67), agg-sql-sum($$67)]
                     -- AGGREGATE  |LOCAL|
+                      distinct ([$$67])
                       -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                        order (ASC, $$67)
                         -- MICRO_STABLE_SORT [$$67(ASC)]  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- PRE_CLUSTERED_GROUP_BY[$$g]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$g)
               -- STABLE_SORT [$$g(ASC)]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$g]  |PARTITIONED|
+                  join (true)
                   -- NESTED_LOOP  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (true)
                       -- NESTED_LOOP  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$67])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$67] <- [$$x.getField(1)]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$x])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.d1)  |PARTITIONED|
+                                  data-scan []<-[$$75, $$x] <- test.d1
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                          project ([])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (test.d2)  |PARTITIONED|
+                              data-scan []<-[$$76, $$y] <- test.d2
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                    exchange
                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                      unnest $$g <- range(1, 3)
                       -- UNNEST  |UNPARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.11.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.11.plan
index 0e17c71..9bddb87 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.11.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.11.plan
@@ -1,43 +1,81 @@
+distribute result [$$74]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$74])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$74] <- [{"g": $$g, "sum_distinct_x": $$77, "sum_distinct_y": $$78}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$g(ASC) ]  |PARTITIONED|
-          -- PRE_CLUSTERED_GROUP_BY[$$g]  |PARTITIONED|
-                  {
+          group by ([$$g := $$g]) decor ([]) {
+                    aggregate [$$77] <- [agg-sql-sum($$67)]
                     -- AGGREGATE  |LOCAL|
+                      distinct ([$$67])
                       -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                        order (ASC, $$67)
                         -- MICRO_STABLE_SORT [$$67(ASC)]  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
-                  {
+                 }
+                 {
+                    aggregate [$$78] <- [agg-sql-sum($$72)]
                     -- AGGREGATE  |LOCAL|
+                      distinct ([$$72])
                       -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                        order (ASC, $$72)
                         -- MICRO_STABLE_SORT [$$72(ASC)]  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- PRE_CLUSTERED_GROUP_BY[$$g]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$g)
               -- STABLE_SORT [$$g(ASC)]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$g]  |PARTITIONED|
+                  join (true)
                   -- NESTED_LOOP  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (true)
                       -- NESTED_LOOP  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$67])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$67] <- [$$x.getField(1)]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$x])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.d1)  |PARTITIONED|
+                                  data-scan []<-[$$75, $$x] <- test.d1
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                          project ([$$72])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$72] <- [$$y.getField(1)]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$y])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.d2)  |PARTITIONED|
+                                  data-scan []<-[$$76, $$y] <- test.d2
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                    exchange
                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                      unnest $$g <- range(1, 3)
                       -- UNNEST  |UNPARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.12.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.12.plan
index 746b781..084c0d4 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.12.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.12.plan
@@ -1,39 +1,73 @@
+distribute result [$$83]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$83])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$83] <- [{"g": $$g, "sum_x": $$86, "sum_distinct_x": $$87, "sum_distinct_y": $$88}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$g(ASC) ]  |PARTITIONED|
-          -- PRE_CLUSTERED_GROUP_BY[$$g]  |PARTITIONED|
-                  {
+          group by ([$$g := $$g]) decor ([]) {
+                    aggregate [$$86] <- [agg-sql-sum($$71)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
-                  {
+                 }
+                 {
+                    aggregate [$$87, $$88] <- [agg-sql-sum($$71), agg-sql-sum($$71)]
                     -- AGGREGATE  |LOCAL|
+                      distinct ([$$71])
                       -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                        order (ASC, $$71)
                         -- MICRO_STABLE_SORT [$$71(ASC)]  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- PRE_CLUSTERED_GROUP_BY[$$g]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$g)
               -- STABLE_SORT [$$g(ASC)]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$g]  |PARTITIONED|
+                  join (true)
                   -- NESTED_LOOP  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (true)
                       -- NESTED_LOOP  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$71])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$71] <- [$$x.getField(1)]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$x])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.d1)  |PARTITIONED|
+                                  data-scan []<-[$$84, $$x] <- test.d1
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                          project ([])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (test.d2)  |PARTITIONED|
+                              data-scan []<-[$$85, $$y] <- test.d2
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                    exchange
                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                      unnest $$g <- range(1, 3)
                       -- UNNEST  |UNPARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.13.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.13.plan
index 60d2ed2..4735df7 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.13.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.13.plan
@@ -1,57 +1,107 @@
+distribute result [$$94]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$94])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$94] <- [{"g": $$g, "sum_distinct_x": $$98, "sum_y": $$99, "sum_distinct_z": $$100}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$g(ASC) ]  |PARTITIONED|
-          -- PRE_CLUSTERED_GROUP_BY[$$g]  |PARTITIONED|
-                  {
+          group by ([$$g := $$g]) decor ([]) {
+                    aggregate [$$98] <- [agg-sql-sum($$82)]
                     -- AGGREGATE  |LOCAL|
+                      distinct ([$$82])
                       -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                        order (ASC, $$82)
                         -- MICRO_STABLE_SORT [$$82(ASC)]  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
-                  {
+                 }
+                 {
+                    aggregate [$$99] <- [agg-sql-sum($$87)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
-                  {
+                 }
+                 {
+                    aggregate [$$100] <- [agg-sql-sum($$92)]
                     -- AGGREGATE  |LOCAL|
+                      distinct ([$$92])
                       -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                        order (ASC, $$92)
                         -- MICRO_STABLE_SORT [$$92(ASC)]  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- PRE_CLUSTERED_GROUP_BY[$$g]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$g)
               -- STABLE_SORT [$$g(ASC)]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$g]  |PARTITIONED|
+                  join (true)
                   -- NESTED_LOOP  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (true)
                       -- NESTED_LOOP  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          join (true)
                           -- NESTED_LOOP  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$82])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$82] <- [$$x.getField(1)]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$x])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.d1)  |PARTITIONED|
+                                      data-scan []<-[$$95, $$x] <- test.d1
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                              project ([$$87])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$87] <- [$$y.getField(1)]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$y])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.d2)  |PARTITIONED|
+                                      data-scan []<-[$$96, $$y] <- test.d2
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                          project ([$$92])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$92] <- [$$z.getField(1)]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$z])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.d3)  |PARTITIONED|
+                                  data-scan []<-[$$97, $$z] <- test.d3
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                    exchange
                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                      unnest $$g <- range(1, 3)
                       -- UNNEST  |UNPARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.14.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.14.plan
index 247fc31..3d00cbb 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.14.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.14.plan
@@ -1,63 +1,117 @@
+distribute result [$$148]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$148])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$148] <- [{"g": $$g, "sum_distinct_x": $$152, "sum_y": $$153, "sum_distinct_z": $$154, "avg_distinct_x": $$155, "avg_distinct_y": $$156, "count_x": $$157, "count_distinct_y": $$158, "avg_z": $$159, "count_distinct_z": $$160}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$g(ASC) ]  |PARTITIONED|
-          -- PRE_CLUSTERED_GROUP_BY[$$g]  |PARTITIONED|
-                  {
+          group by ([$$g := $$g]) decor ([]) {
+                    aggregate [$$152, $$155] <- [agg-sql-sum($$106), agg-sql-avg($$106)]
                     -- AGGREGATE  |LOCAL|
+                      distinct ([$$106])
                       -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                        order (ASC, $$106)
                         -- MICRO_STABLE_SORT [$$106(ASC)]  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
-                  {
+                 }
+                 {
+                    aggregate [$$153, $$157, $$159] <- [agg-sql-sum($$111), agg-sql-count($$106), agg-sql-avg($$116)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
-                  {
+                 }
+                 {
+                    aggregate [$$154, $$160] <- [agg-sql-sum($$116), agg-sql-count($$116)]
                     -- AGGREGATE  |LOCAL|
+                      distinct ([$$116])
                       -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                        order (ASC, $$116)
                         -- MICRO_STABLE_SORT [$$116(ASC)]  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
-                  {
+                 }
+                 {
+                    aggregate [$$156, $$158] <- [agg-sql-avg($$111), agg-sql-count($$111)]
                     -- AGGREGATE  |LOCAL|
+                      distinct ([$$111])
                       -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                        order (ASC, $$111)
                         -- MICRO_STABLE_SORT [$$111(ASC)]  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- PRE_CLUSTERED_GROUP_BY[$$g]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$g)
               -- STABLE_SORT [$$g(ASC)]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$g]  |PARTITIONED|
+                  join (true)
                   -- NESTED_LOOP  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (true)
                       -- NESTED_LOOP  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          join (true)
                           -- NESTED_LOOP  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$106])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$106] <- [$$x.getField(1)]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$x])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.d1)  |PARTITIONED|
+                                      data-scan []<-[$$149, $$x] <- test.d1
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                              project ([$$111])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$111] <- [$$y.getField(1)]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$y])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.d2)  |PARTITIONED|
+                                      data-scan []<-[$$150, $$y] <- test.d2
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                          project ([$$116])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$116] <- [$$z.getField(1)]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$z])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.d3)  |PARTITIONED|
+                                  data-scan []<-[$$151, $$z] <- test.d3
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                    exchange
                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                      unnest $$g <- range(1, 3)
                       -- UNNEST  |UNPARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.15.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.15.plan
index 5c97374..e0e2439 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.15.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.15.plan
@@ -1,175 +1,350 @@
+distribute result [$$118]
 -- DISTRIBUTE_RESULT  |LOCAL|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+    project ([$$118])
     -- STREAM_PROJECT  |LOCAL|
+      assign [$$118] <- [{"sum_distinct_x": $$119, "sum_y": $$120, "sum_distinct_z": $$121, "avg_distinct_x": $$122, "avg_distinct_y": $$123, "count_x": $$124, "count_distinct_y": $$125, "avg_z": $$126, "count_distinct_z": $$127}]
       -- ASSIGN  |LOCAL|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+          join (true)
           -- NESTED_LOOP  |LOCAL|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+              join (true)
               -- NESTED_LOOP  |LOCAL|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                  join (true)
                   -- NESTED_LOOP  |LOCAL|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                      aggregate [$$119, $$122] <- [agg-sql-sum($$137), agg-sql-avg($$137)]
                       -- AGGREGATE  |LOCAL|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                          distinct ([$$137])
                           -- PRE_SORTED_DISTINCT_BY  |LOCAL|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-                              -- STABLE_SORT [$$133(ASC)]  |LOCAL|
+                              order (ASC, $$137)
+                              -- STABLE_SORT [$$137(ASC)]  |LOCAL|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                  join (true)
                                   -- NESTED_LOOP  |UNPARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                      join (true)
                                       -- NESTED_LOOP  |UNPARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                          replicate
                                           -- REPLICATE  |UNPARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                              replicate
                                               -- REPLICATE  |UNPARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                  unnest $$137 <- range(1, 5)
                                                   -- UNNEST  |UNPARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                          replicate
                                           -- REPLICATE  |UNPARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                              project ([])
                                               -- STREAM_PROJECT  |UNPARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                  replicate
                                                   -- REPLICATE  |UNPARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                      unnest $$138 <- range(6, 10)
                                                       -- UNNEST  |UNPARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                      replicate
                                       -- REPLICATE  |UNPARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                          project ([])
                                           -- STREAM_PROJECT  |UNPARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                              replicate
                                               -- REPLICATE  |UNPARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                  unnest $$139 <- range(11, 15)
                                                   -- UNNEST  |UNPARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                      aggregate [$$120, $$124, $$126] <- [agg-global-sql-sum($$164), agg-sql-sum($$165), agg-global-sql-avg($$166)]
                       -- AGGREGATE  |LOCAL|
+                        aggregate [$$164, $$165, $$166] <- [agg-local-sql-sum($$150), agg-sql-count($$149), agg-local-sql-avg($$151)]
                         -- AGGREGATE  |LOCAL|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                            join (true)
                             -- NESTED_LOOP  |UNPARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                join (true)
                                 -- NESTED_LOOP  |UNPARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                    project ([$$149])
                                     -- STREAM_PROJECT  |UNPARTITIONED|
+                                      assign [$$149] <- [$$137]
                                       -- ASSIGN  |UNPARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                          replicate
                                           -- REPLICATE  |UNPARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                              replicate
                                               -- REPLICATE  |UNPARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                  unnest $$137 <- range(1, 5)
                                                   -- UNNEST  |UNPARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                    replicate
                                     -- REPLICATE  |UNPARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                        project ([$$150])
                                         -- STREAM_PROJECT  |UNPARTITIONED|
+                                          assign [$$150] <- [$$138]
                                           -- ASSIGN  |UNPARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                              replicate
                                               -- REPLICATE  |UNPARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                  unnest $$138 <- range(6, 10)
                                                   -- UNNEST  |UNPARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                project ([$$151])
                                 -- STREAM_PROJECT  |UNPARTITIONED|
+                                  assign [$$151] <- [$$163]
                                   -- ASSIGN  |UNPARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                      replicate
                                       -- REPLICATE  |UNPARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                          project ([$$163])
                                           -- STREAM_PROJECT  |UNPARTITIONED|
+                                            assign [$$163] <- [$$139]
                                             -- ASSIGN  |UNPARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                replicate
                                                 -- REPLICATE  |UNPARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                    unnest $$139 <- range(11, 15)
                                                     -- UNNEST  |UNPARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                  aggregate [$$121, $$127] <- [agg-sql-sum($$163), agg-sql-count($$163)]
                   -- AGGREGATE  |LOCAL|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                      distinct ([$$163])
                       -- PRE_SORTED_DISTINCT_BY  |LOCAL|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-                          -- STABLE_SORT [$$159(ASC)]  |LOCAL|
+                          order (ASC, $$163)
+                          -- STABLE_SORT [$$163(ASC)]  |LOCAL|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                              join (true)
                               -- NESTED_LOOP  |UNPARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                  join (true)
                                   -- NESTED_LOOP  |UNPARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                      replicate
                                       -- REPLICATE  |UNPARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                          project ([])
                                           -- STREAM_PROJECT  |UNPARTITIONED|
+                                            assign [$$161] <- [$$137]
                                             -- ASSIGN  |UNPARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                replicate
                                                 -- REPLICATE  |UNPARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                    unnest $$137 <- range(1, 5)
                                                     -- UNNEST  |UNPARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                      project ([])
                                       -- STREAM_PROJECT  |UNPARTITIONED|
+                                        assign [] <- []
                                         -- ASSIGN  |UNPARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                            replicate
                                             -- REPLICATE  |UNPARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                project ([])
                                                 -- STREAM_PROJECT  |UNPARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                    replicate
                                                     -- REPLICATE  |UNPARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                        unnest $$138 <- range(6, 10)
                                                         -- UNNEST  |UNPARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                  replicate
                                   -- REPLICATE  |UNPARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                      project ([$$163])
                                       -- STREAM_PROJECT  |UNPARTITIONED|
+                                        assign [$$163] <- [$$139]
                                         -- ASSIGN  |UNPARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                            replicate
                                             -- REPLICATE  |UNPARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                unnest $$139 <- range(11, 15)
                                                 -- UNNEST  |UNPARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+              aggregate [$$123, $$125] <- [agg-sql-avg($$y), agg-sql-count($$y)]
               -- AGGREGATE  |LOCAL|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                  distinct ([$$y])
                   -- PRE_SORTED_DISTINCT_BY  |LOCAL|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                      order (ASC, $$y)
                       -- STABLE_SORT [$$y(ASC)]  |LOCAL|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                          join (true)
                           -- NESTED_LOOP  |UNPARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                              join (true)
                               -- NESTED_LOOP  |UNPARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                  project ([])
                                   -- STREAM_PROJECT  |UNPARTITIONED|
+                                    assign [] <- []
                                     -- ASSIGN  |UNPARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                        replicate
                                         -- REPLICATE  |UNPARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                            project ([])
                                             -- STREAM_PROJECT  |UNPARTITIONED|
+                                              assign [$$161] <- [$$137]
                                               -- ASSIGN  |UNPARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                  replicate
                                                   -- REPLICATE  |UNPARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                      unnest $$137 <- range(1, 5)
                                                       -- UNNEST  |UNPARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                  project ([$$y])
                                   -- STREAM_PROJECT  |UNPARTITIONED|
+                                    assign [$$y] <- [$$150]
                                     -- ASSIGN  |UNPARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                        replicate
                                         -- REPLICATE  |UNPARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                            project ([$$150])
                                             -- STREAM_PROJECT  |UNPARTITIONED|
+                                              assign [$$150] <- [$$138]
                                               -- ASSIGN  |UNPARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                  replicate
                                                   -- REPLICATE  |UNPARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                      unnest $$138 <- range(6, 10)
                                                       -- UNNEST  |UNPARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                              project ([])
                               -- STREAM_PROJECT  |UNPARTITIONED|
+                                assign [] <- []
                                 -- ASSIGN  |UNPARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                    replicate
                                     -- REPLICATE  |UNPARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                        project ([])
                                         -- STREAM_PROJECT  |UNPARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                            replicate
                                             -- REPLICATE  |UNPARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                unnest $$139 <- range(11, 15)
                                                 -- UNNEST  |UNPARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.16.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.16.plan
index 79505b4..9bcaba9 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.16.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.16.plan
@@ -1,49 +1,89 @@
+distribute result [$$139]
 -- DISTRIBUTE_RESULT  |LOCAL|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+    project ([$$139])
     -- STREAM_PROJECT  |LOCAL|
+      assign [$$139] <- [{"g": $$g, "sum_distinct_x": $$140, "sum_y": $$141, "sum_distinct_z": $$142, "avg_distinct_x": $$143, "avg_distinct_y": $$144, "count_x": $$145, "count_distinct_y": $$146, "avg_z": $$147, "count_distinct_z": $$148}]
       -- ASSIGN  |LOCAL|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-          -- PRE_CLUSTERED_GROUP_BY[$$g]  |LOCAL|
-                  {
+          group by ([$$g := $$g]) decor ([]) {
+                    aggregate [$$140, $$143] <- [agg-sql-sum($$x), agg-sql-avg($$x)]
                     -- AGGREGATE  |LOCAL|
+                      distinct ([$$x])
                       -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                        order (ASC, $$x)
                         -- MICRO_STABLE_SORT [$$x(ASC)]  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
-                  {
+                 }
+                 {
+                    aggregate [$$141, $$145, $$147] <- [agg-global-sql-sum($$176), agg-sql-sum($$177), agg-global-sql-avg($$178)]
                     -- AGGREGATE  |LOCAL|
+                      aggregate [$$176, $$177, $$178] <- [agg-local-sql-sum($$y), agg-sql-count($$x), agg-local-sql-avg($$z)]
                       -- AGGREGATE  |LOCAL|
+                        nested tuple source
                         -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
-                  {
+                 }
+                 {
+                    aggregate [$$142, $$148] <- [agg-sql-sum($$z), agg-sql-count($$z)]
                     -- AGGREGATE  |LOCAL|
+                      distinct ([$$z])
                       -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                        order (ASC, $$z)
                         -- MICRO_STABLE_SORT [$$z(ASC)]  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
-                  {
+                 }
+                 {
+                    aggregate [$$144, $$146] <- [agg-sql-avg($$y), agg-sql-count($$y)]
                     -- AGGREGATE  |LOCAL|
+                      distinct ([$$y])
                       -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                        order (ASC, $$y)
                         -- MICRO_STABLE_SORT [$$y(ASC)]  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- PRE_CLUSTERED_GROUP_BY[$$g]  |LOCAL|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+              order (ASC, $$g)
               -- STABLE_SORT [$$g(ASC)]  |LOCAL|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                  join (true)
                   -- NESTED_LOOP  |UNPARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                      join (true)
                       -- NESTED_LOOP  |UNPARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                          join (true)
                           -- NESTED_LOOP  |UNPARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                              unnest $$x <- range(1, 5)
                               -- UNNEST  |UNPARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                              unnest $$y <- range(6, 10)
                               -- UNNEST  |UNPARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                          unnest $$z <- range(11, 15)
                           -- UNNEST  |UNPARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                      unnest $$g <- range(1, 3)
                       -- UNNEST  |UNPARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.17.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.17.plan
index 578e272..214eb35 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.17.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.17.plan
@@ -1,94 +1,178 @@
+distribute result [$$148]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    union ($$217, $$251, $$148)
     -- UNION_ALL  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$217])
         -- STREAM_PROJECT  |PARTITIONED|
+          assign [$$217] <- [if-missing-or-null(to-object({"sum_distinct_x": $$285, "sum_distinct_y": $$286}), { "sum_distinct_x": missing, "sum_distinct_y": missing })]
           -- ASSIGN  |PARTITIONED|
+            project ([$$285, $$286])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- PRE_CLUSTERED_GROUP_BY[$$149]  |PARTITIONED|
-                        {
+                group by ([$#1 := $$149]) decor ([]) {
+                          aggregate [$$285] <- [agg-sql-sum($$115)]
                           -- AGGREGATE  |LOCAL|
+                            distinct ([$$115])
                             -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                              order (ASC, $$115)
                               -- MICRO_STABLE_SORT [$$115(ASC)]  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                        }
-                        {
+                       }
+                       {
+                          aggregate [$$286] <- [agg-sql-sum($$120)]
                           -- AGGREGATE  |LOCAL|
+                            distinct ([$$120])
                             -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                              order (ASC, $$120)
                               -- MICRO_STABLE_SORT [$$120(ASC)]  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                        }
+                       }
+                -- PRE_CLUSTERED_GROUP_BY[$$149]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    order (ASC, $$149)
                     -- STABLE_SORT [$$149(ASC)]  |PARTITIONED|
+                      exchange
                       -- HASH_PARTITION_EXCHANGE [$$149]  |PARTITIONED|
+                        join (true)
                         -- NESTED_LOOP  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$149, $$115])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$149, $$115] <- [true, $$x.getField(1)]
                               -- ASSIGN  |PARTITIONED|
+                                project ([$$x])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  assign [$$x] <- [$$x]
                                   -- ASSIGN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      replicate
                                       -- REPLICATE  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$x])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.d1)  |PARTITIONED|
+                                              data-scan []<-[$$153, $$x] <- test.d1
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$120])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$120] <- [$$138]
                               -- ASSIGN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  replicate
                                   -- REPLICATE  |PARTITIONED|
+                                    exchange
                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                      project ([$$138])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$138] <- [$$y.getField(1)]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$y])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.d2)  |PARTITIONED|
+                                              data-scan []<-[$$154, $$y] <- test.d2
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$251])
         -- STREAM_PROJECT  |PARTITIONED|
+          assign [$$251] <- [if-missing-or-null(to-object({"sum_distinct_x": $$287, "sum_distinct_y": $$288}), { "sum_distinct_x": missing, "sum_distinct_y": missing })]
           -- ASSIGN  |PARTITIONED|
+            project ([$$287, $$288])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- PRE_CLUSTERED_GROUP_BY[$$150]  |PARTITIONED|
-                        {
+                group by ([$#2 := $$150]) decor ([]) {
+                          aggregate [$$287] <- [agg-sql-sum($$133)]
                           -- AGGREGATE  |LOCAL|
+                            distinct ([$$133])
                             -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                              order (ASC, $$133)
                               -- MICRO_STABLE_SORT [$$133(ASC)]  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                        }
-                        {
+                       }
+                       {
+                          aggregate [$$288] <- [agg-sql-sum($$138)]
                           -- AGGREGATE  |LOCAL|
+                            distinct ([$$138])
                             -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                              order (ASC, $$138)
                               -- MICRO_STABLE_SORT [$$138(ASC)]  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                        }
+                       }
+                -- PRE_CLUSTERED_GROUP_BY[$$150]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    order (ASC, $$150)
                     -- STABLE_SORT [$$150(ASC)]  |PARTITIONED|
+                      exchange
                       -- HASH_PARTITION_EXCHANGE [$$150]  |PARTITIONED|
+                        join (true)
                         -- NESTED_LOOP  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$150, $$133])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$150, $$133] <- [false, $$x.getField(1)]
                               -- ASSIGN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  replicate
                                   -- REPLICATE  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$x])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.d1)  |PARTITIONED|
+                                          data-scan []<-[$$153, $$x] <- test.d1
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                project ([$$138])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  assign [$$138] <- [$$y.getField(1)]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$y])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (test.d2)  |PARTITIONED|
+                                        data-scan []<-[$$154, $$y] <- test.d2
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.3.plan
index 38f23fd..d223187 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.3.plan
@@ -1,25 +1,50 @@
+distribute result [$$44]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$44])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$44] <- [{"count_distinct_x": $$47}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$47] <- [agg-sql-count(1)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- SORT_MERGE_EXCHANGE [$$42(ASC) ]  |PARTITIONED|
+            distinct ([$$42])
             -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (ASC, $$42)
                 -- STABLE_SORT [$$42(ASC)]  |PARTITIONED|
+                  exchange
                   -- HASH_PARTITION_EXCHANGE [$$42]  |PARTITIONED|
+                    join (true)
                     -- NESTED_LOOP  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$42])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$42] <- [$$x.getField(1)]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$x])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.d1)  |PARTITIONED|
+                                data-scan []<-[$$45, $$x] <- test.d1
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      exchange
                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                        project ([])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (test.d2)  |PARTITIONED|
+                            data-scan []<-[$$46, $$y] <- test.d2
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.4.plan
index 4439523..e1e5a25 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.4.plan
@@ -1,25 +1,50 @@
+distribute result [$$53]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$53])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$53] <- [{"count_distinct_x": $$56, "sum_distinct_x": $$57}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$56, $$57] <- [agg-sql-count($$46), agg-sql-sum($$46)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- SORT_MERGE_EXCHANGE [$$46(ASC) ]  |PARTITIONED|
+            distinct ([$$46])
             -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (ASC, $$46)
                 -- STABLE_SORT [$$46(ASC)]  |PARTITIONED|
+                  exchange
                   -- HASH_PARTITION_EXCHANGE [$$46]  |PARTITIONED|
+                    join (true)
                     -- NESTED_LOOP  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$46])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$46] <- [$$x.getField(1)]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$x])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.d1)  |PARTITIONED|
+                                data-scan []<-[$$54, $$x] <- test.d1
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      exchange
                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                        project ([])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (test.d2)  |PARTITIONED|
+                            data-scan []<-[$$55, $$y] <- test.d2
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.5.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.5.plan
index 1ee89a8..adde41f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.5.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.5.plan
@@ -1,60 +1,120 @@
+distribute result [$$53]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$53])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$53] <- [{"sum_distinct_x": $$56, "sum_distinct_y": $$57}]
       -- ASSIGN  |UNPARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+          join (true)
           -- NESTED_LOOP  |UNPARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+              aggregate [$$56] <- [agg-sql-sum($$62)]
               -- AGGREGATE  |UNPARTITIONED|
+                exchange
                 -- SORT_MERGE_EXCHANGE [$$62(ASC) ]  |PARTITIONED|
+                  distinct ([$$62])
                   -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$62)
                       -- STABLE_SORT [$$62(ASC)]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$62]  |PARTITIONED|
+                          join (true)
                           -- NESTED_LOOP  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$62])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$62] <- [$$64.getField(1)]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$64])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      replicate
                                       -- REPLICATE  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.d1)  |PARTITIONED|
+                                          data-scan []<-[$$65, $$64] <- test.d1
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                              project ([])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$67, $$66] <- [$$55, $$y]
                                 -- ASSIGN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    replicate
                                     -- REPLICATE  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (test.d2)  |PARTITIONED|
+                                        data-scan []<-[$$55, $$y] <- test.d2
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+              aggregate [$$57] <- [agg-sql-sum($$51)]
               -- AGGREGATE  |UNPARTITIONED|
+                exchange
                 -- SORT_MERGE_EXCHANGE [$$51(ASC) ]  |PARTITIONED|
+                  distinct ([$$51])
                   -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$51)
                       -- STABLE_SORT [$$51(ASC)]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$51]  |PARTITIONED|
+                          join (true)
                           -- NESTED_LOOP  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$54, $$x] <- [$$65, $$64]
                                 -- ASSIGN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    replicate
                                     -- REPLICATE  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (test.d1)  |PARTITIONED|
+                                        data-scan []<-[$$65, $$64] <- test.d1
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                              project ([$$51])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$51] <- [$$y.getField(1)]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$y])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      replicate
                                       -- REPLICATE  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.d2)  |PARTITIONED|
+                                          data-scan []<-[$$55, $$y] <- test.d2
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.6.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.6.plan
index 6c7bcd3..405ab0f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.6.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.6.plan
@@ -1,62 +1,124 @@
+distribute result [$$62]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$62])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$62] <- [{"sum_x": $$65, "sum_distinct_x": $$66, "sum_distinct_y": $$67}]
       -- ASSIGN  |UNPARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+          join (true)
           -- NESTED_LOOP  |UNPARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+              aggregate [$$65] <- [agg-global-sql-sum($$77)]
               -- AGGREGATE  |UNPARTITIONED|
+                exchange
                 -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                  aggregate [$$77] <- [agg-local-sql-sum($$72)]
                   -- AGGREGATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (true)
                       -- NESTED_LOOP  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$72])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$72] <- [$$50]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                replicate
                                 -- REPLICATE  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$50])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$50] <- [$$x.getField(1)]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$x])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (test.d1)  |PARTITIONED|
+                                            data-scan []<-[$$63, $$x] <- test.d1
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [] <- []
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                replicate
                                 -- REPLICATE  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    project ([])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (test.d2)  |PARTITIONED|
+                                        data-scan []<-[$$64, $$y] <- test.d2
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+              aggregate [$$66, $$67] <- [agg-sql-sum($$50), agg-sql-sum($$50)]
               -- AGGREGATE  |UNPARTITIONED|
+                exchange
                 -- SORT_MERGE_EXCHANGE [$$50(ASC) ]  |PARTITIONED|
+                  distinct ([$$50])
                   -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$50)
                       -- STABLE_SORT [$$50(ASC)]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$50]  |PARTITIONED|
+                          join (true)
                           -- NESTED_LOOP  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              replicate
                               -- REPLICATE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$50])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$50] <- [$$x.getField(1)]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$x])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.d1)  |PARTITIONED|
+                                          data-scan []<-[$$63, $$x] <- test.d1
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              replicate
                               -- REPLICATE  |PARTITIONED|
+                                exchange
                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                  project ([])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.d2)  |PARTITIONED|
+                                      data-scan []<-[$$64, $$y] <- test.d2
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.7.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.7.plan
index 274a43a..839d01d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.7.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.7.plan
@@ -1,139 +1,278 @@
+distribute result [$$73]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$73])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$73] <- [{"sum_distinct_x": $$77, "sum_y": $$78, "sum_distinct_z": $$79}]
       -- ASSIGN  |UNPARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+          join (true)
           -- NESTED_LOOP  |UNPARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+              join (true)
               -- NESTED_LOOP  |UNPARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                  aggregate [$$77] <- [agg-sql-sum($$86)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- SORT_MERGE_EXCHANGE [$$86(ASC) ]  |PARTITIONED|
+                      distinct ([$$86])
                       -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$86)
                           -- STABLE_SORT [$$86(ASC)]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$86]  |PARTITIONED|
+                              join (true)
                               -- NESTED_LOOP  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  join (true)
                                   -- NESTED_LOOP  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$86])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$86] <- [$$89.getField(1)]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$89])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              replicate
                                               -- REPLICATE  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- DATASOURCE_SCAN (test.d1)  |PARTITIONED|
+                                                  data-scan []<-[$$90, $$89] <- test.d1
+                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      replicate
                                       -- REPLICATE  |PARTITIONED|
+                                        exchange
                                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                          project ([])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              replicate
                                               -- REPLICATE  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- DATASOURCE_SCAN (test.d2)  |PARTITIONED|
+                                                  data-scan []<-[$$92, $$91] <- test.d2
+                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  replicate
                                   -- REPLICATE  |PARTITIONED|
+                                    exchange
                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                      project ([])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          replicate
                                           -- REPLICATE  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.d3)  |PARTITIONED|
+                                              data-scan []<-[$$94, $$93] <- test.d3
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                  aggregate [$$78] <- [agg-global-sql-sum($$107)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$107] <- [agg-local-sql-sum($$99)]
                       -- AGGREGATE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          join (true)
                           -- NESTED_LOOP  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              join (true)
                               -- NESTED_LOOP  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [] <- []
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        replicate
                                         -- REPLICATE  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$74, $$x] <- [$$90, $$89]
                                               -- ASSIGN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  replicate
                                                   -- REPLICATE  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.d1)  |PARTITIONED|
+                                                      data-scan []<-[$$90, $$89] <- test.d1
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                exchange
                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                  project ([$$99])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$99] <- [$$103.getField(1)]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$103])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$104, $$103] <- [$$92, $$91]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- DATASOURCE_SCAN (test.d2)  |PARTITIONED|
+                                                data-scan []<-[$$92, $$91] <- test.d2
+                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [] <- []
                                 -- ASSIGN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    replicate
                                     -- REPLICATE  |PARTITIONED|
+                                      exchange
                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                        project ([])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- DATASOURCE_SCAN (test.d3)  |PARTITIONED|
+                                                data-scan []<-[$$94, $$93] <- test.d3
+                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+              aggregate [$$79] <- [agg-sql-sum($$71)]
               -- AGGREGATE  |UNPARTITIONED|
+                exchange
                 -- SORT_MERGE_EXCHANGE [$$71(ASC) ]  |PARTITIONED|
+                  distinct ([$$71])
                   -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$71)
                       -- STABLE_SORT [$$71(ASC)]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$71]  |PARTITIONED|
+                          join (true)
                           -- NESTED_LOOP  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              join (true)
                               -- NESTED_LOOP  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  replicate
                                   -- REPLICATE  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$74, $$x] <- [$$90, $$89]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- DATASOURCE_SCAN (test.d1)  |PARTITIONED|
+                                                data-scan []<-[$$90, $$89] <- test.d1
+                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [] <- []
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        replicate
                                         -- REPLICATE  |PARTITIONED|
+                                          exchange
                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                            project ([])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                replicate
                                                 -- REPLICATE  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (test.d2)  |PARTITIONED|
+                                                    data-scan []<-[$$92, $$91] <- test.d2
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                              project ([$$71])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$71] <- [$$z.getField(1)]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$z])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$76, $$z] <- [$$94, $$93]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        replicate
                                         -- REPLICATE  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (test.d3)  |PARTITIONED|
+                                            data-scan []<-[$$94, $$93] <- test.d3
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.8.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.8.plan
index a6f3df3..2fda7e1 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.8.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.8.plan
@@ -1,204 +1,408 @@
+distribute result [$$127]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$127])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$127] <- [{"sum_distinct_x": $$131, "sum_y": $$132, "sum_distinct_z": $$133, "avg_distinct_x": $$134, "avg_distinct_y": $$135, "count_x": $$136, "count_distinct_y": $$137, "avg_z": $$138, "count_distinct_z": $$139}]
       -- ASSIGN  |UNPARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+          join (true)
           -- NESTED_LOOP  |UNPARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+              join (true)
               -- NESTED_LOOP  |UNPARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                  join (true)
                   -- NESTED_LOOP  |UNPARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                      aggregate [$$131, $$134] <- [agg-sql-sum($$152), agg-sql-avg($$152)]
                       -- AGGREGATE  |UNPARTITIONED|
+                        exchange
                         -- SORT_MERGE_EXCHANGE [$$152(ASC) ]  |PARTITIONED|
+                          distinct ([$$152])
                           -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$152)
                               -- STABLE_SORT [$$152(ASC)]  |PARTITIONED|
+                                exchange
                                 -- HASH_PARTITION_EXCHANGE [$$152]  |PARTITIONED|
+                                  join (true)
                                   -- NESTED_LOOP  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      join (true)
                                       -- NESTED_LOOP  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          replicate
                                           -- REPLICATE  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$152])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$152] <- [$$155.getField(1)]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  project ([$$155])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      replicate
                                                       -- REPLICATE  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- DATASOURCE_SCAN (test.d1)  |PARTITIONED|
+                                                          data-scan []<-[$$156, $$155] <- test.d1
+                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              empty-tuple-source
                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          replicate
                                           -- REPLICATE  |PARTITIONED|
+                                            exchange
                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                              project ([])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$158, $$157] <- [$$176, $$175]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    replicate
                                                     -- REPLICATE  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.d2)  |PARTITIONED|
+                                                        data-scan []<-[$$176, $$175] <- test.d2
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      replicate
                                       -- REPLICATE  |PARTITIONED|
+                                        exchange
                                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                          project ([])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$160, $$159] <- [$$196, $$195]
                                             -- ASSIGN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                replicate
                                                 -- REPLICATE  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (test.d3)  |PARTITIONED|
+                                                    data-scan []<-[$$196, $$195] <- test.d3
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                      aggregate [$$132, $$136, $$138] <- [agg-global-sql-sum($$197), agg-sql-sum($$198), agg-global-sql-avg($$199)]
                       -- AGGREGATE  |UNPARTITIONED|
+                        exchange
                         -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                          aggregate [$$197, $$198, $$199] <- [agg-local-sql-sum($$171), agg-sql-count($$170), agg-local-sql-avg($$172)]
                           -- AGGREGATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              join (true)
                               -- NESTED_LOOP  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  join (true)
                                   -- NESTED_LOOP  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$170])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$170] <- [$$152]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$152])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$152] <- [$$155.getField(1)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$155])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        replicate
                                                         -- REPLICATE  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- DATASOURCE_SCAN (test.d1)  |PARTITIONED|
+                                                            data-scan []<-[$$156, $$155] <- test.d1
+                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                empty-tuple-source
                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      replicate
                                       -- REPLICATE  |PARTITIONED|
+                                        exchange
                                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                          project ([$$171])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$171] <- [$$175.getField(1)]
                                             -- ASSIGN  |PARTITIONED|
+                                              project ([$$175])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  replicate
                                                   -- REPLICATE  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.d2)  |PARTITIONED|
+                                                      data-scan []<-[$$176, $$175] <- test.d2
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$172])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$172] <- [$$190]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        replicate
                                         -- REPLICATE  |PARTITIONED|
+                                          exchange
                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                            project ([$$190])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$190] <- [$$195.getField(1)]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$195])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    replicate
                                                     -- REPLICATE  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.d3)  |PARTITIONED|
+                                                        data-scan []<-[$$196, $$195] <- test.d3
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                  aggregate [$$133, $$139] <- [agg-sql-sum($$190), agg-sql-count($$190)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- SORT_MERGE_EXCHANGE [$$190(ASC) ]  |PARTITIONED|
+                      distinct ([$$190])
                       -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$190)
                           -- STABLE_SORT [$$190(ASC)]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$190]  |PARTITIONED|
+                              join (true)
                               -- NESTED_LOOP  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  join (true)
                                   -- NESTED_LOOP  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      replicate
                                       -- REPLICATE  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$192, $$191] <- [$$156, $$155]
                                             -- ASSIGN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                replicate
                                                 -- REPLICATE  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (test.d1)  |PARTITIONED|
+                                                    data-scan []<-[$$156, $$155] <- test.d1
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [] <- []
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                project ([])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$158, $$157] <- [$$176, $$175]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      replicate
                                                       -- REPLICATE  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- DATASOURCE_SCAN (test.d2)  |PARTITIONED|
+                                                          data-scan []<-[$$176, $$175] <- test.d2
+                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              empty-tuple-source
                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  replicate
                                   -- REPLICATE  |PARTITIONED|
+                                    exchange
                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                      project ([$$190])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$190] <- [$$195.getField(1)]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$195])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              replicate
                                               -- REPLICATE  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- DATASOURCE_SCAN (test.d3)  |PARTITIONED|
+                                                  data-scan []<-[$$196, $$195] <- test.d3
+                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+              aggregate [$$135, $$137] <- [agg-sql-avg($$90), agg-sql-count($$90)]
               -- AGGREGATE  |UNPARTITIONED|
+                exchange
                 -- SORT_MERGE_EXCHANGE [$$90(ASC) ]  |PARTITIONED|
+                  distinct ([$$90])
                   -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$90)
                       -- STABLE_SORT [$$90(ASC)]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$90]  |PARTITIONED|
+                          join (true)
                           -- NESTED_LOOP  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              join (true)
                               -- NESTED_LOOP  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [] <- []
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        replicate
                                         -- REPLICATE  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$192, $$191] <- [$$156, $$155]
                                               -- ASSIGN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  replicate
                                                   -- REPLICATE  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.d1)  |PARTITIONED|
+                                                      data-scan []<-[$$156, $$155] <- test.d1
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$90])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$90] <- [$$171]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        replicate
                                         -- REPLICATE  |PARTITIONED|
+                                          exchange
                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                            project ([$$171])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$171] <- [$$175.getField(1)]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$175])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    replicate
                                                     -- REPLICATE  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.d2)  |PARTITIONED|
+                                                        data-scan []<-[$$176, $$175] <- test.d2
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [] <- []
                                 -- ASSIGN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    replicate
                                     -- REPLICATE  |PARTITIONED|
+                                      exchange
                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                        project ([])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$160, $$159] <- [$$196, $$195]
                                           -- ASSIGN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              replicate
                                               -- REPLICATE  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- DATASOURCE_SCAN (test.d3)  |PARTITIONED|
+                                                  data-scan []<-[$$196, $$195] <- test.d3
+                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.9.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.9.plan
index 76735bd..2c1a377 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.9.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-sql-sugar/distinct_mixed/distinct_mixed.9.plan
@@ -1,35 +1,67 @@
+distribute result [$$65]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$65])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$65] <- [{"g": $$g, "count_distinct_x": $$68}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$g(ASC) ]  |PARTITIONED|
-          -- PRE_CLUSTERED_GROUP_BY[$$g]  |PARTITIONED|
-                  {
+          group by ([$$g := $$g]) decor ([]) {
+                    aggregate [$$68] <- [agg-sql-count($$63)]
                     -- AGGREGATE  |LOCAL|
+                      distinct ([$$63])
                       -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                        order (ASC, $$63)
                         -- MICRO_STABLE_SORT [$$63(ASC)]  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- PRE_CLUSTERED_GROUP_BY[$$g]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$g)
               -- STABLE_SORT [$$g(ASC)]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$g]  |PARTITIONED|
+                  join (true)
                   -- NESTED_LOOP  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (true)
                       -- NESTED_LOOP  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$63])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$63] <- [$$x.getField(1)]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$x])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.d1)  |PARTITIONED|
+                                  data-scan []<-[$$66, $$x] <- test.d1
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                          project ([])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (test.d2)  |PARTITIONED|
+                              data-scan []<-[$$67, $$y] <- test.d2
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                    exchange
                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                      unnest $$g <- range(1, 3)
                       -- UNNEST  |UNPARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.10.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.10.plan
index 63d3f7c..c2eb6c0 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.10.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.10.plan
@@ -1,27 +1,48 @@
+distribute result [$$81]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$81])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$81] <- [{"ten": $$ten, "cnt": $$85, "min2": $$86, "max2": $$87, "sum20": $$88}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$ten(ASC) ]  |PARTITIONED|
-          -- SORT_GROUP_BY[$$95]  |PARTITIONED|
-                  {
+          group by ([$$ten := $$95]) decor ([]) {
+                    aggregate [$$85, $$86, $$87, $$88] <- [agg-sql-sum($$91), agg-global-sql-min($$92), agg-global-sql-max($$93), agg-global-sql-sum($$94)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- SORT_GROUP_BY[$$95]  |PARTITIONED|
+            exchange
             -- HASH_PARTITION_EXCHANGE [$$95]  |PARTITIONED|
-              -- PRE_CLUSTERED_GROUP_BY[$$82]  |PARTITIONED|
-                      {
+              group by ([$$95 := $$82]) decor ([]) {
+                        aggregate [$$91, $$92, $$93, $$94] <- [agg-sql-count(1), agg-local-sql-min($$63), agg-local-sql-max($$63), agg-local-sql-sum($$79)]
                         -- AGGREGATE  |LOCAL|
+                          select (gt($$90, 0))
                           -- STREAM_SELECT  |LOCAL|
+                            nested tuple source
                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- PRE_CLUSTERED_GROUP_BY[$$82]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  order (ASC, $$82)
                   -- STABLE_SORT [$$82(ASC)]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$63, $$79, $$90, $$82])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$79, $$63, $$90, $$82] <- [$$tenk.getField(5), $$tenk.getField(2), $$tenk.getField(3), $$tenk.getField(4)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$tenk])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                              data-scan []<-[$$84, $$tenk] <- test.tenk
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                  empty-tuple-source
+                                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.3.plan
index 574df58..f01f325 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.3.plan
@@ -1,16 +1,32 @@
+distribute result [$$46]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$46])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$46] <- [{"cnt": $$49, "sm": $$50}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$49, $$50] <- [agg-sql-sum($$52), agg-global-sql-sum($$53)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$52, $$53] <- [agg-sql-count($$36), agg-local-sql-sum($$47)]
             -- AGGREGATE  |PARTITIONED|
+              assign [$$36] <- [1]
               -- ASSIGN  |PARTITIONED|
+                select (gt($$47, 0))
                 -- STREAM_SELECT  |PARTITIONED|
+                  project ([$$47])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$47] <- [$$tenk.getField(3)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$tenk])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                          data-scan []<-[$$48, $$tenk] <- test.tenk
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.4.plan
index c94ef11..2b3dbef 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.4.plan
@@ -1,27 +1,48 @@
+distribute result [$$57]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$57])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$57] <- [{"two": $$two, "cnt": $$61, "sm": $$62}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$two(ASC) ]  |PARTITIONED|
-          -- SORT_GROUP_BY[$$67]  |PARTITIONED|
-                  {
+          group by ([$$two := $$67]) decor ([]) {
+                    aggregate [$$61, $$62] <- [agg-sql-sum($$65), agg-global-sql-sum($$66)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- SORT_GROUP_BY[$$67]  |PARTITIONED|
+            exchange
             -- HASH_PARTITION_EXCHANGE [$$67]  |PARTITIONED|
-              -- PRE_CLUSTERED_GROUP_BY[$$58]  |PARTITIONED|
-                      {
+              group by ([$$67 := $$58]) decor ([]) {
+                        aggregate [$$65, $$66] <- [agg-sql-count(1), agg-local-sql-sum($$59)]
                         -- AGGREGATE  |LOCAL|
+                          select (gt($$59, 0))
                           -- STREAM_SELECT  |LOCAL|
+                            nested tuple source
                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- PRE_CLUSTERED_GROUP_BY[$$58]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  order (ASC, $$58)
                   -- STABLE_SORT [$$58(ASC)]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$59, $$58])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$59, $$58] <- [$$tenk.getField(3), $$tenk.getField(2)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$tenk])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                              data-scan []<-[$$60, $$tenk] <- test.tenk
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.5.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.5.plan
index 9462514..b714756 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.5.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.5.plan
@@ -1,68 +1,124 @@
+distribute result [$#2]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$#2])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- SORT_MERGE_EXCHANGE [$$189(ASC) ]  |PARTITIONED|
+        order (ASC, $$189)
         -- STABLE_SORT [$$189(ASC)]  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            union ($$240, $$241, $#2) ($$two, $$two, $$189)
             -- UNION_ALL  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$240, $$two])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$240] <- [cast({"two": $$two, "cnt": $$183, "sm": $$184})]
                   -- ASSIGN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- SORT_GROUP_BY[$$236]  |PARTITIONED|
-                              {
+                      group by ([$$two := $$236]) decor ([]) {
+                                aggregate [$$183, $$184] <- [agg-sql-sum($$234), agg-global-sql-sum($$235)]
                                 -- AGGREGATE  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- SORT_GROUP_BY[$$236]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$236]  |PARTITIONED|
-                          -- PRE_CLUSTERED_GROUP_BY[$$115]  |PARTITIONED|
-                                  {
+                          group by ([$$236 := $$115]) decor ([]) {
+                                    aggregate [$$234, $$235] <- [agg-sql-count(1), agg-local-sql-sum($$117)]
                                     -- AGGREGATE  |LOCAL|
+                                      select (gt($$117, 0))
                                       -- STREAM_SELECT  |LOCAL|
+                                        nested tuple source
                                         -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                  }
+                                 }
+                          -- PRE_CLUSTERED_GROUP_BY[$$115]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$115)
                               -- STABLE_SORT [$$115(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$117, $$115])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$117, $$115] <- [$$tenk.getField(3), $$tenk.getField(2)]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$tenk])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$tenk] <- [$$tenk]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$tenk])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                                                    data-scan []<-[$$120, $$tenk] <- test.tenk
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$241, $$two])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$241] <- [cast({"two": $$two, "cnt": $$185, "sm": $$186})]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$185, $$186, $$two])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- SORT_GROUP_BY[$$239]  |PARTITIONED|
-                                {
+                        group by ([$$91 := $$239]) decor ([$$two := $$114]) {
+                                  aggregate [$$185, $$186] <- [agg-sql-sum($$237), agg-global-sql-sum($$238)]
                                   -- AGGREGATE  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                }
+                               }
+                        -- SORT_GROUP_BY[$$239]  |PARTITIONED|
+                          exchange
                           -- HASH_PARTITION_EXCHANGE [$$239]  |PARTITIONED|
-                            -- PRE_CLUSTERED_GROUP_BY[$$116]  |PARTITIONED|
-                                    {
+                            group by ([$$239 := $$116]) decor ([$$114]) {
+                                      aggregate [$$237, $$238] <- [agg-sql-count(1), agg-local-sql-sum($$118)]
                                       -- AGGREGATE  |LOCAL|
+                                        select (gt($$118, 0))
                                         -- STREAM_SELECT  |LOCAL|
+                                          nested tuple source
                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                    }
+                                   }
+                            -- PRE_CLUSTERED_GROUP_BY[$$116]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$116)
                                 -- STABLE_SORT [$$116(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$116, $$114, $$118])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$116, $$114, $$118] <- [true, null, $$tenk.getField(3)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          replicate
                                           -- REPLICATE  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$tenk])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                                                  data-scan []<-[$$120, $$tenk] <- test.tenk
+                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.6.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.6.plan
index 3f5657c..1b7c678 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.6.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.6.plan
@@ -1,26 +1,46 @@
+distribute result [$$122]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$122])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$122] <- [{"twothous": $$124, "fivethous": $$134, "tenthous": $$tenk.tenthous, "cnt": $$126, "sm": $$127, "cnt_filter": $$128, "sm_filter": $$129}]
       -- ASSIGN  |UNPARTITIONED|
-        -- WINDOW  |UNPARTITIONED|
-                {
+        window-aggregate [] <- [] order (ASC, $$tenk.tenthous) frame on (ASC, $$tenk.tenthous) start unbounded end [$$tenk.tenthous] {
+                  aggregate [$$129, $$128] <- [agg-sql-sum($$tenk.tenthous), agg-sql-count(1)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    select (eq($$124, 0))
                     -- STREAM_SELECT  |UNPARTITIONED|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |UNPARTITIONED|
-                }
-          -- WINDOW  |UNPARTITIONED|
-                  {
+               }
+        -- WINDOW  |UNPARTITIONED|
+          window-aggregate [] <- [] order (ASC, $$tenk.tenthous) frame on (ASC, $$tenk.tenthous) start unbounded end [$$tenk.tenthous] {
+                    aggregate [$$127, $$126] <- [agg-sql-sum($$tenk.tenthous), agg-sql-count(1)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- WINDOW  |UNPARTITIONED|
+            exchange
             -- SORT_MERGE_EXCHANGE [$$tenk.tenthous(ASC) ]  |PARTITIONED|
+              order (ASC, $$tenk.tenthous)
               -- STABLE_SORT [$$tenk.tenthous(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$124, $$134, $$tenk.tenthous])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    select (eq($$tenk.getField(7), 0))
                     -- STREAM_SELECT  |PARTITIONED|
+                      assign [$$134, $$tenk.tenthous, $$124] <- [$$tenk.getField(9), $$tenk.getField(10), $$tenk.getField(8)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$tenk])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                            data-scan []<-[$$125, $$tenk] <- test.tenk
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.7.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.7.plan
index af2e160..1cdec98 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.7.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.7.plan
@@ -1,44 +1,73 @@
+distribute result [$$179]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$179])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$179] <- [{"twenty": $$twenty, "sm": $$186, "sm_sm": $$190, "sm_sm_where_twenty_lt_10": $$191, "sm_sm_where_sm_lt_3k": $$192}]
       -- ASSIGN  |UNPARTITIONED|
+        project ([$$twenty, $$186, $$190, $$191, $$192])
         -- STREAM_PROJECT  |UNPARTITIONED|
-          -- WINDOW  |UNPARTITIONED|
-                  {
+          window-aggregate [] <- [] order (ASC, $$twenty) frame on (ASC, $$twenty) start unbounded end [$$twenty] {
+                    aggregate [$$192] <- [agg-sql-sum($$185)]
                     -- AGGREGATE  |UNPARTITIONED|
+                      select (lt($$184, 3000))
                       -- STREAM_SELECT  |UNPARTITIONED|
+                        nested tuple source
                         -- NESTED_TUPLE_SOURCE  |UNPARTITIONED|
-                  }
+                 }
+          -- WINDOW  |UNPARTITIONED|
+            project ([$$twenty, $$186, $$190, $$191, $$185, $$184])
             -- STREAM_PROJECT  |UNPARTITIONED|
-              -- WINDOW  |UNPARTITIONED|
-                      {
+              window-aggregate [] <- [] order (ASC, $$twenty) frame on (ASC, $$twenty) start unbounded end [$$twenty] {
+                        aggregate [$$191] <- [agg-sql-sum($$183)]
                         -- AGGREGATE  |UNPARTITIONED|
+                          select (lt($$twenty, 10))
                           -- STREAM_SELECT  |UNPARTITIONED|
+                            nested tuple source
                             -- NESTED_TUPLE_SOURCE  |UNPARTITIONED|
-                      }
+                     }
+              -- WINDOW  |UNPARTITIONED|
+                project ([$$twenty, $$186, $$190, $$185, $$184, $$183])
                 -- STREAM_PROJECT  |UNPARTITIONED|
-                  -- WINDOW  |UNPARTITIONED|
-                          {
+                  window-aggregate [] <- [] order (ASC, $$twenty) frame on (ASC, $$twenty) start unbounded end [$$twenty] {
+                            aggregate [$$190] <- [agg-sql-sum($$182)]
                             -- AGGREGATE  |LOCAL|
+                              nested tuple source
                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                         }
+                  -- WINDOW  |UNPARTITIONED|
+                    exchange
                     -- SORT_MERGE_EXCHANGE [$$twenty(ASC) ]  |PARTITIONED|
-                      -- SORT_GROUP_BY[$$198]  |PARTITIONED|
-                              {
+                      group by ([$$twenty := $$198]) decor ([]) {
+                                aggregate [$$182, $$183, $$184, $$185, $$186] <- [agg-global-sql-sum($$193), agg-global-sql-sum($$194), agg-global-sql-sum($$195), agg-global-sql-sum($$196), agg-global-sql-sum($$197)]
                                 -- AGGREGATE  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- SORT_GROUP_BY[$$198]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$198]  |PARTITIONED|
-                          -- SORT_GROUP_BY[$$180]  |PARTITIONED|
-                                  {
+                          group by ([$$198 := $$180]) decor ([]) {
+                                    aggregate [$$193, $$194, $$195, $$196, $$197] <- [agg-local-sql-sum($$122), agg-local-sql-sum($$122), agg-local-sql-sum($$122), agg-local-sql-sum($$122), agg-local-sql-sum($$122)]
                                     -- AGGREGATE  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                  }
+                                 }
+                          -- SORT_GROUP_BY[$$180]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$122, $$180])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$122, $$180] <- [$$tenk.getField(4), $$tenk.getField(5)]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$tenk])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                                      data-scan []<-[$$181, $$tenk] <- test.tenk
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.8.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.8.plan
index 4ceb881..5d66d10 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.8.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.8.plan
@@ -1,28 +1,50 @@
+distribute result [$$65]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$65])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$65] <- [{"two": $$two, "sm": $$68}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$two(ASC) ]  |PARTITIONED|
-          -- PRE_CLUSTERED_GROUP_BY[$$66]  |PARTITIONED|
-                  {
+          group by ([$$two := $$66]) decor ([]) {
+                    aggregate [$$68] <- [agg-sql-sum($$70)]
                     -- AGGREGATE  |LOCAL|
+                      select ($$60)
                       -- STREAM_SELECT  |LOCAL|
-                        -- SUBPLAN  |LOCAL|
-                                {
+                        subplan {
+                                  aggregate [$$60] <- [empty-stream()]
                                   -- AGGREGATE  |LOCAL|
+                                    select (not(if-missing-or-null(gt($$x, 0), false)))
                                     -- STREAM_SELECT  |LOCAL|
+                                      unnest $$x <- scan-collection(ordered-list-constructor($$70, numeric-add($$70, $$70)))
                                       -- UNNEST  |LOCAL|
+                                        nested tuple source
                                         -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                }
+                               }
+                        -- SUBPLAN  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- PRE_CLUSTERED_GROUP_BY[$$66]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$66)
               -- STABLE_SORT [$$66(ASC)]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$66]  |PARTITIONED|
+                  project ([$$70, $$66])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$70, $$66] <- [$$tenk.getField(3), $$tenk.getField(2)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$tenk])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                          data-scan []<-[$$67, $$tenk] <- test.tenk
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.9.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.9.plan
index 02d8027..69d1261 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.9.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate-subclause/agg_filter_01/agg_filter_01.9.plan
@@ -1,16 +1,32 @@
+distribute result [$$70]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$70])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$70] <- [{"cnt": $$73, "min2": $$74, "max2": $$75, "sum20": $$76}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$73, $$74, $$75, $$76] <- [agg-sql-sum($$78), agg-global-sql-min($$79), agg-global-sql-max($$80), agg-global-sql-sum($$81)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$78, $$79, $$80, $$81] <- [agg-sql-count($$44), agg-local-sql-min($$52), agg-local-sql-max($$52), agg-local-sql-sum($$68)]
             -- AGGREGATE  |PARTITIONED|
+              assign [$$44] <- [1]
               -- ASSIGN  |PARTITIONED|
+                project ([$$68, $$52])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (gt($$tenk.getField(3), 0))
                   -- STREAM_SELECT  |PARTITIONED|
+                    assign [$$68, $$52] <- [$$tenk.getField(5), $$tenk.getField(2)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$tenk])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                          data-scan []<-[$$72, $$tenk] <- test.tenk
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                              empty-tuple-source
+                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/constant-agg.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/constant-agg.plan
index b79b733..81b2593 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/constant-agg.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/constant-agg.plan
@@ -1,11 +1,22 @@
+distribute result [$$31]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$31])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$31] <- [{"count": $$33}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$33] <- [agg-sql-sum($$34)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$34] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (TinySocial.FacebookUsers)  |PARTITIONED|
+                data-scan []<-[$$32, $$u] <- TinySocial.FacebookUsers
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/constant-gby-agg.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/constant-gby-agg.plan
index 453e53b..5e1578a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/constant-gby-agg.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/constant-gby-agg.plan
@@ -1,24 +1,42 @@
+distribute result [$$42]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$42])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$42] <- [{"alias": $$alias, "count": $$45}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- SORT_GROUP_BY[$$47]  |PARTITIONED|
-                  {
+          group by ([$$alias := $$47]) decor ([]) {
+                    aggregate [$$45] <- [agg-sql-sum($$46)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- SORT_GROUP_BY[$$47]  |PARTITIONED|
+            exchange
             -- HASH_PARTITION_EXCHANGE [$$47]  |PARTITIONED|
-              -- SORT_GROUP_BY[$$43]  |PARTITIONED|
-                      {
+              group by ([$$47 := $$43]) decor ([]) {
+                        aggregate [$$46] <- [agg-sql-count(1)]
                         -- AGGREGATE  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SORT_GROUP_BY[$$43]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$43])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$43] <- [$$u.getField("alias")]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$u])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (TinySocial.FacebookUsers)  |PARTITIONED|
+                          data-scan []<-[$$44, $$u] <- TinySocial.FacebookUsers
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/count-dataset.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/count-dataset.plan
index 6318801..9bc4be3 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/count-dataset.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/count-dataset.plan
@@ -1,9 +1,18 @@
+distribute result [$$7]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    aggregate [$$7] <- [agg-sum($$8)]
     -- AGGREGATE  |UNPARTITIONED|
+      exchange
       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+        aggregate [$$8] <- [agg-count(1)]
         -- AGGREGATE  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- DATASOURCE_SCAN (TinySocial.FacebookUsers)  |PARTITIONED|
+            data-scan []<-[$$6, $$4] <- TinySocial.FacebookUsers
+            -- DATASOURCE_SCAN  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                empty-tuple-source
                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/list-dataset.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/list-dataset.plan
index 1b428e7..cb245b9 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/list-dataset.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/list-dataset.plan
@@ -1,9 +1,18 @@
+distribute result [$$4]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    aggregate [$$4] <- [listify($$3)]
     -- AGGREGATE  |UNPARTITIONED|
+      exchange
       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+        project ([$$3])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- DATASOURCE_SCAN (TinySocial.FacebookUsers)  |PARTITIONED|
+            data-scan []<-[$$5, $$3] <- TinySocial.FacebookUsers
+            -- DATASOURCE_SCAN  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                empty-tuple-source
                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/query-ASTERIXDB-1626-2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/query-ASTERIXDB-1626-2.plan
index 5304d60..e7da8ae 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/query-ASTERIXDB-1626-2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/query-ASTERIXDB-1626-2.plan
@@ -1,15 +1,30 @@
+distribute result [$$44]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$44])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$44] <- [{"total": numeric-multiply($$46, $$47)}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$46, $$47] <- [agg-sql-sum($$49), agg-global-sql-avg($$50)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$49, $$50] <- [agg-sql-count($$35), agg-local-sql-avg($$41)]
             -- AGGREGATE  |PARTITIONED|
+              assign [$$41] <- [count($$35)]
               -- ASSIGN  |PARTITIONED|
+                project ([$$35])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$35] <- [$$FacebookUsers.getField("friend-ids")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$FacebookUsers])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (TinySocial.FacebookUsers)  |PARTITIONED|
+                        data-scan []<-[$$45, $$FacebookUsers] <- TinySocial.FacebookUsers
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/query-ASTERIXDB-1626-3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/query-ASTERIXDB-1626-3.plan
index 5304d60..abe0d8b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/query-ASTERIXDB-1626-3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/query-ASTERIXDB-1626-3.plan
@@ -1,15 +1,30 @@
+distribute result [$$57]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$57])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$57] <- [{"total": numeric-multiply($$59, $$60), "t": 1}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$59, $$60] <- [agg-sql-sum($$62), agg-global-sql-avg($$63)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$62, $$63] <- [agg-sql-count($$48), agg-local-sql-avg($$54)]
             -- AGGREGATE  |PARTITIONED|
+              assign [$$54] <- [count($$48)]
               -- ASSIGN  |PARTITIONED|
+                project ([$$48])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$48] <- [$$FacebookUsers.getField("friend-ids")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$FacebookUsers])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (TinySocial.FacebookUsers)  |PARTITIONED|
+                        data-scan []<-[$$58, $$FacebookUsers] <- TinySocial.FacebookUsers
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/query-ASTERIXDB-1626.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/query-ASTERIXDB-1626.plan
index 5304d60..8efc211 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/query-ASTERIXDB-1626.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/query-ASTERIXDB-1626.plan
@@ -1,15 +1,30 @@
+distribute result [$$45]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$45])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$45] <- [{"$1": $$47, "$2": $$48}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$47, $$48] <- [agg-sql-sum($$50), agg-global-sql-avg($$51)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$50, $$51] <- [agg-sql-count($$37), agg-local-sql-avg($$43)]
             -- AGGREGATE  |PARTITIONED|
+              assign [$$43] <- [count($$37)]
               -- ASSIGN  |PARTITIONED|
+                project ([$$37])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$37] <- [$$FacebookUsers.getField("friend-ids")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$FacebookUsers])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (TinySocial.FacebookUsers)  |PARTITIONED|
+                        data-scan []<-[$$46, $$FacebookUsers] <- TinySocial.FacebookUsers
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/serial-agg.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/serial-agg.plan
index 8b7a8d7..04f152f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/serial-agg.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/aggregate/serial-agg.plan
@@ -1,24 +1,42 @@
+distribute result [$$44]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$44])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$44] <- [{"gid": $$gid, "stddev": $$47}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- EXTERNAL_GROUP_BY[$$50]  |PARTITIONED|
-                  {
+          group by ([$$gid := $$50]) decor ([]) {
+                    aggregate [$$47] <- [global-sql-stddev-serial_samp($$49)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- EXTERNAL_GROUP_BY[$$50]  |PARTITIONED|
+            exchange
             -- HASH_PARTITION_EXCHANGE [$$50]  |PARTITIONED|
-              -- EXTERNAL_GROUP_BY[$$45]  |PARTITIONED|
-                      {
+              group by ([$$50 := $$45]) decor ([]) {
+                        aggregate [$$49] <- [local-sql-stddev-serial_samp($$42)]
                         -- AGGREGATE  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- EXTERNAL_GROUP_BY[$$45]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$42, $$45])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$42, $$45] <- [$$t.getField(2), $$t.getField(1)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$t])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (test.Test)  |PARTITIONED|
+                          data-scan []<-[$$46, $$t] <- test.Test
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/any-and-every-1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/any-and-every-1.plan
index faac4b0..4e5b72f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/any-and-every-1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/any-and-every-1.plan
@@ -1,19 +1,35 @@
+distribute result [$$28]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$28])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$28] <- [{"D": $$D}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$D])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and($$24, eq($$25, 0)))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$D, $$24, $$25])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$24, $$25] <- [non-empty-stream(), agg-sql-count(switch-case(eq($$I, 1), true, NULL, true))]
                         -- AGGREGATE  |LOCAL|
+                          unnest $$I <- scan-collection($$30)
                           -- UNNEST  |LOCAL|
+                            nested tuple source
                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                assign [$$30] <- [$$D.getField("items")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$D])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (TestDataverse.Dataset1)  |PARTITIONED|
+                      data-scan []<-[$$29, $$D] <- TestDataverse.Dataset1
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                          empty-tuple-source
+                          -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/any-and-every-2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/any-and-every-2.plan
index b482afb..5687310 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/any-and-every-2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/any-and-every-2.plan
@@ -1,26 +1,46 @@
+distribute result [$$42]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$42])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$42] <- [{"D": $$D}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$D])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and($$38, eq($$39, 0)))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$D, $$38, $$39])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$38, $$39] <- [non-empty-stream(), agg-sql-count(switch-case(and($$35, eq($$36, 0)), true, NULL, true))]
                         -- AGGREGATE  |LOCAL|
-                          -- SUBPLAN  |LOCAL|
-                                  {
+                          subplan {
+                                    aggregate [$$35, $$36] <- [non-empty-stream(), agg-sql-count(switch-case(eq($$J, 1), true, NULL, true))]
                                     -- AGGREGATE  |LOCAL|
+                                      unnest $$J <- scan-collection($$45)
                                       -- UNNEST  |LOCAL|
+                                        nested tuple source
                                         -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                  }
+                                 }
+                          -- SUBPLAN  |LOCAL|
+                            assign [$$45] <- [$$I.getField("items")]
                             -- ASSIGN  |LOCAL|
+                              unnest $$I <- scan-collection($$44)
                               -- UNNEST  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                assign [$$44] <- [$$D.getField("items")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$D])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (TestDataverse.Dataset1)  |PARTITIONED|
+                      data-scan []<-[$$43, $$D] <- TestDataverse.Dataset1
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                          empty-tuple-source
+                          -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/any-and-every-3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/any-and-every-3.plan
index d865914..0136fed 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/any-and-every-3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/any-and-every-3.plan
@@ -1,20 +1,37 @@
+distribute result [$$41]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$41])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$41] <- [{"D": $$D}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$D])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and($$37, eq($$38, 0)))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$D, $$37, $$38])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$37, $$38] <- [non-empty-stream(), agg-sql-count(switch-case(and(eq($$I, 1), eq($$J, 2)), true, NULL, true))]
                         -- AGGREGATE  |LOCAL|
+                          unnest $$J <- scan-collection($$44)
                           -- UNNEST  |LOCAL|
+                            unnest $$I <- scan-collection($$43)
                             -- UNNEST  |LOCAL|
+                              nested tuple source
                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                assign [$$44, $$43] <- [$$D.getField("other_items"), $$D.getField("items")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$D])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (TestDataverse.Dataset1)  |PARTITIONED|
+                      data-scan []<-[$$42, $$D] <- TestDataverse.Dataset1
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                          empty-tuple-source
+                          -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query1.plan
index d53724e..045259c 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query1.plan
@@ -1,23 +1,46 @@
+distribute result [$$33]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$33])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$33] <- [{"D": $$D, "DI": $$DI}]
       -- ASSIGN  |PARTITIONED|
+        select (and(eq($$DI.getField("field2"), 2), eq($$DI.getField("field3"), 3)))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$D, $$DI])
           -- STREAM_PROJECT  |PARTITIONED|
+            unnest $$DI <- scan-collection($$37)
             -- UNNEST  |PARTITIONED|
+              select (and(eq($$D.getField("field1"), 1), eq($$D.getField("field4"), 4)))
               -- STREAM_SELECT  |PARTITIONED|
+                assign [$$37] <- [$$D.getField("items")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$D])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (TestDataverse.Dataset1.Dataset1)  |PARTITIONED|
+                      unnest-map [$$34, $$D] <- index-search("Dataset1", 0, "TestDataverse", "Dataset1", false, false, 1, $$52, 1, $$52, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          distinct ([$$52])
                           -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$52)
                               -- STABLE_SORT [$$52(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$52])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- BTREE_SEARCH (TestDataverse.Dataset1.d1Idx)  |PARTITIONED|
+                                      unnest-map [$$48, $$49, $$50, $$51, $$52] <- index-search("d1Idx", 0, "TestDataverse", "Dataset1", false, false, 4, $$40, $$41, $$42, $$43, 4, $$44, $$45, $$46, $$47, true, true, true)
+                                      -- BTREE_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$40, $$41, $$42, $$43, $$44, $$45, $$46, $$47] <- [1, 2, 3, 4, 1, 2, 3, 4]
                                           -- ASSIGN  |PARTITIONED|
-                                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                            empty-tuple-source
+                                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query2.plan
index ab9c768..00d886a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query2.plan
@@ -1,23 +1,46 @@
+distribute result [$$37]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$37])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$37] <- [{"D": $$D, "DI": $$DI}]
       -- ASSIGN  |PARTITIONED|
+        select (and(eq($$DI.getField("field2"), 2), eq($$DI.getField("field3"), 3), eq($$DI.getField("field3_notindexed"), 3)))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$D, $$DI])
           -- STREAM_PROJECT  |PARTITIONED|
+            unnest $$DI <- scan-collection($$42)
             -- UNNEST  |PARTITIONED|
+              select (and(eq($$D.getField("field4"), 4), eq($$D.getField("field1"), 1), eq($$D.getField("field4_notindexed"), 4)))
               -- STREAM_SELECT  |PARTITIONED|
+                assign [$$42] <- [$$D.getField("items")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$D])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (TestDataverse.Dataset1.Dataset1)  |PARTITIONED|
+                      unnest-map [$$38, $$D] <- index-search("Dataset1", 0, "TestDataverse", "Dataset1", false, false, 1, $$58, 1, $$58, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          distinct ([$$58])
                           -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$58)
                               -- STABLE_SORT [$$58(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$58])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- BTREE_SEARCH (TestDataverse.Dataset1.d1Idx)  |PARTITIONED|
+                                      unnest-map [$$54, $$55, $$56, $$57, $$58] <- index-search("d1Idx", 0, "TestDataverse", "Dataset1", false, false, 4, $$46, $$47, $$48, $$49, 4, $$50, $$51, $$52, $$53, true, true, true)
+                                      -- BTREE_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$46, $$47, $$48, $$49, $$50, $$51, $$52, $$53] <- [1, 2, 3, 4, 1, 2, 3, 4]
                                           -- ASSIGN  |PARTITIONED|
-                                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                            empty-tuple-source
+                                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query3.plan
index 2c6241a..998ff57 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query3.plan
@@ -1,27 +1,54 @@
+distribute result [$$48]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$48])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$48] <- [{"D": $$D, "DOI": $$DOI, "DII": $$DII}]
       -- ASSIGN  |PARTITIONED|
+        select (and(eq($$DII.getField("field2"), 2), eq($$DII.getField("field3"), 3), eq($$DII.getField("field3_notindexed"), 3)))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$D, $$DOI, $$DII])
           -- STREAM_PROJECT  |PARTITIONED|
+            unnest $$DII <- scan-collection($$54)
             -- UNNEST  |PARTITIONED|
+              select (eq($$DOI.getField("field2_notindexed"), 2))
               -- STREAM_SELECT  |PARTITIONED|
+                assign [$$54] <- [$$DOI.getField("inner_items")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$D, $$DOI])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    unnest $$DOI <- scan-collection($$52)
                     -- UNNEST  |PARTITIONED|
+                      select (and(eq($$D.getField("field1"), 1), eq($$D.getField("field4"), 4)))
                       -- STREAM_SELECT  |PARTITIONED|
+                        assign [$$52] <- [$$D.getField("outer_items")]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$D])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (TestDataverse.Dataset1.Dataset1)  |PARTITIONED|
+                              unnest-map [$$49, $$D] <- index-search("Dataset1", 0, "TestDataverse", "Dataset1", false, false, 1, $$70, 1, $$70, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  distinct ([$$70])
                                   -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$70)
                                       -- STABLE_SORT [$$70(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$70])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- BTREE_SEARCH (TestDataverse.Dataset1.d1Idx)  |PARTITIONED|
+                                              unnest-map [$$66, $$67, $$68, $$69, $$70] <- index-search("d1Idx", 0, "TestDataverse", "Dataset1", false, false, 4, $$58, $$59, $$60, $$61, 4, $$62, $$63, $$64, $$65, true, true, true)
+                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  assign [$$58, $$59, $$60, $$61, $$62, $$63, $$64, $$65] <- [1, 2, 3, 4, 1, 2, 3, 4]
                                                   -- ASSIGN  |PARTITIONED|
-                                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                                    empty-tuple-source
+                                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query4.plan
index d25efc7..c00274e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query4.plan
@@ -1,31 +1,59 @@
+distribute result [$$35]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$35])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$35] <- [{"D": $$D}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$D])
         -- STREAM_PROJECT  |PARTITIONED|
+          select ($$30)
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$D, $$30])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$30] <- [non-empty-stream()]
                         -- AGGREGATE  |LOCAL|
+                          select (and(eq($$41, 2), eq($$40, 3)))
                           -- STREAM_SELECT  |LOCAL|
+                            assign [$$41, $$40] <- [$$DI.getField("field2"), $$DI.getField("field3")]
                             -- ASSIGN  |LOCAL|
+                              unnest $$DI <- scan-collection($$39)
                               -- UNNEST  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                select (and(eq($$D.getField("field1"), 1), eq($$D.getField("field4"), 4)))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$39] <- [$$D.getField("items")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$D])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (TestDataverse.Dataset1.Dataset1)  |PARTITIONED|
+                        unnest-map [$$36, $$D] <- index-search("Dataset1", 0, "TestDataverse", "Dataset1", false, false, 1, $$54, 1, $$54, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            distinct ([$$54])
                             -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$54)
                                 -- STABLE_SORT [$$54(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$54])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (TestDataverse.Dataset1.d1Idx)  |PARTITIONED|
+                                        unnest-map [$$50, $$51, $$52, $$53, $$54] <- index-search("d1Idx", 0, "TestDataverse", "Dataset1", false, false, 4, $$42, $$43, $$44, $$45, 4, $$46, $$47, $$48, $$49, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            assign [$$42, $$43, $$44, $$45, $$46, $$47, $$48, $$49] <- [1, 2, 3, 4, 1, 2, 3, 4]
                                             -- ASSIGN  |PARTITIONED|
-                                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                              empty-tuple-source
+                                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query5.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query5.plan
index df8e08b..4027a2b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query5.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query5.plan
@@ -1,40 +1,74 @@
+distribute result [$$52]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$52])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$52] <- [{"D": $$D}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$D])
         -- STREAM_PROJECT  |PARTITIONED|
+          select ($$47)
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$D, $$47])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$47] <- [non-empty-stream()]
                         -- AGGREGATE  |LOCAL|
+                          select ($$45)
                           -- STREAM_SELECT  |LOCAL|
-                            -- SUBPLAN  |LOCAL|
-                                    {
+                            subplan {
+                                      aggregate [$$45] <- [non-empty-stream()]
                                       -- AGGREGATE  |LOCAL|
+                                        select (and(eq($$61, 2), eq($$60, 3), eq($$59, 3)))
                                         -- STREAM_SELECT  |LOCAL|
+                                          assign [$$61, $$60, $$59] <- [$$DII.getField("field2"), $$DII.getField("field3"), $$DII.getField("field3_notindexed")]
                                           -- ASSIGN  |LOCAL|
+                                            unnest $$DII <- scan-collection($$58)
                                             -- UNNEST  |LOCAL|
+                                              nested tuple source
                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                    }
+                                   }
+                            -- SUBPLAN  |LOCAL|
+                              select (eq($$57, 2))
                               -- STREAM_SELECT  |LOCAL|
+                                assign [$$58, $$57] <- [$$DOI.getField("inner_items"), $$DOI.getField("field2_notindexed")]
                                 -- ASSIGN  |LOCAL|
+                                  unnest $$DOI <- scan-collection($$56)
                                   -- UNNEST  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                select (and(eq($$D.getField("field1"), 1), eq($$D.getField("field4"), 4)))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$56] <- [$$D.getField("outer_items")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$D])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (TestDataverse.Dataset1.Dataset1)  |PARTITIONED|
+                        unnest-map [$$53, $$D] <- index-search("Dataset1", 0, "TestDataverse", "Dataset1", false, false, 1, $$76, 1, $$76, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            distinct ([$$76])
                             -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$76)
                                 -- STABLE_SORT [$$76(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$76])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (TestDataverse.Dataset1.d1Idx)  |PARTITIONED|
+                                        unnest-map [$$72, $$73, $$74, $$75, $$76] <- index-search("d1Idx", 0, "TestDataverse", "Dataset1", false, false, 4, $$64, $$65, $$66, $$67, 4, $$68, $$69, $$70, $$71, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            assign [$$64, $$65, $$66, $$67, $$68, $$69, $$70, $$71] <- [1, 2, 3, 4, 1, 2, 3, 4]
                                             -- ASSIGN  |PARTITIONED|
-                                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                              empty-tuple-source
+                                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query6.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query6.plan
index 492b219..f03b734 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query6.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query6.plan
@@ -1,33 +1,66 @@
+distribute result [$$69]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$69])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$69] <- [{"D2": $$D2, "D1IV": {"field1": $$85, "field2": $$86, "field3": $$87, "field4": $$88}}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$D2, $$88, $$85, $$87, $$86])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and(eq($$86, $$73), eq($$87, $$75), eq($$88, $$77), eq($$85, $$79)))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$D2, $$79, $$77, $$75, $$73, $$88, $$85, $$87, $$86])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$87, $$86] <- [$$D1I.getField("field3"), $$D1I.getField("field2")]
               -- ASSIGN  |PARTITIONED|
+                project ([$$D2, $$79, $$77, $$75, $$73, $$88, $$85, $$D1I])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$D1I <- scan-collection($$84)
                   -- UNNEST  |PARTITIONED|
+                    project ([$$D2, $$79, $$77, $$75, $$73, $$88, $$85, $$84])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$88, $$85, $$84] <- [$$D1.getField("field4"), $$D1.getField("field1"), $$D1.getField("items")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$D2, $$79, $$77, $$75, $$73, $$D1])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (TestDataverse.Dataset1.Dataset1)  |PARTITIONED|
+                            unnest-map [$$71, $$D1] <- index-search("Dataset1", 0, "TestDataverse", "Dataset1", true, false, 1, $$93, 1, $$93, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$93, $$D2, $$79, $$77, $$75, $$73])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    distinct ([$$93, $$94])
                                     -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        order (ASC, $$93) (ASC, $$94)
                                         -- STABLE_SORT [$$93(ASC), $$94(ASC)]  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$D2, $$79, $$77, $$75, $$73, $$94, $$93])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- BTREE_SEARCH (TestDataverse.Dataset1.d1Idx)  |PARTITIONED|
+                                                unnest-map [$$89, $$90, $$91, $$92, $$93] <- index-search("d1Idx", 0, "TestDataverse", "Dataset1", true, true, 4, $$79, $$73, $$75, $$77, 4, $$79, $$73, $$75, $$77, true, true, true)
+                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                  exchange
                                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                    running-aggregate [$$94] <- [create-query-uid()]
                                                     -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                      assign [$$79, $$77, $$75, $$73] <- [to-bigint($$D2.getField("field1")), to-bigint($$D2.getField("field4")), to-bigint($$D2.getField("field3")), to-bigint($$D2.getField("field2"))]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        project ([$$D2])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- DATASOURCE_SCAN (TestDataverse.Dataset2)  |PARTITIONED|
+                                                            data-scan []<-[$$70, $$D2] <- TestDataverse.Dataset2
+                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                empty-tuple-source
                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query7.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query7.plan
index 63544ef..e9058b1 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query7.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query7.plan
@@ -1,33 +1,66 @@
+distribute result [$$79]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$79])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$79] <- [{"D2": $$D2, "D1IV": {"field1_notindexed": $$101, "field1": $$102, "field2": $$103, "field3": $$104, "field3_notindexed": $$105, "field4": $$106}}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$D2, $$106, $$102, $$101, $$105, $$104, $$103])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and(eq($$101, $$83), eq($$103, $$85), eq($$104, $$87), eq($$105, $$89), eq($$106, $$91), eq($$102, $$93)))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$D2, $$93, $$91, $$89, $$87, $$85, $$83, $$106, $$102, $$101, $$105, $$104, $$103])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$105, $$104, $$103] <- [$$D1I.getField("field3_notindexed"), $$D1I.getField("field3"), $$D1I.getField("field2")]
               -- ASSIGN  |PARTITIONED|
+                project ([$$D2, $$93, $$91, $$89, $$87, $$85, $$83, $$106, $$102, $$101, $$D1I])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$D1I <- scan-collection($$100)
                   -- UNNEST  |PARTITIONED|
+                    project ([$$D2, $$93, $$91, $$89, $$87, $$85, $$83, $$106, $$102, $$101, $$100])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$106, $$102, $$101, $$100] <- [$$D1.getField("field4"), $$D1.getField("field1"), $$D1.getField("field1_notindexed"), $$D1.getField("items")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$D2, $$93, $$91, $$89, $$87, $$85, $$83, $$D1])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (TestDataverse.Dataset1.Dataset1)  |PARTITIONED|
+                            unnest-map [$$81, $$D1] <- index-search("Dataset1", 0, "TestDataverse", "Dataset1", true, false, 1, $$111, 1, $$111, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$111, $$D2, $$93, $$91, $$89, $$87, $$85, $$83])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    distinct ([$$111, $$112])
                                     -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        order (ASC, $$111) (ASC, $$112)
                                         -- STABLE_SORT [$$111(ASC), $$112(ASC)]  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$D2, $$93, $$91, $$89, $$87, $$85, $$83, $$112, $$111])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- BTREE_SEARCH (TestDataverse.Dataset1.d1Idx)  |PARTITIONED|
+                                                unnest-map [$$107, $$108, $$109, $$110, $$111] <- index-search("d1Idx", 0, "TestDataverse", "Dataset1", true, true, 4, $$93, $$85, $$87, $$91, 4, $$93, $$85, $$87, $$91, true, true, true)
+                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                  exchange
                                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                    running-aggregate [$$112] <- [create-query-uid()]
                                                     -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                      assign [$$93, $$91, $$89, $$87, $$85, $$83] <- [to-bigint($$D2.getField("field1")), to-bigint($$D2.getField("field4")), to-bigint($$D2.getField("field3_notindexed")), to-bigint($$D2.getField("field3")), to-bigint($$D2.getField("field2")), to-bigint($$D2.getField("field1_notindexed"))]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        project ([$$D2])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- DATASOURCE_SCAN (TestDataverse.Dataset2)  |PARTITIONED|
+                                                            data-scan []<-[$$80, $$D2] <- TestDataverse.Dataset2
+                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                empty-tuple-source
                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query8.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query8.plan
index 3f740b0..9cb42fc 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query8.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query8.plan
@@ -1,38 +1,73 @@
+distribute result [$$54]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$54])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$54] <- [{"D2": $$D2, "D1": $$D1}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$D2, $$D1])
         -- STREAM_PROJECT  |PARTITIONED|
+          select ($$47)
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$D2, $$D1, $$47])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$47] <- [non-empty-stream()]
                         -- AGGREGATE  |LOCAL|
+                          select (and(eq($$66, to-bigint($$67)), eq($$64, to-bigint($$65))))
                           -- STREAM_SELECT  |LOCAL|
+                            assign [$$66, $$64] <- [$$D1I.getField("field2"), $$D1I.getField("field3")]
                             -- ASSIGN  |LOCAL|
+                              unnest $$D1I <- scan-collection($$63)
                               -- UNNEST  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                assign [$$63] <- [$$D1.getField("items")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$D2, $$67, $$65, $$D1])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (TestDataverse.Dataset1.Dataset1)  |PARTITIONED|
+                      unnest-map [$$56, $$D1] <- index-search("Dataset1", 0, "TestDataverse", "Dataset1", true, false, 1, $$74, 1, $$74, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$74, $$D2, $$67, $$65])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              distinct ([$$74, $$75])
                               -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- STABLE_SORT [$$77(ASC), $$78(ASC)]  |PARTITIONED|
+                                  order (ASC, $$74) (ASC, $$75)
+                                  -- STABLE_SORT [$$74(ASC), $$75(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$D2, $$67, $$65, $$74, $$75])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (TestDataverse.Dataset1.d1Idx)  |PARTITIONED|
+                                          unnest-map [$$70, $$71, $$72, $$73, $$74] <- index-search("d1Idx", 0, "TestDataverse", "Dataset1", true, true, 4, $$58, $$68, $$69, $$60, 4, $$58, $$68, $$69, $$60, true, true, true)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                              running-aggregate [$$75] <- [create-query-uid()]
                                               -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                assign [$$69, $$68] <- [to-bigint($$65), to-bigint($$67)]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  assign [$$60, $$58, $$67, $$65] <- [to-bigint($$D2.getField("field4")), to-bigint($$D2.getField("field1")), $$D2.getField("field2"), $$D2.getField("field3")]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$D2])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (TestDataverse.Dataset2)  |PARTITIONED|
+                                                        data-scan []<-[$$55, $$D2] <- TestDataverse.Dataset2
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query9.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query9.plan
index ed318b1..e393017 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query9.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/atomic-and-array-queries/query9.plan
@@ -1,47 +1,88 @@
+distribute result [$$75]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$75])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$75] <- [{"D2": $$D2, "D1": $$D1}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$D2, $$D1])
         -- STREAM_PROJECT  |PARTITIONED|
+          select ($$68)
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$D2, $$D1, $$68])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$68] <- [non-empty-stream()]
                         -- AGGREGATE  |LOCAL|
+                          select ($$66)
                           -- STREAM_SELECT  |LOCAL|
-                            -- SUBPLAN  |LOCAL|
-                                    {
+                            subplan {
+                                      aggregate [$$66] <- [non-empty-stream()]
                                       -- AGGREGATE  |LOCAL|
+                                        select (and(eq($$92, to-bigint($$93)), eq($$90, to-bigint($$91)), eq($$88, to-bigint($$89))))
                                         -- STREAM_SELECT  |LOCAL|
+                                          assign [$$92, $$90, $$88] <- [$$DII.getField("field2"), $$DII.getField("field3"), $$DII.getField("field3_notindexed")]
                                           -- ASSIGN  |LOCAL|
+                                            unnest $$DII <- scan-collection($$87)
                                             -- UNNEST  |LOCAL|
+                                              nested tuple source
                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                    }
+                                   }
+                            -- SUBPLAN  |LOCAL|
+                              select (eq($$85, to-bigint($$86)))
                               -- STREAM_SELECT  |LOCAL|
+                                assign [$$87, $$85] <- [$$DOI.getField("inner_items"), $$DOI.getField("field2_notindexed")]
                                 -- ASSIGN  |LOCAL|
+                                  unnest $$DOI <- scan-collection($$84)
                                   -- UNNEST  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                assign [$$84] <- [$$D1.getField("outer_items")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$D2, $$93, $$91, $$89, $$86, $$D1])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (TestDataverse.Dataset1.Dataset1)  |PARTITIONED|
+                      unnest-map [$$77, $$D1] <- index-search("Dataset1", 0, "TestDataverse", "Dataset1", true, false, 1, $$104, 1, $$104, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$104, $$D2, $$93, $$91, $$89, $$86])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              distinct ([$$104, $$105])
                               -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- STABLE_SORT [$$108(ASC), $$109(ASC)]  |PARTITIONED|
+                                  order (ASC, $$104) (ASC, $$105)
+                                  -- STABLE_SORT [$$104(ASC), $$105(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$D2, $$93, $$91, $$89, $$86, $$104, $$105])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (TestDataverse.Dataset1.d1Idx)  |PARTITIONED|
+                                          unnest-map [$$100, $$101, $$102, $$103, $$104] <- index-search("d1Idx", 0, "TestDataverse", "Dataset1", true, true, 4, $$79, $$96, $$97, $$81, 4, $$79, $$96, $$97, $$81, true, true, true)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                              running-aggregate [$$105] <- [create-query-uid()]
                                               -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                assign [$$97, $$96] <- [to-bigint($$91), to-bigint($$93)]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  assign [$$81, $$79, $$93, $$91, $$89, $$86] <- [to-bigint($$D2.getField("field4")), to-bigint($$D2.getField("field1")), $$D2.getField("field2"), $$D2.getField("field3"), $$D2.getField("field3_notindexed"), $$D2.getField("field2_notindexed")]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$D2])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (TestDataverse.Dataset2)  |PARTITIONED|
+                                                        data-scan []<-[$$76, $$D2] <- TestDataverse.Dataset2
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-1/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-1/query1.plan
index 7306c4d..a4937ed 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-1/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-1/query1.plan
@@ -1,39 +1,75 @@
+distribute result [$$52]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$52])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$52] <- [{"$1": $$55}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$55] <- [agg-sql-sum($$59)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$59] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select ($$42)
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$42])
                 -- STREAM_PROJECT  |PARTITIONED|
-                  -- SUBPLAN  |PARTITIONED|
-                          {
+                  subplan {
+                            aggregate [$$42] <- [non-empty-stream()]
                             -- AGGREGATE  |LOCAL|
+                              select (eq($$58, $#4))
                               -- STREAM_SELECT  |LOCAL|
+                                unnest $#4 <- scan-collection($$57)
                                 -- UNNEST  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                         }
+                  -- SUBPLAN  |PARTITIONED|
+                    project ([$$58, $$57])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      select (eq($$C.getField(1), "--Ni3oJ4VOqfOEu7Sj2Vzg"))
                       -- STREAM_SELECT  |PARTITIONED|
+                        assign [$$57] <- [$$C.getField(2)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$58, $$C])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                              unnest-map [$$54, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", true, false, 1, $$61, 1, $$61, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$61, $$58])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      distinct ([$$61, $$53])
                                       -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          order (ASC, $$61) (ASC, $$53)
                                           -- STABLE_SORT [$$61(ASC), $$53(ASC)]  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$53, $$58, $$61])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                                  unnest-map [$$60, $$61] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", true, true, 1, $$58, 1, $$58, true, true, true)
+                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                    exchange
                                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                      project ([$$53, $$58])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$58] <- [$$M.getField(2)]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                            data-scan []<-[$$53, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                                                empty-tuple-source
+                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-1/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-1/query2.plan
index cb70d4f..9a35ba5 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-1/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-1/query2.plan
@@ -1,39 +1,75 @@
+distribute result [$$60]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$60])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$60] <- [{"$1": $$63}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$63] <- [agg-sql-sum($$67)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$67] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select ($$52)
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$52])
                 -- STREAM_PROJECT  |PARTITIONED|
-                  -- SUBPLAN  |PARTITIONED|
-                          {
+                  subplan {
+                            aggregate [$$52] <- [non-empty-stream()]
                             -- AGGREGATE  |LOCAL|
+                              select (eq($$66, $$D))
                               -- STREAM_SELECT  |LOCAL|
+                                unnest $$D <- scan-collection($$65)
                                 -- UNNEST  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                         }
+                  -- SUBPLAN  |PARTITIONED|
+                    project ([$$66, $$65])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      select (eq($$C.getField(1), "--Ni3oJ4VOqfOEu7Sj2Vzg"))
                       -- STREAM_SELECT  |PARTITIONED|
+                        assign [$$65] <- [$$C.getField(2)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$66, $$C])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                              unnest-map [$$62, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", true, false, 1, $$69, 1, $$69, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$69, $$66])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      distinct ([$$69, $$61])
                                       -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          order (ASC, $$69) (ASC, $$61)
                                           -- STABLE_SORT [$$69(ASC), $$61(ASC)]  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$61, $$66, $$69])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                                  unnest-map [$$68, $$69] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", true, true, 1, $$66, 1, $$66, true, true, true)
+                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                    exchange
                                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                      project ([$$61, $$66])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$66] <- [$$M.getField(2)]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                            data-scan []<-[$$61, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                                                empty-tuple-source
+                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-1/query3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-1/query3.plan
index b81bf80..0a75680 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-1/query3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-1/query3.plan
@@ -1,39 +1,75 @@
+distribute result [$$63]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$63])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$63] <- [{"$1": $$66}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$66] <- [agg-sql-sum($$71)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$71] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select ($$55)
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$55])
                 -- STREAM_PROJECT  |PARTITIONED|
-                  -- SUBPLAN  |PARTITIONED|
-                          {
+                  subplan {
+                            aggregate [$$55] <- [empty-stream()]
                             -- AGGREGATE  |LOCAL|
+                              select (not(if-missing-or-null(eq($$70, $$D), false)))
                               -- STREAM_SELECT  |LOCAL|
+                                unnest $$D <- scan-collection($$68)
                                 -- UNNEST  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                         }
+                  -- SUBPLAN  |PARTITIONED|
+                    project ([$$70, $$68])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      select (and(gt(len($$68), 0), eq($$C.getField(1), "--Ni3oJ4VOqfOEu7Sj2Vzg")))
                       -- STREAM_SELECT  |PARTITIONED|
+                        assign [$$68] <- [$$C.getField(2)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$70, $$C])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                              unnest-map [$$65, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", true, false, 1, $$73, 1, $$73, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$73, $$70])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      distinct ([$$73, $$64])
                                       -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          order (ASC, $$73) (ASC, $$64)
                                           -- STABLE_SORT [$$73(ASC), $$64(ASC)]  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$64, $$70, $$73])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                                  unnest-map [$$72, $$73] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", true, true, 1, $$70, 1, $$70, true, true, true)
+                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                    exchange
                                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                      project ([$$64, $$70])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$70] <- [$$M.getField(2)]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                            data-scan []<-[$$64, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                                                empty-tuple-source
+                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-1/query4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-1/query4.plan
index d7acd37..acec03e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-1/query4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-1/query4.plan
@@ -1,65 +1,124 @@
+distribute result [$$67]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$67])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$67] <- [{"$1": $$71}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$71] <- [agg-sql-sum($$76)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$76] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select ($$59)
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$59])
                 -- STREAM_PROJECT  |PARTITIONED|
-                  -- SUBPLAN  |PARTITIONED|
-                          {
+                  subplan {
+                            aggregate [$$59] <- [non-empty-stream()]
                             -- AGGREGATE  |LOCAL|
+                              select (eq($$73, $#5))
                               -- STREAM_SELECT  |LOCAL|
+                                unnest $#5 <- scan-collection($$74)
                                 -- UNNEST  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                         }
+                  -- SUBPLAN  |PARTITIONED|
+                    project ([$$73, $$74])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$74] <- [$$B.getField(2)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$73, $$B])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (TestYelp.YelpCheckinB.YelpCheckinB)  |PARTITIONED|
+                            unnest-map [$$70, $$B] <- index-search("YelpCheckinB", 0, "TestYelp", "YelpCheckinB", true, false, 1, $$80, 1, $$80, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$80, $$73])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    distinct ([$$80, $$81])
                                     -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        order (ASC, $$80) (ASC, $$81)
                                         -- STABLE_SORT [$$80(ASC), $$81(ASC)]  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$73, $$81, $$80])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- BTREE_SEARCH (TestYelp.YelpCheckinB.IdxYelpCheckinBDates)  |PARTITIONED|
+                                                unnest-map [$$79, $$80] <- index-search("IdxYelpCheckinBDates", 0, "TestYelp", "YelpCheckinB", true, true, 1, $$73, 1, $$73, true, true, true)
+                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                  exchange
                                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                    running-aggregate [$$81] <- [create-query-uid()]
                                                     -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                      project ([$$73])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        select ($$55)
                                                         -- STREAM_SELECT  |PARTITIONED|
+                                                          project ([$$73, $$55])
                                                           -- STREAM_PROJECT  |PARTITIONED|
-                                                            -- SUBPLAN  |PARTITIONED|
-                                                                    {
+                                                            subplan {
+                                                                      aggregate [$$55] <- [non-empty-stream()]
                                                                       -- AGGREGATE  |LOCAL|
+                                                                        select (eq($$73, $#4))
                                                                         -- STREAM_SELECT  |LOCAL|
+                                                                          unnest $#4 <- scan-collection($$72)
                                                                           -- UNNEST  |LOCAL|
+                                                                            nested tuple source
                                                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                    }
+                                                                   }
+                                                            -- SUBPLAN  |PARTITIONED|
+                                                              project ([$$73, $$72])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$72] <- [$$A.getField(2)]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  project ([$$73, $$A])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- BTREE_SEARCH (TestYelp.YelpCheckinA.YelpCheckinA)  |PARTITIONED|
+                                                                      unnest-map [$$69, $$A] <- index-search("YelpCheckinA", 0, "TestYelp", "YelpCheckinA", true, false, 1, $$78, 1, $$78, true, true, true)
+                                                                      -- BTREE_SEARCH  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          project ([$$78, $$73])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              distinct ([$$78, $$68])
                                                                               -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  order (ASC, $$78) (ASC, $$68)
                                                                                   -- STABLE_SORT [$$78(ASC), $$68(ASC)]  |PARTITIONED|
+                                                                                    exchange
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                      project ([$$68, $$73, $$78])
                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                        exchange
                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                          -- BTREE_SEARCH (TestYelp.YelpCheckinA.IdxYelpCheckinADates)  |PARTITIONED|
+                                                                                          unnest-map [$$77, $$78] <- index-search("IdxYelpCheckinADates", 0, "TestYelp", "YelpCheckinA", true, true, 1, $$73, 1, $$73, true, true, true)
+                                                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                                                            exchange
                                                                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                              project ([$$68, $$73])
                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                assign [$$73] <- [$$M.getField(2)]
                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                  exchange
                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                    -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                                                                    data-scan []<-[$$68, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                      exchange
                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                        empty-tuple-source
                                                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-1/query5.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-1/query5.plan
index e06e50b..2d24b12 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-1/query5.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-1/query5.plan
@@ -1,38 +1,73 @@
+distribute result [$$62]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$62])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$62] <- [{"$1": $$65}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$65] <- [agg-sql-sum($$69)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$69] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and($$52, eq($$53, 0)))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$52, $$53])
                 -- STREAM_PROJECT  |PARTITIONED|
-                  -- SUBPLAN  |PARTITIONED|
-                          {
+                  subplan {
+                            aggregate [$$52, $$53] <- [non-empty-stream(), agg-sql-count(switch-case(eq($$68, $$D), true, NULL, true))]
                             -- AGGREGATE  |LOCAL|
+                              unnest $$D <- scan-collection($$67)
                               -- UNNEST  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                         }
+                  -- SUBPLAN  |PARTITIONED|
+                    project ([$$68, $$67])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      select (eq($$C.getField(1), "--Ni3oJ4VOqfOEu7Sj2Vzg"))
                       -- STREAM_SELECT  |PARTITIONED|
+                        assign [$$67] <- [$$C.getField(2)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$68, $$C])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                              unnest-map [$$64, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", true, false, 1, $$71, 1, $$71, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$71, $$68])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      distinct ([$$71, $$63])
                                       -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          order (ASC, $$71) (ASC, $$63)
                                           -- STABLE_SORT [$$71(ASC), $$63(ASC)]  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$63, $$68, $$71])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                                  unnest-map [$$70, $$71] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", true, true, 1, $$68, 1, $$68, true, true, true)
+                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                    exchange
                                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                      project ([$$63, $$68])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$68] <- [$$M.getField(2)]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                            data-scan []<-[$$63, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                                                empty-tuple-source
+                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-2/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-2/query1.plan
index 641e620..57a5e5a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-2/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-2/query1.plan
@@ -1,39 +1,75 @@
+distribute result [$$53]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$53])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$53] <- [{"$1": $$56}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$56] <- [agg-sql-sum($$61)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$61] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select ($$43)
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$43])
                 -- STREAM_PROJECT  |PARTITIONED|
-                  -- SUBPLAN  |PARTITIONED|
-                          {
+                  subplan {
+                            aggregate [$$43] <- [non-empty-stream()]
                             -- AGGREGATE  |LOCAL|
+                              select (eq($$59, $#4))
                               -- STREAM_SELECT  |LOCAL|
+                                unnest $#4 <- scan-collection($$58)
                                 -- UNNEST  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                         }
+                  -- SUBPLAN  |PARTITIONED|
+                    project ([$$59, $$58])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$58] <- [$$C.getField(2).getField(0)]
                       -- ASSIGN  |PARTITIONED|
+                        select (eq($$C.getField(1), "--Ni3oJ4VOqfOEu7Sj2Vzg"))
                         -- STREAM_SELECT  |PARTITIONED|
+                          project ([$$59, $$C])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                              unnest-map [$$55, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", true, false, 1, $$63, 1, $$63, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$63, $$59])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      distinct ([$$63, $$54])
                                       -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          order (ASC, $$63) (ASC, $$54)
                                           -- STABLE_SORT [$$63(ASC), $$54(ASC)]  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$54, $$59, $$63])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                                  unnest-map [$$62, $$63] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", true, true, 1, $$59, 1, $$59, true, true, true)
+                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                    exchange
                                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                      project ([$$54, $$59])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$59] <- [$$M.getField(2)]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                            data-scan []<-[$$54, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                                                empty-tuple-source
+                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-2/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-2/query2.plan
index 109cc05..f8c6ed8 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-2/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-2/query2.plan
@@ -1,38 +1,73 @@
+distribute result [$$63]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$63])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$63] <- [{"$1": $$66}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$66] <- [agg-sql-sum($$71)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$71] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and($$53, eq($$54, 0)))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$53, $$54])
                 -- STREAM_PROJECT  |PARTITIONED|
-                  -- SUBPLAN  |PARTITIONED|
-                          {
+                  subplan {
+                            aggregate [$$53, $$54] <- [non-empty-stream(), agg-sql-count(switch-case(eq($$69, $$D), true, NULL, true))]
                             -- AGGREGATE  |LOCAL|
+                              unnest $$D <- scan-collection($$68)
                               -- UNNEST  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                         }
+                  -- SUBPLAN  |PARTITIONED|
+                    project ([$$69, $$68])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$68] <- [$$C.getField(2).getField(0)]
                       -- ASSIGN  |PARTITIONED|
+                        select (eq($$C.getField(1), "--Ni3oJ4VOqfOEu7Sj2Vzg"))
                         -- STREAM_SELECT  |PARTITIONED|
+                          project ([$$69, $$C])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                              unnest-map [$$65, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", true, false, 1, $$73, 1, $$73, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$73, $$69])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      distinct ([$$73, $$64])
                                       -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          order (ASC, $$73) (ASC, $$64)
                                           -- STABLE_SORT [$$73(ASC), $$64(ASC)]  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$64, $$69, $$73])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                                  unnest-map [$$72, $$73] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", true, true, 1, $$69, 1, $$69, true, true, true)
+                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                    exchange
                                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                      project ([$$64, $$69])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$69] <- [$$M.getField(2)]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                            data-scan []<-[$$64, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                                                empty-tuple-source
+                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-2/query3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-2/query3.plan
index d895e99..2a8df29 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-2/query3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-2/query3.plan
@@ -1,35 +1,67 @@
+distribute result [$$61]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$61])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$61] <- [{"$1": $$64}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$64] <- [agg-sql-sum($$69)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$69] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select ($$53)
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$53])
                 -- STREAM_PROJECT  |PARTITIONED|
-                  -- SUBPLAN  |PARTITIONED|
-                          {
+                  subplan {
+                            aggregate [$$53] <- [empty-stream()]
                             -- AGGREGATE  |LOCAL|
+                              select (not(if-missing-or-null(eq($$67, $$D), false)))
                               -- STREAM_SELECT  |LOCAL|
+                                unnest $$D <- scan-collection($$66)
                                 -- UNNEST  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                         }
+                  -- SUBPLAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (true)
                       -- NESTED_LOOP  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$67])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$67] <- [$$M.getField(2)]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$M])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                  data-scan []<-[$$62, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                          project ([$$66])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$66] <- [$$C.getField(2).getField(0)]
                             -- ASSIGN  |PARTITIONED|
+                              select (eq($$C.getField(1), "--Ni3oJ4VOqfOEu7Sj2Vzg"))
                               -- STREAM_SELECT  |PARTITIONED|
+                                project ([$$C])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                                    data-scan []<-[$$63, $$C] <- TestYelp.YelpCheckin
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                        empty-tuple-source
+                                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-3/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-3/query1.plan
index 09bcc02..c77f310 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-3/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-3/query1.plan
@@ -1,40 +1,77 @@
+distribute result [$$61]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$61])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$61] <- [{"$1": $$64}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$64] <- [agg-sql-sum($$69)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$69] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select ($$51)
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$51])
                 -- STREAM_PROJECT  |PARTITIONED|
-                  -- SUBPLAN  |PARTITIONED|
-                          {
+                  subplan {
+                            aggregate [$$51] <- [non-empty-stream()]
                             -- AGGREGATE  |LOCAL|
+                              select (eq($$67, $$68))
                               -- STREAM_SELECT  |LOCAL|
+                                assign [$$67] <- [$$D.getField(0)]
                                 -- ASSIGN  |LOCAL|
+                                  unnest $$D <- scan-collection($$66)
                                   -- UNNEST  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                         }
+                  -- SUBPLAN  |PARTITIONED|
+                    project ([$$68, $$66])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      select (eq($$C.getField(1), "--Ni3oJ4VOqfOEu7Sj2Vzg"))
                       -- STREAM_SELECT  |PARTITIONED|
+                        assign [$$66] <- [$$C.getField(2)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$68, $$C])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                              unnest-map [$$63, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", true, false, 1, $$71, 1, $$71, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$71, $$68])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      distinct ([$$71, $$62])
                                       -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          order (ASC, $$71) (ASC, $$62)
                                           -- STABLE_SORT [$$71(ASC), $$62(ASC)]  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$62, $$68, $$71])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                                  unnest-map [$$70, $$71] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", true, true, 1, $$68, 1, $$68, true, true, true)
+                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                    exchange
                                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                      project ([$$62, $$68])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$68] <- [$$M.getField(2)]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                            data-scan []<-[$$62, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                                                empty-tuple-source
+                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-3/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-3/query2.plan
index 7217e9f..43a95a8 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-3/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-3/query2.plan
@@ -1,39 +1,75 @@
+distribute result [$$63]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$63])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$63] <- [{"$1": $$66}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$66] <- [agg-sql-sum($$71)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$71] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and($$51, eq($$52, 0)))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$51, $$52])
                 -- STREAM_PROJECT  |PARTITIONED|
-                  -- SUBPLAN  |PARTITIONED|
-                          {
+                  subplan {
+                            aggregate [$$51, $$52] <- [non-empty-stream(), agg-sql-count(switch-case(eq($$69, $$70), true, NULL, true))]
                             -- AGGREGATE  |LOCAL|
+                              assign [$$69] <- [$$D.getField(0)]
                               -- ASSIGN  |LOCAL|
+                                unnest $$D <- scan-collection($$68)
                                 -- UNNEST  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                         }
+                  -- SUBPLAN  |PARTITIONED|
+                    project ([$$70, $$68])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      select (eq($$C.getField(1), "--Ni3oJ4VOqfOEu7Sj2Vzg"))
                       -- STREAM_SELECT  |PARTITIONED|
+                        assign [$$68] <- [$$C.getField(2)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$70, $$C])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                              unnest-map [$$65, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", true, false, 1, $$73, 1, $$73, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$73, $$70])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      distinct ([$$73, $$64])
                                       -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          order (ASC, $$73) (ASC, $$64)
                                           -- STABLE_SORT [$$73(ASC), $$64(ASC)]  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$64, $$70, $$73])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                                  unnest-map [$$72, $$73] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", true, true, 1, $$70, 1, $$70, true, true, true)
+                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                    exchange
                                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                      project ([$$64, $$70])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$70] <- [$$M.getField(2)]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                            data-scan []<-[$$64, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                                                empty-tuple-source
+                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-4/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-4/query1.plan
index 22f9aa6..1f8054b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-4/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-4/query1.plan
@@ -1,47 +1,88 @@
+distribute result [$$72]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$72])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$72] <- [{"$1": $$75}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$75] <- [agg-sql-sum($$82)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$82] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select ($$62)
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$62])
                 -- STREAM_PROJECT  |PARTITIONED|
-                  -- SUBPLAN  |PARTITIONED|
-                          {
+                  subplan {
+                            aggregate [$$62] <- [non-empty-stream()]
                             -- AGGREGATE  |LOCAL|
+                              select ($$61)
                               -- STREAM_SELECT  |LOCAL|
-                                -- SUBPLAN  |LOCAL|
-                                        {
+                                subplan {
+                                          aggregate [$$61] <- [non-empty-stream()]
                                           -- AGGREGATE  |LOCAL|
+                                            select (eq($$D, $$79))
                                             -- STREAM_SELECT  |LOCAL|
+                                              unnest $$D <- scan-collection($$78)
                                               -- UNNEST  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- SUBPLAN  |LOCAL|
+                                  assign [$$78] <- [$$CT.getField(1)]
                                   -- ASSIGN  |LOCAL|
+                                    unnest $$CT <- scan-collection($$77)
                                     -- UNNEST  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                         }
+                  -- SUBPLAN  |PARTITIONED|
+                    project ([$$79, $$77])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      select (eq($$C.getField(1), "--Ni3oJ4VOqfOEu7Sj2Vzg"))
                       -- STREAM_SELECT  |PARTITIONED|
+                        assign [$$77] <- [$$C.getField(2)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$79, $$C])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                              unnest-map [$$74, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", true, false, 1, $$84, 1, $$84, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$84, $$79])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      distinct ([$$84, $$73])
                                       -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          order (ASC, $$84) (ASC, $$73)
                                           -- STABLE_SORT [$$84(ASC), $$73(ASC)]  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$73, $$79, $$84])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                                  unnest-map [$$83, $$84] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", true, true, 1, $$79, 1, $$79, true, true, true)
+                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                    exchange
                                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                      project ([$$73, $$79])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$79] <- [$$M.getField(2)]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                            data-scan []<-[$$73, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                                                empty-tuple-source
+                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-4/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-4/query2.plan
index df73479..deb7d82 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-4/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-4/query2.plan
@@ -1,47 +1,88 @@
+distribute result [$$75]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$75])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$75] <- [{"$1": $$78}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$78] <- [agg-sql-sum($$86)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$86] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select ($$62)
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$62])
                 -- STREAM_PROJECT  |PARTITIONED|
-                  -- SUBPLAN  |PARTITIONED|
-                          {
+                  subplan {
+                            aggregate [$$62] <- [empty-stream()]
                             -- AGGREGATE  |LOCAL|
+                              select (not(if-missing-or-null($$61, false)))
                               -- STREAM_SELECT  |LOCAL|
-                                -- SUBPLAN  |LOCAL|
-                                        {
+                                subplan {
+                                          aggregate [$$61] <- [non-empty-stream()]
                                           -- AGGREGATE  |LOCAL|
+                                            select (eq($$D, $$83))
                                             -- STREAM_SELECT  |LOCAL|
+                                              unnest $$D <- scan-collection($$82)
                                               -- UNNEST  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- SUBPLAN  |LOCAL|
+                                  assign [$$82] <- [$$CT.getField(1)]
                                   -- ASSIGN  |LOCAL|
+                                    unnest $$CT <- scan-collection($$79)
                                     -- UNNEST  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                         }
+                  -- SUBPLAN  |PARTITIONED|
+                    project ([$$83, $$79])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      select (and(eq($$C.getField(1), "--Ni3oJ4VOqfOEu7Sj2Vzg"), gt(len($$79), 0)))
                       -- STREAM_SELECT  |PARTITIONED|
+                        assign [$$79] <- [$$C.getField(2)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$83, $$C])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                              unnest-map [$$77, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", true, false, 1, $$88, 1, $$88, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$88, $$83])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      distinct ([$$88, $$76])
                                       -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          order (ASC, $$88) (ASC, $$76)
                                           -- STABLE_SORT [$$88(ASC), $$76(ASC)]  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$76, $$83, $$88])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                                  unnest-map [$$87, $$88] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", true, true, 1, $$83, 1, $$83, true, true, true)
+                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                    exchange
                                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                      project ([$$76, $$83])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$83] <- [$$M.getField(2)]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                            data-scan []<-[$$76, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                                                empty-tuple-source
+                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-4/query3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-4/query3.plan
index 6c55934..8bfebef 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-4/query3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-4/query3.plan
@@ -1,45 +1,84 @@
+distribute result [$$76]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$76])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$76] <- [{"$1": $$79}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$79] <- [agg-sql-sum($$86)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$86] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and($$64, eq($$65, 0)))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$64, $$65])
                 -- STREAM_PROJECT  |PARTITIONED|
-                  -- SUBPLAN  |PARTITIONED|
-                          {
+                  subplan {
+                            aggregate [$$64, $$65] <- [non-empty-stream(), agg-sql-count(switch-case(and($$61, eq($$62, 0)), true, NULL, true))]
                             -- AGGREGATE  |LOCAL|
-                              -- SUBPLAN  |LOCAL|
-                                      {
+                              subplan {
+                                        aggregate [$$61, $$62] <- [non-empty-stream(), agg-sql-count(switch-case(eq($$D, $$83), true, NULL, true))]
                                         -- AGGREGATE  |LOCAL|
+                                          unnest $$D <- scan-collection($$82)
                                           -- UNNEST  |LOCAL|
+                                            nested tuple source
                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                      }
+                                     }
+                              -- SUBPLAN  |LOCAL|
+                                assign [$$82] <- [$$CT.getField(1)]
                                 -- ASSIGN  |LOCAL|
+                                  unnest $$CT <- scan-collection($$81)
                                   -- UNNEST  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                         }
+                  -- SUBPLAN  |PARTITIONED|
+                    project ([$$83, $$81])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      select (eq($$C.getField(1), "--Ni3oJ4VOqfOEu7Sj2Vzg"))
                       -- STREAM_SELECT  |PARTITIONED|
+                        assign [$$81] <- [$$C.getField(2)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$83, $$C])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                              unnest-map [$$78, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", true, false, 1, $$88, 1, $$88, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$88, $$83])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      distinct ([$$88, $$77])
                                       -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          order (ASC, $$88) (ASC, $$77)
                                           -- STABLE_SORT [$$88(ASC), $$77(ASC)]  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$77, $$83, $$88])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                                  unnest-map [$$87, $$88] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", true, true, 1, $$83, 1, $$83, true, true, true)
+                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                    exchange
                                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                      project ([$$77, $$83])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$83] <- [$$M.getField(2)]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                            data-scan []<-[$$77, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                                                empty-tuple-source
+                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-4/query4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-4/query4.plan
index 552ba9b..54776ed 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-4/query4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-quantified-queries/use-case-4/query4.plan
@@ -1,77 +1,142 @@
+distribute result [$$115]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$115])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$115] <- [{"$1": $$119}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$119] <- [agg-sql-sum($$130)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$130] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and($$105, eq($$106, 0)))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$105, $$106])
                 -- STREAM_PROJECT  |PARTITIONED|
-                  -- SUBPLAN  |PARTITIONED|
-                          {
+                  subplan {
+                            aggregate [$$105, $$106] <- [non-empty-stream(), agg-sql-count(switch-case(and($$102, eq($$103, 0)), true, NULL, true))]
                             -- AGGREGATE  |LOCAL|
-                              -- SUBPLAN  |LOCAL|
-                                      {
+                              subplan {
+                                        aggregate [$$102, $$103] <- [non-empty-stream(), agg-sql-count(switch-case(eq($$D, $$122), true, NULL, true))]
                                         -- AGGREGATE  |LOCAL|
+                                          unnest $$D <- scan-collection($$124)
                                           -- UNNEST  |LOCAL|
+                                            nested tuple source
                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                      }
+                                     }
+                              -- SUBPLAN  |LOCAL|
+                                assign [$$124] <- [$$CT.getField(1)]
                                 -- ASSIGN  |LOCAL|
+                                  unnest $$CT <- scan-collection($$123)
                                   -- UNNEST  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                         }
+                  -- SUBPLAN  |PARTITIONED|
+                    project ([$$122, $$123])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$123] <- [$$B.getField(2)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$122, $$B])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (TestYelp.YelpCheckinB.YelpCheckinB)  |PARTITIONED|
+                            unnest-map [$$118, $$B] <- index-search("YelpCheckinB", 0, "TestYelp", "YelpCheckinB", true, false, 1, $$134, 1, $$134, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$134, $$122])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    distinct ([$$134, $$135])
                                     -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        order (ASC, $$134) (ASC, $$135)
                                         -- STABLE_SORT [$$134(ASC), $$135(ASC)]  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$122, $$135, $$134])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- BTREE_SEARCH (TestYelp.YelpCheckinB.IdxYelpCheckinDatesB)  |PARTITIONED|
+                                                unnest-map [$$133, $$134] <- index-search("IdxYelpCheckinDatesB", 0, "TestYelp", "YelpCheckinB", true, true, 1, $$122, 1, $$122, true, true, true)
+                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                  exchange
                                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                    running-aggregate [$$135] <- [create-query-uid()]
                                                     -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                      project ([$$122])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        select (and($$95, eq($$96, 0)))
                                                         -- STREAM_SELECT  |PARTITIONED|
+                                                          project ([$$122, $$95, $$96])
                                                           -- STREAM_PROJECT  |PARTITIONED|
-                                                            -- SUBPLAN  |PARTITIONED|
-                                                                    {
+                                                            subplan {
+                                                                      aggregate [$$95, $$96] <- [non-empty-stream(), agg-sql-count(switch-case(and($$92, eq($$93, 0)), true, NULL, true))]
                                                                       -- AGGREGATE  |LOCAL|
-                                                                        -- SUBPLAN  |LOCAL|
-                                                                                {
+                                                                        subplan {
+                                                                                  aggregate [$$92, $$93] <- [non-empty-stream(), agg-sql-count(switch-case(eq($$D, $$122), true, NULL, true))]
                                                                                   -- AGGREGATE  |LOCAL|
+                                                                                    unnest $$D <- scan-collection($$121)
                                                                                     -- UNNEST  |LOCAL|
+                                                                                      nested tuple source
                                                                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                }
+                                                                               }
+                                                                        -- SUBPLAN  |LOCAL|
+                                                                          assign [$$121] <- [$$CT.getField(1)]
                                                                           -- ASSIGN  |LOCAL|
+                                                                            unnest $$CT <- scan-collection($$120)
                                                                             -- UNNEST  |LOCAL|
+                                                                              nested tuple source
                                                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                    }
+                                                                   }
+                                                            -- SUBPLAN  |PARTITIONED|
+                                                              project ([$$122, $$120])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$120] <- [$$A.getField(2)]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  project ([$$122, $$A])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- BTREE_SEARCH (TestYelp.YelpCheckinA.YelpCheckinA)  |PARTITIONED|
+                                                                      unnest-map [$$117, $$A] <- index-search("YelpCheckinA", 0, "TestYelp", "YelpCheckinA", true, false, 1, $$132, 1, $$132, true, true, true)
+                                                                      -- BTREE_SEARCH  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          project ([$$132, $$122])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              distinct ([$$132, $$116])
                                                                               -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  order (ASC, $$132) (ASC, $$116)
                                                                                   -- STABLE_SORT [$$132(ASC), $$116(ASC)]  |PARTITIONED|
+                                                                                    exchange
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                      project ([$$116, $$122, $$132])
                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                        exchange
                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                          -- BTREE_SEARCH (TestYelp.YelpCheckinA.IdxYelpCheckinDatesA)  |PARTITIONED|
+                                                                                          unnest-map [$$131, $$132] <- index-search("IdxYelpCheckinDatesA", 0, "TestYelp", "YelpCheckinA", true, true, 1, $$122, 1, $$122, true, true, true)
+                                                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                                                            exchange
                                                                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                              project ([$$116, $$122])
                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                assign [$$122] <- [$$M.getField(2)]
                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                  exchange
                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                    -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                                                                    data-scan []<-[$$116, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                      exchange
                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                        empty-tuple-source
                                                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-1/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-1/query1.plan
index fb3c603..0b60a19 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-1/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-1/query1.plan
@@ -1,32 +1,64 @@
+distribute result [$$41]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$41])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$41] <- [{"marker": $$42}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$42])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$D, $$44))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$42, $$44, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$46)
               -- UNNEST  |PARTITIONED|
+                project ([$$42, $$44, $$46])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (eq($$C.getField(1), "--Ni3oJ4VOqfOEu7Sj2Vzg"))
                   -- STREAM_SELECT  |PARTITIONED|
+                    assign [$$46] <- [$$C.getField(2)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$42, $$44, $$C])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                          unnest-map [$$43, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", true, false, 1, $$49, 1, $$49, true, true, true)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$49, $$42, $$44])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  distinct ([$$49, $$50])
                                   -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$49) (ASC, $$50)
                                       -- STABLE_SORT [$$49(ASC), $$50(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$42, $$44, $$50, $$49])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                              unnest-map [$$48, $$49] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", true, true, 1, $$44, 1, $$44, true, true, true)
+                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                exchange
                                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                  running-aggregate [$$50] <- [create-query-uid()]
                                                   -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                    project ([$$42, $$44])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      assign [$$44] <- [$$M.getField(1)]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                          data-scan []<-[$$42, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              empty-tuple-source
                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-1/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-1/query2.plan
index 70118a1..873dd44 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-1/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-1/query2.plan
@@ -1,32 +1,64 @@
+distribute result [$$41]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$41])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$41] <- [{"marker": $$42}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$42])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$D, $$44))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$42, $$44, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$46)
               -- UNNEST  |PARTITIONED|
+                project ([$$42, $$44, $$46])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$46] <- [$$C.getField(2)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$42, $$44, $$C])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                        unnest-map [$$43, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", true, false, 1, $$49, 1, $$49, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$49, $$42, $$44])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                distinct ([$$49, $$50])
                                 -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$49) (ASC, $$50)
                                     -- STABLE_SORT [$$49(ASC), $$50(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$42, $$44, $$50, $$49])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                            unnest-map [$$48, $$49] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", true, true, 1, $$44, 1, $$44, true, true, true)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                running-aggregate [$$50] <- [create-query-uid()]
                                                 -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                  project ([$$42, $$44])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    select (eq($$M.getField(3), "19:49:16"))
                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                      assign [$$44] <- [$$M.getField(1)]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                          data-scan []<-[$$42, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              empty-tuple-source
                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-1/query3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-1/query3.plan
index bb23941..424a018 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-1/query3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-1/query3.plan
@@ -1,34 +1,68 @@
+distribute result [$$67]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$67])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$67] <- [{"$1": $$71}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$71] <- [agg-sql-sum($$73)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$73] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (eq($$D, $$70))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$70, $$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$D <- scan-collection($$72)
                   -- UNNEST  |PARTITIONED|
+                    project ([$$70, $$72])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$72] <- [$$C.getField(2)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$70, $$C])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                            unnest-map [$$69, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", true, false, 1, $$75, 1, $$75, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$75, $$70])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    distinct ([$$75, $$76])
                                     -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        order (ASC, $$75) (ASC, $$76)
                                         -- STABLE_SORT [$$75(ASC), $$76(ASC)]  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$70, $$76, $$75])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                                unnest-map [$$74, $$75] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", true, true, 1, $$70, 1, $$70, true, true, true)
+                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                  exchange
                                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                    running-aggregate [$$76] <- [create-query-uid()]
                                                     -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                      project ([$$70])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$70] <- [$$M.getField(1)]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          project ([$$M])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                              data-scan []<-[$$68, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  empty-tuple-source
                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-1/query4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-1/query4.plan
index f602149..298b25d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-1/query4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-1/query4.plan
@@ -1,37 +1,74 @@
+distribute result [$$69]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$69])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$69] <- [{"$1": $$72}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$72] <- [agg-sql-sum($$77)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$77] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select ($$80)
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$80])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  window-aggregate [$$80] <- [win-mark-first-missing-impl($$71)] partition [$$70] order (DESC, $$71)
                   -- WINDOW_STREAM  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$70) (DESC, $$71)
                       -- STABLE_SORT [$$70(ASC), $$71(DESC)]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$70]  |PARTITIONED|
+                          project ([$$70, $$71])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            select (eq($$D, $$73)) retain-untrue ($$71 <- MISSING)
                             -- STREAM_SELECT  |PARTITIONED|
+                              project ([$$70, $$73, $$71, $$D])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                outer-unnest $$D <- scan-collection($$74)
                                 -- LEFT_OUTER_UNNEST  |PARTITIONED|
+                                  project ([$$70, $$73, $$71, $$74])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$74] <- [$$C.getField(2)]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$70, $$73, $$71, $$C])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                                          left-outer-unnest-map [$$71, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", true, false, 1, $$79, 1, $$79, true, true, true)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              distinct ([$$79, $$70])
                                               -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  order (ASC, $$79) (ASC, $$70)
                                                   -- STABLE_SORT [$$79(ASC), $$70(ASC)]  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      project ([$$70, $$73, $$79])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                                          left-outer-unnest-map [$$78, $$79] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", true, true, 1, $$73, 1, $$73, true, true, true)
+                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                            exchange
                                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                              project ([$$70, $$73])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$73] <- [$$M.getField(1)]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                                    data-scan []<-[$$70, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        empty-tuple-source
                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-2/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-2/query1.plan
index 2b052dc..dfc53aa 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-2/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-2/query1.plan
@@ -1,32 +1,64 @@
+distribute result [$$42]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$42])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$42] <- [{"marker": $$43}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$43])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$D, $$45))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$43, $$45, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$47)
               -- UNNEST  |PARTITIONED|
+                project ([$$43, $$45, $$47])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$47] <- [$$C.getField(2).getField(0)]
                   -- ASSIGN  |PARTITIONED|
+                    select (eq($$C.getField(1), "--Ni3oJ4VOqfOEu7Sj2Vzg"))
                     -- STREAM_SELECT  |PARTITIONED|
+                      project ([$$43, $$45, $$C])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                          unnest-map [$$44, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", true, false, 1, $$51, 1, $$51, true, true, true)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$51, $$43, $$45])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  distinct ([$$51, $$52])
                                   -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$51) (ASC, $$52)
                                       -- STABLE_SORT [$$51(ASC), $$52(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$43, $$45, $$52, $$51])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                              unnest-map [$$50, $$51] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", true, true, 1, $$45, 1, $$45, true, true, true)
+                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                exchange
                                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                  running-aggregate [$$52] <- [create-query-uid()]
                                                   -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                    project ([$$43, $$45])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      assign [$$45] <- [$$M.getField(2)]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                          data-scan []<-[$$43, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              empty-tuple-source
                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-2/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-2/query2.plan
index 1cad651..ca81713 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-2/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-2/query2.plan
@@ -1,32 +1,64 @@
+distribute result [$$42]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$42])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$42] <- [{"marker": $$43}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$43])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$D, $$45))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$43, $$45, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$47)
               -- UNNEST  |PARTITIONED|
+                project ([$$43, $$45, $$47])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$47] <- [$$C.getField(2).getField(0)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$43, $$45, $$C])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                        unnest-map [$$44, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", true, false, 1, $$51, 1, $$51, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$51, $$43, $$45])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                distinct ([$$51, $$52])
                                 -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$51) (ASC, $$52)
                                     -- STABLE_SORT [$$51(ASC), $$52(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$43, $$45, $$52, $$51])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                            unnest-map [$$50, $$51] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", true, true, 1, $$45, 1, $$45, true, true, true)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                running-aggregate [$$52] <- [create-query-uid()]
                                                 -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                  project ([$$43, $$45])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    select (eq($$M.getField(3), "19:49:16"))
                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                      assign [$$45] <- [$$M.getField(2)]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                          data-scan []<-[$$43, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              empty-tuple-source
                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-2/query3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-2/query3.plan
index 36d1e39..52f540a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-2/query3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-2/query3.plan
@@ -1,34 +1,68 @@
+distribute result [$$68]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$68])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$68] <- [{"$1": $$72}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$72] <- [agg-sql-sum($$75)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$75] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (eq($$D, $$71))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$71, $$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$D <- scan-collection($$73)
                   -- UNNEST  |PARTITIONED|
+                    project ([$$71, $$73])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$73] <- [$$C.getField(2).getField(0)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$71, $$C])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                            unnest-map [$$70, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", true, false, 1, $$77, 1, $$77, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$77, $$71])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    distinct ([$$77, $$78])
                                     -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        order (ASC, $$77) (ASC, $$78)
                                         -- STABLE_SORT [$$77(ASC), $$78(ASC)]  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$71, $$78, $$77])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                                unnest-map [$$76, $$77] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", true, true, 1, $$71, 1, $$71, true, true, true)
+                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                  exchange
                                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                    running-aggregate [$$78] <- [create-query-uid()]
                                                     -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                      project ([$$71])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$71] <- [$$M.getField(2)]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          project ([$$M])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                              data-scan []<-[$$69, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  empty-tuple-source
                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-2/query4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-2/query4.plan
index 44fd353..42df8c2 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-2/query4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-2/query4.plan
@@ -1,37 +1,74 @@
+distribute result [$$70]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$70])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$70] <- [{"$1": $$73}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$73] <- [agg-sql-sum($$79)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$79] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select ($$82)
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$82])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  window-aggregate [$$82] <- [win-mark-first-missing-impl($$72)] partition [$$71] order (DESC, $$72)
                   -- WINDOW_STREAM  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$71) (DESC, $$72)
                       -- STABLE_SORT [$$71(ASC), $$72(DESC)]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$71]  |PARTITIONED|
+                          project ([$$71, $$72])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            select (eq($$D, $$74)) retain-untrue ($$72 <- MISSING)
                             -- STREAM_SELECT  |PARTITIONED|
+                              project ([$$71, $$74, $$72, $$D])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                outer-unnest $$D <- scan-collection($$75)
                                 -- LEFT_OUTER_UNNEST  |PARTITIONED|
+                                  project ([$$71, $$74, $$72, $$75])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$75] <- [$$C.getField(2).getField(0)]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$71, $$74, $$72, $$C])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                                          left-outer-unnest-map [$$72, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", true, false, 1, $$81, 1, $$81, true, true, true)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              distinct ([$$81, $$71])
                                               -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  order (ASC, $$81) (ASC, $$71)
                                                   -- STABLE_SORT [$$81(ASC), $$71(ASC)]  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      project ([$$71, $$74, $$81])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                                          left-outer-unnest-map [$$80, $$81] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", true, true, 1, $$74, 1, $$74, true, true, true)
+                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                            exchange
                                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                              project ([$$71, $$74])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$74] <- [$$M.getField(2)]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                                    data-scan []<-[$$71, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        empty-tuple-source
                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-3/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-3/query1.plan
index bf67e63..b41e997 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-3/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-3/query1.plan
@@ -1,32 +1,64 @@
+distribute result [$$42]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$42])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$42] <- [{"marker": $$43}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$43])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$D.getField(0), $$46))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$43, $$46, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$48)
               -- UNNEST  |PARTITIONED|
+                project ([$$43, $$46, $$48])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (eq($$C.getField(1), "--Ni3oJ4VOqfOEu7Sj2Vzg"))
                   -- STREAM_SELECT  |PARTITIONED|
+                    assign [$$48] <- [$$C.getField(2)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$43, $$46, $$C])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                          unnest-map [$$44, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", true, false, 1, $$51, 1, $$51, true, true, true)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$51, $$43, $$46])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  distinct ([$$51, $$52])
                                   -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$51) (ASC, $$52)
                                       -- STABLE_SORT [$$51(ASC), $$52(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$43, $$46, $$52, $$51])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                              unnest-map [$$50, $$51] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", true, true, 1, $$46, 1, $$46, true, true, true)
+                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                exchange
                                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                  running-aggregate [$$52] <- [create-query-uid()]
                                                   -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                    project ([$$43, $$46])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      assign [$$46] <- [$$M.getField(2)]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                          data-scan []<-[$$43, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              empty-tuple-source
                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-3/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-3/query2.plan
index 443990e..f491fe6 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-3/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-3/query2.plan
@@ -1,32 +1,64 @@
+distribute result [$$42]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$42])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$42] <- [{"marker": $$43}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$43])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$D.getField(0), $$46))
           -- STREAM_SELECT  |PARTITIONED|
+            select (eq($$D.getField(1), "19:49:16"))
             -- STREAM_SELECT  |PARTITIONED|
+              project ([$$43, $$46, $$D])
               -- STREAM_PROJECT  |PARTITIONED|
+                unnest $$D <- scan-collection($$47)
                 -- UNNEST  |PARTITIONED|
+                  project ([$$43, $$46, $$47])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$47] <- [$$C.getField(2)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$43, $$46, $$C])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                          unnest-map [$$44, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", true, false, 1, $$51, 1, $$51, true, true, true)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$51, $$43, $$46])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  distinct ([$$51, $$52])
                                   -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$51) (ASC, $$52)
                                       -- STABLE_SORT [$$51(ASC), $$52(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$43, $$46, $$52, $$51])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                              unnest-map [$$50, $$51] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", true, true, 1, $$46, 1, $$46, true, true, true)
+                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                exchange
                                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                  running-aggregate [$$52] <- [create-query-uid()]
                                                   -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                    project ([$$43, $$46])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      assign [$$46] <- [$$M.getField(2)]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                          data-scan []<-[$$43, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              empty-tuple-source
                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-3/query3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-3/query3.plan
index 1cad651..06da8df 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-3/query3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-3/query3.plan
@@ -1,32 +1,64 @@
+distribute result [$$42]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$42])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$42] <- [{"marker": $$43}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$43])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$D.getField(0), $$46))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$43, $$46, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$48)
               -- UNNEST  |PARTITIONED|
+                project ([$$43, $$46, $$48])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$48] <- [$$C.getField(2)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$43, $$46, $$C])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                        unnest-map [$$44, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", true, false, 1, $$51, 1, $$51, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$51, $$43, $$46])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                distinct ([$$51, $$52])
                                 -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$51) (ASC, $$52)
                                     -- STABLE_SORT [$$51(ASC), $$52(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$43, $$46, $$52, $$51])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                            unnest-map [$$50, $$51] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", true, true, 1, $$46, 1, $$46, true, true, true)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                running-aggregate [$$52] <- [create-query-uid()]
                                                 -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                  project ([$$43, $$46])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    select (eq($$M.getField(3), "19:49:16"))
                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                      assign [$$46] <- [$$M.getField(2)]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                          data-scan []<-[$$43, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              empty-tuple-source
                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-3/query4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-3/query4.plan
index 36d1e39..0a29c9b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-3/query4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-3/query4.plan
@@ -1,34 +1,68 @@
+distribute result [$$69]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$69])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$69] <- [{"$1": $$73}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$73] <- [agg-sql-sum($$75)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$75] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (eq($$D.getField(0), $$72))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$72, $$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$D <- scan-collection($$74)
                   -- UNNEST  |PARTITIONED|
+                    project ([$$72, $$74])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$74] <- [$$C.getField(2)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$72, $$C])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                            unnest-map [$$71, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", true, false, 1, $$77, 1, $$77, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$77, $$72])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    distinct ([$$77, $$78])
                                     -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        order (ASC, $$77) (ASC, $$78)
                                         -- STABLE_SORT [$$77(ASC), $$78(ASC)]  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$72, $$78, $$77])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                                unnest-map [$$76, $$77] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", true, true, 1, $$72, 1, $$72, true, true, true)
+                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                  exchange
                                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                    running-aggregate [$$78] <- [create-query-uid()]
                                                     -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                      project ([$$72])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$72] <- [$$M.getField(2)]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          project ([$$M])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                              data-scan []<-[$$70, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  empty-tuple-source
                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-3/query5.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-3/query5.plan
index 0497e66..86bd124 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-3/query5.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-3/query5.plan
@@ -1,37 +1,74 @@
+distribute result [$$71]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$71])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$71] <- [{"$1": $$74}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$74] <- [agg-sql-sum($$79)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$79] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select ($$82)
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$82])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  window-aggregate [$$82] <- [win-mark-first-missing-impl($$73)] partition [$$72] order (DESC, $$73)
                   -- WINDOW_STREAM  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$72) (DESC, $$73)
                       -- STABLE_SORT [$$72(ASC), $$73(DESC)]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$72]  |PARTITIONED|
+                          project ([$$72, $$73])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            select (eq($$D.getField(0), $$75)) retain-untrue ($$73 <- MISSING)
                             -- STREAM_SELECT  |PARTITIONED|
+                              project ([$$72, $$75, $$73, $$D])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                outer-unnest $$D <- scan-collection($$76)
                                 -- LEFT_OUTER_UNNEST  |PARTITIONED|
+                                  project ([$$72, $$75, $$73, $$76])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$76] <- [$$C.getField(2)]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$72, $$75, $$73, $$C])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                                          left-outer-unnest-map [$$73, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", true, false, 1, $$81, 1, $$81, true, true, true)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              distinct ([$$81, $$72])
                                               -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  order (ASC, $$81) (ASC, $$72)
                                                   -- STABLE_SORT [$$81(ASC), $$72(ASC)]  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      project ([$$72, $$75, $$81])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                                          left-outer-unnest-map [$$80, $$81] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", true, true, 1, $$75, 1, $$75, true, true, true)
+                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                            exchange
                                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                              project ([$$72, $$75])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$75] <- [$$M.getField(2)]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                                    data-scan []<-[$$72, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        empty-tuple-source
                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-4/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-4/query1.plan
index e09340f..381a20d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-4/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-4/query1.plan
@@ -1,36 +1,72 @@
+distribute result [$$52]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$52])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$52] <- [{"marker": $$53}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$53])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$D, $$55))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$53, $$55, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$58)
               -- UNNEST  |PARTITIONED|
+                project ([$$53, $$55, $$58])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$58] <- [$$CT.getField(1)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$53, $$55, $$CT])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      unnest $$CT <- scan-collection($$57)
                       -- UNNEST  |PARTITIONED|
+                        project ([$$53, $$55, $$57])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          select (eq($$C.getField(1), "--Ni3oJ4VOqfOEu7Sj2Vzg"))
                           -- STREAM_SELECT  |PARTITIONED|
+                            assign [$$57] <- [$$C.getField(2)]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$53, $$55, $$C])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                                  unnest-map [$$54, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", true, false, 1, $$61, 1, $$61, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$61, $$53, $$55])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          distinct ([$$61, $$62])
                                           -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              order (ASC, $$61) (ASC, $$62)
                                               -- STABLE_SORT [$$61(ASC), $$62(ASC)]  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  project ([$$53, $$55, $$62, $$61])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                                      unnest-map [$$60, $$61] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", true, true, 1, $$55, 1, $$55, true, true, true)
+                                                      -- BTREE_SEARCH  |PARTITIONED|
+                                                        exchange
                                                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                          running-aggregate [$$62] <- [create-query-uid()]
                                                           -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                            project ([$$53, $$55])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$55] <- [$$M.getField(2)]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                                  data-scan []<-[$$53, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      empty-tuple-source
                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-4/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-4/query2.plan
index 1569695..5e1f154 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-4/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-4/query2.plan
@@ -1,37 +1,74 @@
+distribute result [$$54]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$54])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$54] <- [{"marker": $$55}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$55])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$D, $$57))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$55, $$57, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$61)
               -- UNNEST  |PARTITIONED|
+                project ([$$55, $$57, $$61])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (eq($$CT.getField(0), 1))
                   -- STREAM_SELECT  |PARTITIONED|
+                    assign [$$61] <- [$$CT.getField(1)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$55, $$57, $$CT])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        unnest $$CT <- scan-collection($$59)
                         -- UNNEST  |PARTITIONED|
+                          project ([$$55, $$57, $$59])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            select (eq($$C.getField(1), "--Ni3oJ4VOqfOEu7Sj2Vzg"))
                             -- STREAM_SELECT  |PARTITIONED|
+                              assign [$$59] <- [$$C.getField(2)]
                               -- ASSIGN  |PARTITIONED|
+                                project ([$$55, $$57, $$C])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                                    unnest-map [$$56, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", true, false, 1, $$64, 1, $$64, true, true, true)
+                                    -- BTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$64, $$55, $$57])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            distinct ([$$64, $$65])
                                             -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                order (ASC, $$64) (ASC, $$65)
                                                 -- STABLE_SORT [$$64(ASC), $$65(ASC)]  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$$55, $$57, $$65, $$64])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                                        unnest-map [$$63, $$64] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", true, true, 1, $$57, 1, $$57, true, true, true)
+                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                          exchange
                                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                            running-aggregate [$$65] <- [create-query-uid()]
                                                             -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                              project ([$$55, $$57])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$57] <- [$$M.getField(2)]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                                    data-scan []<-[$$55, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        empty-tuple-source
                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-4/query3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-4/query3.plan
index c4d7c08..782fb57 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-4/query3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-4/query3.plan
@@ -1,36 +1,72 @@
+distribute result [$$52]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$52])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$52] <- [{"marker": $$53}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$53])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$D, $$55))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$53, $$55, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$58)
               -- UNNEST  |PARTITIONED|
+                project ([$$53, $$55, $$58])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$58] <- [$$CT.getField(1)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$53, $$55, $$CT])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      unnest $$CT <- scan-collection($$57)
                       -- UNNEST  |PARTITIONED|
+                        project ([$$53, $$55, $$57])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$57] <- [$$C.getField(2)]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$53, $$55, $$C])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                                unnest-map [$$54, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", true, false, 1, $$61, 1, $$61, true, true, true)
+                                -- BTREE_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$61, $$53, $$55])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        distinct ([$$61, $$62])
                                         -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            order (ASC, $$61) (ASC, $$62)
                                             -- STABLE_SORT [$$61(ASC), $$62(ASC)]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$53, $$55, $$62, $$61])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                                    unnest-map [$$60, $$61] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", true, true, 1, $$55, 1, $$55, true, true, true)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                        running-aggregate [$$62] <- [create-query-uid()]
                                                         -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                          project ([$$53, $$55])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            select (eq($$M.getField(3), "19:49:16"))
                                                             -- STREAM_SELECT  |PARTITIONED|
+                                                              assign [$$55] <- [$$M.getField(2)]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                                  data-scan []<-[$$53, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      empty-tuple-source
                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-4/query4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-4/query4.plan
index 34a1b94..11933b3 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-4/query4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-4/query4.plan
@@ -1,38 +1,76 @@
+distribute result [$$78]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$78])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$78] <- [{"$1": $$82}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$82] <- [agg-sql-sum($$85)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$85] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (eq($$D, $$81))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$81, $$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$D <- scan-collection($$84)
                   -- UNNEST  |PARTITIONED|
+                    project ([$$81, $$84])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$84] <- [$$CT.getField(1)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$81, $$CT])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          unnest $$CT <- scan-collection($$83)
                           -- UNNEST  |PARTITIONED|
+                            project ([$$81, $$83])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$83] <- [$$C.getField(2)]
                               -- ASSIGN  |PARTITIONED|
+                                project ([$$81, $$C])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                                    unnest-map [$$80, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", true, false, 1, $$87, 1, $$87, true, true, true)
+                                    -- BTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$87, $$81])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            distinct ([$$87, $$88])
                                             -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                order (ASC, $$87) (ASC, $$88)
                                                 -- STABLE_SORT [$$87(ASC), $$88(ASC)]  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$$81, $$88, $$87])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                                        unnest-map [$$86, $$87] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", true, true, 1, $$81, 1, $$81, true, true, true)
+                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                          exchange
                                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                            running-aggregate [$$88] <- [create-query-uid()]
                                                             -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                              project ([$$81])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$81] <- [$$M.getField(2)]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  project ([$$M])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                                      data-scan []<-[$$79, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          empty-tuple-source
                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-4/query5.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-4/query5.plan
index aac007e..ca0e4db 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-4/query5.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/join-unnest-queries/use-case-4/query5.plan
@@ -1,41 +1,82 @@
+distribute result [$$80]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$80])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$80] <- [{"$1": $$83}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$83] <- [agg-sql-sum($$89)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$89] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select ($$92)
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$92])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  window-aggregate [$$92] <- [win-mark-first-missing-impl($$82)] partition [$$81] order (DESC, $$82)
                   -- WINDOW_STREAM  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$81) (DESC, $$82)
                       -- STABLE_SORT [$$81(ASC), $$82(DESC)]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$81]  |PARTITIONED|
+                          project ([$$81, $$82])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            select (eq($$D, $$84)) retain-untrue ($$82 <- MISSING)
                             -- STREAM_SELECT  |PARTITIONED|
+                              project ([$$81, $$84, $$82, $$D])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                outer-unnest $$D <- scan-collection($$86)
                                 -- LEFT_OUTER_UNNEST  |PARTITIONED|
+                                  project ([$$81, $$84, $$82, $$86])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$86] <- [$$CT.getField(1)]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$81, $$84, $$82, $$CT])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        outer-unnest $$CT <- scan-collection($$85)
                                         -- LEFT_OUTER_UNNEST  |PARTITIONED|
+                                          project ([$$81, $$84, $$82, $$85])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$85] <- [$$C.getField(2)]
                                             -- ASSIGN  |PARTITIONED|
+                                              project ([$$81, $$84, $$82, $$C])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                                                  left-outer-unnest-map [$$82, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", true, false, 1, $$91, 1, $$91, true, true, true)
+                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      distinct ([$$91, $$81])
                                                       -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          order (ASC, $$91) (ASC, $$81)
                                                           -- STABLE_SORT [$$91(ASC), $$81(ASC)]  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              project ([$$81, $$84, $$91])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                                                  left-outer-unnest-map [$$90, $$91] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", true, true, 1, $$84, 1, $$84, true, true, true)
+                                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                                    exchange
                                                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                      project ([$$81, $$84])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        assign [$$84] <- [$$M.getField(2)]
                                                                         -- ASSIGN  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                            -- DATASOURCE_SCAN (TestYelp.YelpCheckinDateMarkers)  |PARTITIONED|
+                                                                            data-scan []<-[$$81, $$M] <- TestYelp.YelpCheckinDateMarkers
+                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                empty-tuple-source
                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-indexes/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-indexes/query1.plan
index 0d37f51..8d2cc73 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-indexes/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-indexes/query1.plan
@@ -1,43 +1,83 @@
+distribute result [$$30]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$30])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$30] <- [{"k": $$k}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$k])
         -- STREAM_PROJECT  |PARTITIONED|
+          select ($$28)
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$k, $$28])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$28] <- [non-empty-stream()]
                         -- AGGREGATE  |LOCAL|
+                          select (and(eq($$34, 284), eq($$33, 263)))
                           -- STREAM_SELECT  |LOCAL|
+                            assign [$$34, $$33] <- [$$v.getField("a"), $$v.getField("b")]
                             -- ASSIGN  |LOCAL|
+                              unnest $$v <- scan-collection($$32)
                               -- UNNEST  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                assign [$$32] <- [$$k.getField("uarr_i")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$k])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (test.KSI.KSI)  |PARTITIONED|
+                      unnest-map [$$31, $$k] <- index-search("KSI", 0, "test", "KSI", false, false, 1, $$43, 1, $$43, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          intersect [$$43] <- [[$$38], [$$42]]
                           -- INTERSECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              distinct ([$$38])
                               -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- STABLE_SORT [$$40(ASC)]  |PARTITIONED|
+                                  order (ASC, $$38)
+                                  -- STABLE_SORT [$$38(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$38])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (test.KSI.KS1_array_index1)  |PARTITIONED|
+                                          unnest-map [$$37, $$38] <- index-search("KS1_array_index1", 0, "test", "KSI", false, false, 1, $$35, 1, $$36, true, true, true)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$35, $$36] <- [284, 284]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              distinct ([$$42])
                               -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- STABLE_SORT [$$44(ASC)]  |PARTITIONED|
+                                  order (ASC, $$42)
+                                  -- STABLE_SORT [$$42(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$42])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (test.KSI.KS1_array_index2)  |PARTITIONED|
+                                          unnest-map [$$41, $$42] <- index-search("KS1_array_index2", 0, "test", "KSI", false, false, 1, $$39, 1, $$40, true, true, true)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$39, $$40] <- [263, 263]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-indexes/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-indexes/query2.plan
index b793939..116f9c7 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-indexes/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-indexes/query2.plan
@@ -1,54 +1,105 @@
+distribute result [$$32]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$32])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$32] <- [{"k": $$k}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$k])
         -- STREAM_PROJECT  |PARTITIONED|
+          select ($$30)
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$k, $$30])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$30] <- [non-empty-stream()]
                         -- AGGREGATE  |LOCAL|
+                          select (and(eq($$37, 284), eq($$36, 263), eq($$35, 123)))
                           -- STREAM_SELECT  |LOCAL|
+                            assign [$$37, $$36, $$35] <- [$$v.getField("a"), $$v.getField("b"), $$v.getField("c")]
                             -- ASSIGN  |LOCAL|
+                              unnest $$v <- scan-collection($$34)
                               -- UNNEST  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                assign [$$34] <- [$$k.getField("uarr_i")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$k])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (test.KSI.KSI)  |PARTITIONED|
+                      unnest-map [$$33, $$k] <- index-search("KSI", 0, "test", "KSI", false, false, 1, $$50, 1, $$50, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          intersect [$$50] <- [[$$41], [$$45], [$$49]]
                           -- INTERSECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              distinct ([$$41])
                               -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- STABLE_SORT [$$43(ASC)]  |PARTITIONED|
+                                  order (ASC, $$41)
+                                  -- STABLE_SORT [$$41(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$41])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (test.KSI.KS1_array_index1)  |PARTITIONED|
+                                          unnest-map [$$40, $$41] <- index-search("KS1_array_index1", 0, "test", "KSI", false, false, 1, $$38, 1, $$39, true, true, true)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$38, $$39] <- [284, 284]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              distinct ([$$45])
                               -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- STABLE_SORT [$$47(ASC)]  |PARTITIONED|
+                                  order (ASC, $$45)
+                                  -- STABLE_SORT [$$45(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$45])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (test.KSI.KS1_array_index2)  |PARTITIONED|
+                                          unnest-map [$$44, $$45] <- index-search("KS1_array_index2", 0, "test", "KSI", false, false, 1, $$42, 1, $$43, true, true, true)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$42, $$43] <- [263, 263]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              distinct ([$$49])
                               -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- STABLE_SORT [$$51(ASC)]  |PARTITIONED|
+                                  order (ASC, $$49)
+                                  -- STABLE_SORT [$$49(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$49])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (test.KSI.KS1_array_index3)  |PARTITIONED|
+                                          unnest-map [$$48, $$49] <- index-search("KS1_array_index3", 0, "test", "KSI", false, false, 1, $$46, 1, $$47, true, true, true)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$46, $$47] <- [123, 123]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query1.plan
index 62b49d7..3f4aee7 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query1.plan
@@ -1,31 +1,59 @@
+distribute result [$$39]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$39])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$39] <- [{"D1": $$D1}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$D1])
         -- STREAM_PROJECT  |PARTITIONED|
+          select ($$37)
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$D1, $$37])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$37] <- [non-empty-stream()]
                         -- AGGREGATE  |LOCAL|
+                          select (eq($$J, 2))
                           -- STREAM_SELECT  |LOCAL|
+                            unnest $$J <- scan-collection($$42)
                             -- UNNEST  |LOCAL|
+                              select (eq($$I, 1))
                               -- STREAM_SELECT  |LOCAL|
+                                unnest $$I <- scan-collection($$41)
                                 -- UNNEST  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                assign [$$42, $$41] <- [$$D1.getField("other_items"), $$D1.getField("items")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$D1])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (TestDataverse.Dataset1.Dataset1)  |PARTITIONED|
+                      unnest-map [$$40, $$D1] <- index-search("Dataset1", 0, "TestDataverse", "Dataset1", false, false, 1, $$46, 1, $$46, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          distinct ([$$46])
                           -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$46)
                               -- STABLE_SORT [$$46(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$46])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- BTREE_SEARCH (TestDataverse.Dataset1.d1Idx)  |PARTITIONED|
+                                      unnest-map [$$45, $$46] <- index-search("d1Idx", 0, "TestDataverse", "Dataset1", false, false, 1, $$43, 1, $$44, true, true, true)
+                                      -- BTREE_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$43, $$44] <- [1, 1]
                                           -- ASSIGN  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query10.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query10.plan
index 50d2d2d..4dcd291 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query10.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query10.plan
@@ -1,36 +1,66 @@
+distribute result [$$25]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$25])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$25] <- [{"D1": $$D1}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$D1])
         -- STREAM_PROJECT  |PARTITIONED|
+          select ($$23)
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$D1, $$23])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$23] <- [non-empty-stream()]
                         -- AGGREGATE  |LOCAL|
+                          select (eq(true, $#2))
                           -- STREAM_SELECT  |LOCAL|
+                            unnest $#2 <- scan-collection(ordered-list-constructor(eq($$28, "a"), $$21))
                             -- UNNEST  |LOCAL|
-                              -- SUBPLAN  |LOCAL|
-                                      {
+                              subplan {
+                                        aggregate [$$21] <- [non-empty-stream()]
                                         -- AGGREGATE  |LOCAL|
+                                          select (eq("b", $#1))
                                           -- STREAM_SELECT  |LOCAL|
+                                            unnest $#1 <- scan-collection($$27)
                                             -- UNNEST  |LOCAL|
+                                              nested tuple source
                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                      }
+                                     }
+                              -- SUBPLAN  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                assign [$$28, $$27] <- [$$D1.getField("val"), $$D1.getField("items")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$D1])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (TestDataverse.Dataset1.Dataset1)  |PARTITIONED|
+                      unnest-map [$$26, $$D1] <- index-search("Dataset1", 0, "TestDataverse", "Dataset1", false, false, 1, $$32, 1, $$32, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          distinct ([$$32])
                           -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- STABLE_SORT [$$33(ASC)]  |PARTITIONED|
+                              order (ASC, $$32)
+                              -- STABLE_SORT [$$32(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$32])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- BTREE_SEARCH (TestDataverse.Dataset1.d1Idx)  |PARTITIONED|
+                                      unnest-map [$$31, $$32] <- index-search("d1Idx", 0, "TestDataverse", "Dataset1", false, false, 1, $$29, 1, $$30, true, true, true)
+                                      -- BTREE_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$29, $$30] <- ["b", "b"]
                                           -- ASSIGN  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query11.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query11.plan
index f14e55a..90de8d8 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query11.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query11.plan
@@ -1,43 +1,77 @@
+distribute result [$$32]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$32])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$32] <- [{"D1": $$D1}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$D1])
         -- STREAM_PROJECT  |PARTITIONED|
+          select ($$30)
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$D1, $$30])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$30] <- [non-empty-stream()]
                         -- AGGREGATE  |LOCAL|
+                          select (eq(true, $#3))
                           -- STREAM_SELECT  |LOCAL|
+                            unnest $#3 <- scan-collection(ordered-list-constructor(eq($$36, "a"), $$28))
                             -- UNNEST  |LOCAL|
-                              -- SUBPLAN  |LOCAL|
-                                      {
+                              subplan {
+                                        aggregate [$$28] <- [non-empty-stream()]
                                         -- AGGREGATE  |LOCAL|
+                                          select (eq(true, $#2))
                                           -- STREAM_SELECT  |LOCAL|
+                                            unnest $#2 <- scan-collection(ordered-list-constructor(eq($$35, "c"), $$26))
                                             -- UNNEST  |LOCAL|
-                                              -- SUBPLAN  |LOCAL|
-                                                      {
+                                              subplan {
+                                                        aggregate [$$26] <- [non-empty-stream()]
                                                         -- AGGREGATE  |LOCAL|
+                                                          select (eq("b", $#1))
                                                           -- STREAM_SELECT  |LOCAL|
+                                                            unnest $#1 <- scan-collection($$34)
                                                             -- UNNEST  |LOCAL|
+                                                              nested tuple source
                                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                      }
+                                                     }
+                                              -- SUBPLAN  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                      }
+                                     }
+                              -- SUBPLAN  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                assign [$$36, $$35, $$34] <- [$$D1.getField("val"), $$D1.getField("val2"), $$D1.getField("items")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$D1])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (TestDataverse.Dataset1.Dataset1)  |PARTITIONED|
+                      unnest-map [$$33, $$D1] <- index-search("Dataset1", 0, "TestDataverse", "Dataset1", false, false, 1, $$40, 1, $$40, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          distinct ([$$40])
                           -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- STABLE_SORT [$$41(ASC)]  |PARTITIONED|
+                              order (ASC, $$40)
+                              -- STABLE_SORT [$$40(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$40])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- BTREE_SEARCH (TestDataverse.Dataset1.d1Idx)  |PARTITIONED|
+                                      unnest-map [$$39, $$40] <- index-search("d1Idx", 0, "TestDataverse", "Dataset1", false, false, 1, $$37, 1, $$38, true, true, true)
+                                      -- BTREE_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$37, $$38] <- ["b", "b"]
                                           -- ASSIGN  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query2.plan
index 62b49d7..a65f552 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query2.plan
@@ -1,31 +1,59 @@
+distribute result [$$39]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$39])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$39] <- [{"D1": $$D1}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$D1])
         -- STREAM_PROJECT  |PARTITIONED|
+          select ($$37)
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$D1, $$37])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$37] <- [non-empty-stream()]
                         -- AGGREGATE  |LOCAL|
+                          select (eq($$J, 2))
                           -- STREAM_SELECT  |LOCAL|
+                            unnest $$J <- scan-collection($$42)
                             -- UNNEST  |LOCAL|
+                              select (eq($$I, 1))
                               -- STREAM_SELECT  |LOCAL|
+                                unnest $$I <- scan-collection($$41)
                                 -- UNNEST  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                assign [$$42, $$41] <- [$$D1.getField("other_items"), $$D1.getField(1)]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$D1])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (TestDataverse.Dataset1.Dataset1)  |PARTITIONED|
+                      unnest-map [$$40, $$D1] <- index-search("Dataset1", 0, "TestDataverse", "Dataset1", false, false, 1, $$46, 1, $$46, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          distinct ([$$46])
                           -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$46)
                               -- STABLE_SORT [$$46(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$46])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- BTREE_SEARCH (TestDataverse.Dataset1.d1Idx)  |PARTITIONED|
+                                      unnest-map [$$45, $$46] <- index-search("d1Idx", 0, "TestDataverse", "Dataset1", false, false, 1, $$43, 1, $$44, true, true, true)
+                                      -- BTREE_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$43, $$44] <- [1, 1]
                                           -- ASSIGN  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query3.plan
index 24b6a5a..855ccd2 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query3.plan
@@ -1,33 +1,63 @@
+distribute result [$$41]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$41])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$41] <- [{"D1": $$D1}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$D1])
         -- STREAM_PROJECT  |PARTITIONED|
+          select ($$39)
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$D1, $$39])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$39] <- [non-empty-stream()]
                         -- AGGREGATE  |LOCAL|
+                          select (eq($$46, 2))
                           -- STREAM_SELECT  |LOCAL|
+                            assign [$$46] <- [$$J.getField("item")]
                             -- ASSIGN  |LOCAL|
+                              unnest $$J <- scan-collection($$45)
                               -- UNNEST  |LOCAL|
+                                select (eq($$44, 1))
                                 -- STREAM_SELECT  |LOCAL|
+                                  assign [$$44] <- [$$I.getField("item")]
                                   -- ASSIGN  |LOCAL|
+                                    unnest $$I <- scan-collection($$43)
                                     -- UNNEST  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                assign [$$45, $$43] <- [$$D1.getField("other_items"), $$D1.getField("items")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$D1])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (TestDataverse.Dataset1.Dataset1)  |PARTITIONED|
+                      unnest-map [$$42, $$D1] <- index-search("Dataset1", 0, "TestDataverse", "Dataset1", false, false, 1, $$50, 1, $$50, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          distinct ([$$50])
                           -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$50)
                               -- STABLE_SORT [$$50(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$50])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- BTREE_SEARCH (TestDataverse.Dataset1.d1Idx)  |PARTITIONED|
+                                      unnest-map [$$49, $$50] <- index-search("d1Idx", 0, "TestDataverse", "Dataset1", false, false, 1, $$47, 1, $$48, true, true, true)
+                                      -- BTREE_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$47, $$48] <- [1, 1]
                                           -- ASSIGN  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query4.plan
index 24b6a5a..ad81a10 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query4.plan
@@ -1,33 +1,63 @@
+distribute result [$$41]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$41])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$41] <- [{"D1": $$D1}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$D1])
         -- STREAM_PROJECT  |PARTITIONED|
+          select ($$39)
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$D1, $$39])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$39] <- [non-empty-stream()]
                         -- AGGREGATE  |LOCAL|
+                          select (eq($$46, 2))
                           -- STREAM_SELECT  |LOCAL|
+                            assign [$$46] <- [$$J.getField("item")]
                             -- ASSIGN  |LOCAL|
+                              unnest $$J <- scan-collection($$45)
                               -- UNNEST  |LOCAL|
+                                select (eq($$44, 1))
                                 -- STREAM_SELECT  |LOCAL|
+                                  assign [$$44] <- [$$I.getField(0)]
                                   -- ASSIGN  |LOCAL|
+                                    unnest $$I <- scan-collection($$43)
                                     -- UNNEST  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                assign [$$45, $$43] <- [$$D1.getField("other_items"), $$D1.getField(1)]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$D1])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (TestDataverse.Dataset1.Dataset1)  |PARTITIONED|
+                      unnest-map [$$42, $$D1] <- index-search("Dataset1", 0, "TestDataverse", "Dataset1", false, false, 1, $$50, 1, $$50, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          distinct ([$$50])
                           -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$50)
                               -- STABLE_SORT [$$50(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$50])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- BTREE_SEARCH (TestDataverse.Dataset1.d1Idx)  |PARTITIONED|
+                                      unnest-map [$$49, $$50] <- index-search("d1Idx", 0, "TestDataverse", "Dataset1", false, false, 1, $$47, 1, $$48, true, true, true)
+                                      -- BTREE_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$47, $$48] <- [1, 1]
                                           -- ASSIGN  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query5.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query5.plan
index 7992dcf..42a9da6 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query5.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query5.plan
@@ -1,44 +1,82 @@
+distribute result [$$67]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$67])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$67] <- [{"D1": $$D1}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$D1])
         -- STREAM_PROJECT  |PARTITIONED|
+          select ($$65)
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$D1, $$65])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$65] <- [non-empty-stream()]
                         -- AGGREGATE  |LOCAL|
+                          select ($$63)
                           -- STREAM_SELECT  |LOCAL|
-                            -- SUBPLAN  |LOCAL|
-                                    {
+                            subplan {
+                                      aggregate [$$63] <- [non-empty-stream()]
                                       -- AGGREGATE  |LOCAL|
+                                        select (eq($$75, 2))
                                         -- STREAM_SELECT  |LOCAL|
+                                          assign [$$75] <- [$$J2.getField("item")]
                                           -- ASSIGN  |LOCAL|
+                                            unnest $$J2 <- scan-collection($$74)
                                             -- UNNEST  |LOCAL|
+                                              select (eq($$73, 1))
                                               -- STREAM_SELECT  |LOCAL|
+                                                assign [$$73] <- [$$I2.getField("item")]
                                                 -- ASSIGN  |LOCAL|
+                                                  unnest $$I2 <- scan-collection($$72)
                                                   -- UNNEST  |LOCAL|
+                                                    nested tuple source
                                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                    }
+                                   }
+                            -- SUBPLAN  |LOCAL|
+                              select (eq($$71, 2))
                               -- STREAM_SELECT  |LOCAL|
+                                assign [$$71] <- [$$J.getField("item")]
                                 -- ASSIGN  |LOCAL|
+                                  unnest $$J <- scan-collection($$70)
                                   -- UNNEST  |LOCAL|
+                                    assign [$$74, $$72] <- [$$I1.getField("other_inner_items"), $$I1.getField("inner_items")]
                                     -- ASSIGN  |LOCAL|
+                                      unnest $$I1 <- scan-collection($$69)
                                       -- UNNEST  |LOCAL|
+                                        nested tuple source
                                         -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                assign [$$70, $$69] <- [$$D1.getField("other_items"), $$D1.getField("outer_items")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$D1])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (TestDataverse.Dataset1.Dataset1)  |PARTITIONED|
+                      unnest-map [$$68, $$D1] <- index-search("Dataset1", 0, "TestDataverse", "Dataset1", false, false, 1, $$81, 1, $$81, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          distinct ([$$81])
                           -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$81)
                               -- STABLE_SORT [$$81(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$81])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- BTREE_SEARCH (TestDataverse.Dataset1.d1Idx)  |PARTITIONED|
+                                      unnest-map [$$80, $$81] <- index-search("d1Idx", 0, "TestDataverse", "Dataset1", false, false, 1, $$78, 1, $$79, true, true, true)
+                                      -- BTREE_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$78, $$79] <- [1, 1]
                                           -- ASSIGN  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query6.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query6.plan
index 7992dcf..77ed98d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query6.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query6.plan
@@ -1,44 +1,82 @@
+distribute result [$$67]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$67])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$67] <- [{"D1": $$D1}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$D1])
         -- STREAM_PROJECT  |PARTITIONED|
+          select ($$65)
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$D1, $$65])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$65] <- [non-empty-stream()]
                         -- AGGREGATE  |LOCAL|
+                          select ($$63)
                           -- STREAM_SELECT  |LOCAL|
-                            -- SUBPLAN  |LOCAL|
-                                    {
+                            subplan {
+                                      aggregate [$$63] <- [non-empty-stream()]
                                       -- AGGREGATE  |LOCAL|
+                                        select (eq($$75, 2))
                                         -- STREAM_SELECT  |LOCAL|
+                                          assign [$$75] <- [$$J2.getField("item")]
                                           -- ASSIGN  |LOCAL|
+                                            unnest $$J2 <- scan-collection($$74)
                                             -- UNNEST  |LOCAL|
+                                              select (eq($$73, 1))
                                               -- STREAM_SELECT  |LOCAL|
+                                                assign [$$73] <- [$$I2.getField(0)]
                                                 -- ASSIGN  |LOCAL|
+                                                  unnest $$I2 <- scan-collection($$72)
                                                   -- UNNEST  |LOCAL|
+                                                    nested tuple source
                                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                    }
+                                   }
+                            -- SUBPLAN  |LOCAL|
+                              select (eq($$71, 2))
                               -- STREAM_SELECT  |LOCAL|
+                                assign [$$71] <- [$$J.getField("item")]
                                 -- ASSIGN  |LOCAL|
+                                  unnest $$J <- scan-collection($$70)
                                   -- UNNEST  |LOCAL|
+                                    assign [$$74, $$72] <- [$$I1.getField("other_inner_items"), $$I1.getField(0)]
                                     -- ASSIGN  |LOCAL|
+                                      unnest $$I1 <- scan-collection($$69)
                                       -- UNNEST  |LOCAL|
+                                        nested tuple source
                                         -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                assign [$$70, $$69] <- [$$D1.getField("other_items"), $$D1.getField(1)]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$D1])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (TestDataverse.Dataset1.Dataset1)  |PARTITIONED|
+                      unnest-map [$$68, $$D1] <- index-search("Dataset1", 0, "TestDataverse", "Dataset1", false, false, 1, $$81, 1, $$81, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          distinct ([$$81])
                           -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$81)
                               -- STABLE_SORT [$$81(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$81])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- BTREE_SEARCH (TestDataverse.Dataset1.d1Idx)  |PARTITIONED|
+                                      unnest-map [$$80, $$81] <- index-search("d1Idx", 0, "TestDataverse", "Dataset1", false, false, 1, $$78, 1, $$79, true, true, true)
+                                      -- BTREE_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$78, $$79] <- [1, 1]
                                           -- ASSIGN  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query7.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query7.plan
index 7999e77..02d30bb 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query7.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query7.plan
@@ -1,31 +1,59 @@
+distribute result [$$43]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$43])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$43] <- [{"D1": $$D1}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$D1])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and($$39, eq($$40, 0)))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$D1, $$39, $$40])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$39, $$40] <- [non-empty-stream(), agg-sql-count(switch-case(and(eq($$47, 1), eq($$48, 2)), true, NULL, true))]
                         -- AGGREGATE  |LOCAL|
+                          assign [$$48] <- [$$J.getField("item")]
                           -- ASSIGN  |LOCAL|
+                            unnest $$J <- scan-collection($$46)
                             -- UNNEST  |LOCAL|
+                              assign [$$47] <- [$$I.getField(0)]
                               -- ASSIGN  |LOCAL|
+                                unnest $$I <- scan-collection($$45)
                                 -- UNNEST  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                assign [$$46, $$45] <- [$$D1.getField("other_items"), $$D1.getField(1)]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$D1])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (TestDataverse.Dataset1.Dataset1)  |PARTITIONED|
+                      unnest-map [$$44, $$D1] <- index-search("Dataset1", 0, "TestDataverse", "Dataset1", false, false, 1, $$52, 1, $$52, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          distinct ([$$52])
                           -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$52)
                               -- STABLE_SORT [$$52(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$52])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- BTREE_SEARCH (TestDataverse.Dataset1.d1Idx)  |PARTITIONED|
+                                      unnest-map [$$51, $$52] <- index-search("d1Idx", 0, "TestDataverse", "Dataset1", false, false, 1, $$49, 1, $$50, true, true, true)
+                                      -- BTREE_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$49, $$50] <- [1, 1]
                                           -- ASSIGN  |PARTITIONED|
-                                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                            empty-tuple-source
+                                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query8.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query8.plan
index cc99bbf..08d3aad 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query8.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query8.plan
@@ -1,40 +1,74 @@
+distribute result [$$71]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$71])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$71] <- [{"D1": $$D1}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$D1])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and($$67, eq($$68, 0)))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$D1, $$67, $$68])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$67, $$68] <- [non-empty-stream(), agg-sql-count(switch-case(and(eq($$79, 2), and($$63, eq($$64, 0))), true, NULL, true))]
                         -- AGGREGATE  |LOCAL|
-                          -- SUBPLAN  |LOCAL|
-                                  {
+                          subplan {
+                                    aggregate [$$63, $$64] <- [non-empty-stream(), agg-sql-count(switch-case(and(eq($$77, 1), eq($$78, 2)), true, NULL, true))]
                                     -- AGGREGATE  |LOCAL|
+                                      assign [$$78] <- [$$J2.getField("item")]
                                       -- ASSIGN  |LOCAL|
+                                        unnest $$J2 <- scan-collection($$76)
                                         -- UNNEST  |LOCAL|
+                                          assign [$$77] <- [$$I2.getField(0)]
                                           -- ASSIGN  |LOCAL|
+                                            unnest $$I2 <- scan-collection($$75)
                                             -- UNNEST  |LOCAL|
+                                              nested tuple source
                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                  }
+                                 }
+                          -- SUBPLAN  |LOCAL|
+                            assign [$$79] <- [$$J.getField("item")]
                             -- ASSIGN  |LOCAL|
+                              unnest $$J <- scan-collection($$74)
                               -- UNNEST  |LOCAL|
+                                assign [$$76, $$75] <- [$$I1.getField("other_inner_items"), $$I1.getField(0)]
                                 -- ASSIGN  |LOCAL|
+                                  unnest $$I1 <- scan-collection($$73)
                                   -- UNNEST  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                assign [$$74, $$73] <- [$$D1.getField("other_items"), $$D1.getField(1)]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$D1])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (TestDataverse.Dataset1.Dataset1)  |PARTITIONED|
+                      unnest-map [$$72, $$D1] <- index-search("Dataset1", 0, "TestDataverse", "Dataset1", false, false, 1, $$85, 1, $$85, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          distinct ([$$85])
                           -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$85)
                               -- STABLE_SORT [$$85(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$85])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- BTREE_SEARCH (TestDataverse.Dataset1.d1Idx)  |PARTITIONED|
+                                      unnest-map [$$84, $$85] <- index-search("d1Idx", 0, "TestDataverse", "Dataset1", false, false, 1, $$82, 1, $$83, true, true, true)
+                                      -- BTREE_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$82, $$83] <- [1, 1]
                                           -- ASSIGN  |PARTITIONED|
-                                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                            empty-tuple-source
+                                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query9.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query9.plan
index c9574d6..97ccec0 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query9.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/multiple-quantifiers/query9.plan
@@ -1,40 +1,74 @@
+distribute result [$$73]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$73])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$73] <- [{"D1": $$D1}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$D1])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and($$69, eq($$70, 0)))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$D1, $$69, $$70])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$69, $$70] <- [non-empty-stream(), agg-sql-count(switch-case(and(eq($$81, 2), eq($$82, 3), and($$65, eq($$66, 0))), true, NULL, true))]
                         -- AGGREGATE  |LOCAL|
-                          -- SUBPLAN  |LOCAL|
-                                  {
+                          subplan {
+                                    aggregate [$$65, $$66] <- [non-empty-stream(), agg-sql-count(switch-case(and(eq($$79, 1), eq($$80, 2)), true, NULL, true))]
                                     -- AGGREGATE  |LOCAL|
+                                      assign [$$80] <- [$$J2.getField("item")]
                                       -- ASSIGN  |LOCAL|
+                                        unnest $$J2 <- scan-collection($$78)
                                         -- UNNEST  |LOCAL|
+                                          assign [$$79] <- [$$I2.getField(0)]
                                           -- ASSIGN  |LOCAL|
+                                            unnest $$I2 <- scan-collection($$77)
                                             -- UNNEST  |LOCAL|
+                                              nested tuple source
                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                  }
+                                 }
+                          -- SUBPLAN  |LOCAL|
+                            assign [$$81] <- [$$J.getField("item")]
                             -- ASSIGN  |LOCAL|
+                              unnest $$J <- scan-collection($$76)
                               -- UNNEST  |LOCAL|
+                                assign [$$82, $$78, $$77] <- [$$I1.getField(0), $$I1.getField("other_inner_items"), $$I1.getField(1)]
                                 -- ASSIGN  |LOCAL|
+                                  unnest $$I1 <- scan-collection($$75)
                                   -- UNNEST  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                assign [$$76, $$75] <- [$$D1.getField("other_items"), $$D1.getField(1)]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$D1])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (TestDataverse.Dataset1.Dataset1)  |PARTITIONED|
+                      unnest-map [$$74, $$D1] <- index-search("Dataset1", 0, "TestDataverse", "Dataset1", false, false, 1, $$88, 1, $$88, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          distinct ([$$88])
                           -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$88)
                               -- STABLE_SORT [$$88(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$88])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- BTREE_SEARCH (TestDataverse.Dataset1.d1Idx)  |PARTITIONED|
+                                      unnest-map [$$87, $$88] <- index-search("d1Idx", 0, "TestDataverse", "Dataset1", false, false, 1, $$85, 1, $$86, true, true, true)
+                                      -- BTREE_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$85, $$86] <- [1, 1]
                                           -- ASSIGN  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-1/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-1/query1.plan
index 2c5b278..4ac0253 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-1/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-1/query1.plan
@@ -1,30 +1,57 @@
+distribute result [$$19]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$19])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$19] <- [{"business_id": $$22}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$22])
         -- STREAM_PROJECT  |PARTITIONED|
+          select ($$16)
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$22, $$16])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$16] <- [non-empty-stream()]
                         -- AGGREGATE  |LOCAL|
+                          select (eq("2016-04-26 19:49:16", $#1))
                           -- STREAM_SELECT  |LOCAL|
+                            unnest $#1 <- scan-collection($$21)
                             -- UNNEST  |LOCAL|
+                              nested tuple source
                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                project ([$$22, $$21])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$22, $$21] <- [$$C.getField(1), $$C.getField(2)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$C])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                        unnest-map [$$20, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$26, 1, $$26, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            distinct ([$$26])
                             -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$26)
                                 -- STABLE_SORT [$$26(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$26])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                        unnest-map [$$25, $$26] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$23, 1, $$24, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            assign [$$23, $$24] <- ["2016-04-26 19:49:16", "2016-04-26 19:49:16"]
                                             -- ASSIGN  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-1/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-1/query2.plan
index 761ed03..be8c51b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-1/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-1/query2.plan
@@ -1,32 +1,61 @@
+distribute result [$$47]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$47])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$47] <- [{"$1": $$49}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$49] <- [agg-sql-sum($$51)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$51] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select ($$40)
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$40])
                 -- STREAM_PROJECT  |PARTITIONED|
-                  -- SUBPLAN  |PARTITIONED|
-                          {
+                  subplan {
+                            aggregate [$$40] <- [non-empty-stream()]
                             -- AGGREGATE  |LOCAL|
+                              select (and(gt($$D, "2016"), lt($$D, "2017")))
                               -- STREAM_SELECT  |LOCAL|
+                                unnest $$D <- scan-collection($$50)
                                 -- UNNEST  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                         }
+                  -- SUBPLAN  |PARTITIONED|
+                    project ([$$50])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$50] <- [$$C.getField(2)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$C])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                            unnest-map [$$48, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$55, 1, $$55, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                distinct ([$$55])
                                 -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$55)
                                     -- STABLE_SORT [$$55(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$55])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                            unnest-map [$$54, $$55] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$52, 1, $$53, false, false, false)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$52, $$53] <- ["2016", "2017"]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-1/query3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-1/query3.plan
index f2819ea..e39ca50 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-1/query3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-1/query3.plan
@@ -1,33 +1,63 @@
+distribute result [$$51]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$51])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$51] <- [{"$1": $$53}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$53] <- [agg-sql-sum($$56)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$56] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select ($$43)
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$43])
                 -- STREAM_PROJECT  |PARTITIONED|
-                  -- SUBPLAN  |PARTITIONED|
-                          {
+                  subplan {
+                            aggregate [$$43] <- [empty-stream()]
                             -- AGGREGATE  |LOCAL|
+                              select (not(if-missing-or-null(and(gt($$D, "2016"), lt($$D, "2017")), false)))
                               -- STREAM_SELECT  |LOCAL|
+                                unnest $$D <- scan-collection($$54)
                                 -- UNNEST  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                         }
+                  -- SUBPLAN  |PARTITIONED|
+                    select (lt(0, len($$54)))
                     -- STREAM_SELECT  |PARTITIONED|
+                      project ([$$54])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$54] <- [$$C.getField(2)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$C])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                              unnest-map [$$52, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$60, 1, $$60, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  distinct ([$$60])
                                   -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$60)
                                       -- STABLE_SORT [$$60(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$60])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                              unnest-map [$$59, $$60] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$57, 1, $$58, false, false, false)
+                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  assign [$$57, $$58] <- ["2016", "2017"]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-1/query4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-1/query4.plan
index 1ed6cd6..4657856 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-1/query4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-1/query4.plan
@@ -1,31 +1,59 @@
+distribute result [$$49]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$49])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$49] <- [{"$1": $$51}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$51] <- [agg-sql-sum($$53)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$53] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and($$40, eq($$41, 0)))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$40, $$41])
                 -- STREAM_PROJECT  |PARTITIONED|
-                  -- SUBPLAN  |PARTITIONED|
-                          {
+                  subplan {
+                            aggregate [$$40, $$41] <- [non-empty-stream(), agg-sql-count(switch-case(and(gt($$D, "2016"), lt($$D, "2017")), true, NULL, true))]
                             -- AGGREGATE  |LOCAL|
+                              unnest $$D <- scan-collection($$52)
                               -- UNNEST  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                         }
+                  -- SUBPLAN  |PARTITIONED|
+                    project ([$$52])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$52] <- [$$C.getField(2)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$C])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                            unnest-map [$$50, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$57, 1, $$57, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                distinct ([$$57])
                                 -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$57)
                                     -- STABLE_SORT [$$57(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$57])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                            unnest-map [$$56, $$57] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$54, 1, $$55, false, false, false)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$54, $$55] <- ["2016", "2017"]
                                                 -- ASSIGN  |PARTITIONED|
-                                                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                                  empty-tuple-source
+                                                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-1/query5.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-1/query5.plan
index 9120584..bd2d3ba 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-1/query5.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-1/query5.plan
@@ -1,24 +1,45 @@
+distribute result [$$54]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$54])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$54] <- [{"$1": $$56}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$56] <- [agg-sql-sum($$60)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$60] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select ($$46)
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$46])
                 -- STREAM_PROJECT  |PARTITIONED|
-                  -- SUBPLAN  |PARTITIONED|
-                          {
+                  subplan {
+                            aggregate [$$46] <- [empty-stream()]
                             -- AGGREGATE  |LOCAL|
+                              select (not(if-missing-or-null(and(gt($$D, "2016"), lt($$D, "2017")), false)))
                               -- STREAM_SELECT  |LOCAL|
+                                unnest $$D <- scan-collection($$59)
                                 -- UNNEST  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                         }
+                  -- SUBPLAN  |PARTITIONED|
+                    project ([$$59])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      select (and(lt(0, len($$C.getField("dates_notindexed"))), lt(0, len($$C.getField("dates_notindexed_2")))))
                       -- STREAM_SELECT  |PARTITIONED|
+                        assign [$$59] <- [$$C.getField(2)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$C])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                              data-scan []<-[$$55, $$C] <- TestYelp.YelpCheckin
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-2/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-2/query1.plan
index e29b93c..70b7e1a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-2/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-2/query1.plan
@@ -1,30 +1,57 @@
+distribute result [$$20]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$20])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$20] <- [{"business_id": $$23}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$23])
         -- STREAM_PROJECT  |PARTITIONED|
+          select ($$17)
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$23, $$17])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$17] <- [non-empty-stream()]
                         -- AGGREGATE  |LOCAL|
+                          select (eq("2016-04-26", $#1))
                           -- STREAM_SELECT  |LOCAL|
+                            unnest $#1 <- scan-collection($$22)
                             -- UNNEST  |LOCAL|
+                              nested tuple source
                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                project ([$$23, $$22])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$22, $$23] <- [$$C.getField(2).getField(0), $$C.getField(1)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$C])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                        unnest-map [$$21, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$28, 1, $$28, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            distinct ([$$28])
                             -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$28)
                                 -- STABLE_SORT [$$28(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$28])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                        unnest-map [$$27, $$28] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$25, 1, $$26, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            assign [$$25, $$26] <- ["2016-04-26", "2016-04-26"]
                                             -- ASSIGN  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-2/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-2/query2.plan
index 9843256..651a953 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-2/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-2/query2.plan
@@ -1,32 +1,61 @@
+distribute result [$$48]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$48])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$48] <- [{"$1": $$50}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$50] <- [agg-sql-sum($$53)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$53] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select ($$41)
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$41])
                 -- STREAM_PROJECT  |PARTITIONED|
-                  -- SUBPLAN  |PARTITIONED|
-                          {
+                  subplan {
+                            aggregate [$$41] <- [non-empty-stream()]
                             -- AGGREGATE  |LOCAL|
+                              select (and(gt($$D, "2016"), lt($$D, "2017")))
                               -- STREAM_SELECT  |LOCAL|
+                                unnest $$D <- scan-collection($$51)
                                 -- UNNEST  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                         }
+                  -- SUBPLAN  |PARTITIONED|
+                    project ([$$51])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$51] <- [$$C.getField(2).getField(0)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$C])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                            unnest-map [$$49, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$57, 1, $$57, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                distinct ([$$57])
                                 -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$57)
                                     -- STABLE_SORT [$$57(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$57])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                            unnest-map [$$56, $$57] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$54, 1, $$55, false, false, false)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$54, $$55] <- ["2016", "2017"]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-2/query3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-2/query3.plan
index 10ad036..43156c6 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-2/query3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-2/query3.plan
@@ -1,31 +1,59 @@
+distribute result [$$50]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$50])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$50] <- [{"$1": $$52}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$52] <- [agg-sql-sum($$55)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$55] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and($$41, eq($$42, 0)))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$41, $$42])
                 -- STREAM_PROJECT  |PARTITIONED|
-                  -- SUBPLAN  |PARTITIONED|
-                          {
+                  subplan {
+                            aggregate [$$41, $$42] <- [non-empty-stream(), agg-sql-count(switch-case(and(gt($$D, "2016"), lt($$D, "2017")), true, NULL, true))]
                             -- AGGREGATE  |LOCAL|
+                              unnest $$D <- scan-collection($$53)
                               -- UNNEST  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                         }
+                  -- SUBPLAN  |PARTITIONED|
+                    project ([$$53])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$53] <- [$$C.getField(2).getField(0)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$C])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                            unnest-map [$$51, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$59, 1, $$59, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                distinct ([$$59])
                                 -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$59)
                                     -- STABLE_SORT [$$59(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$59])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                            unnest-map [$$58, $$59] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$56, 1, $$57, false, false, false)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$56, $$57] <- ["2016", "2017"]
                                                 -- ASSIGN  |PARTITIONED|
-                                                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                                  empty-tuple-source
+                                                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-2/query4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-2/query4.plan
index 2d561f4..af31a32 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-2/query4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-2/query4.plan
@@ -1,22 +1,41 @@
+distribute result [$$50]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$50])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$50] <- [{"$1": $$52}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$52] <- [agg-sql-sum($$55)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$55] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and($$41, eq($$42, 0)))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$41, $$42])
                 -- STREAM_PROJECT  |PARTITIONED|
-                  -- SUBPLAN  |PARTITIONED|
-                          {
+                  subplan {
+                            aggregate [$$41, $$42] <- [non-empty-stream(), agg-sql-count(switch-case(and(gt($$D, "2016"), lt($$D, "2017")), true, NULL, true))]
                             -- AGGREGATE  |LOCAL|
+                              unnest $$D <- scan-collection($$53)
                               -- UNNEST  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                         }
+                  -- SUBPLAN  |PARTITIONED|
+                    project ([$$53])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$53] <- [$$C.getField(2).getField("dates_notindexed")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$C])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                            data-scan []<-[$$51, $$C] <- TestYelp.YelpCheckin
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-2/query5.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-2/query5.plan
index 2d561f4..6da09a1 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-2/query5.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-2/query5.plan
@@ -1,22 +1,41 @@
+distribute result [$$49]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$49])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$49] <- [{"$1": $$51}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$51] <- [agg-sql-sum($$54)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$54] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and($$40, eq($$41, 0)))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$40, $$41])
                 -- STREAM_PROJECT  |PARTITIONED|
-                  -- SUBPLAN  |PARTITIONED|
-                          {
+                  subplan {
+                            aggregate [$$40, $$41] <- [non-empty-stream(), agg-sql-count(switch-case(eq(lowercase($$D), "2016"), true, NULL, true))]
                             -- AGGREGATE  |LOCAL|
+                              unnest $$D <- scan-collection($$52)
                               -- UNNEST  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                         }
+                  -- SUBPLAN  |PARTITIONED|
+                    project ([$$52])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$52] <- [$$C.getField(2).getField(0)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$C])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                            data-scan []<-[$$50, $$C] <- TestYelp.YelpCheckin
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-3/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-3/query1.plan
index 1d92106..d53b9ef 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-3/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-3/query1.plan
@@ -1,31 +1,59 @@
+distribute result [$$28]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$28])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$28] <- [{"business_id": $$32}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$32])
         -- STREAM_PROJECT  |PARTITIONED|
+          select ($$25)
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$32, $$25])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$25] <- [non-empty-stream()]
                         -- AGGREGATE  |LOCAL|
+                          select (eq("2016-04-26", $$31))
                           -- STREAM_SELECT  |LOCAL|
+                            assign [$$31] <- [$$D.getField(0)]
                             -- ASSIGN  |LOCAL|
+                              unnest $$D <- scan-collection($$30)
                               -- UNNEST  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                project ([$$32, $$30])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$32, $$30] <- [$$C.getField(1), $$C.getField(2)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$C])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                        unnest-map [$$29, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$36, 1, $$36, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            distinct ([$$36])
                             -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$36)
                                 -- STABLE_SORT [$$36(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$36])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                        unnest-map [$$35, $$36] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$33, 1, $$34, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            assign [$$33, $$34] <- ["2016-04-26", "2016-04-26"]
                                             -- ASSIGN  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-3/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-3/query2.plan
index 45549a5..2794d3e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-3/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-3/query2.plan
@@ -1,31 +1,59 @@
+distribute result [$$31]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$31])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$31] <- [{"business_id": $$36}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$36])
         -- STREAM_PROJECT  |PARTITIONED|
+          select ($$28)
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$36, $$28])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$28] <- [non-empty-stream()]
                         -- AGGREGATE  |LOCAL|
+                          select (and(eq($$35, "2016-04-26"), eq($$34, "19:49:16")))
                           -- STREAM_SELECT  |LOCAL|
+                            assign [$$35, $$34] <- [$$D.getField(0), $$D.getField(1)]
                             -- ASSIGN  |LOCAL|
+                              unnest $$D <- scan-collection($$33)
                               -- UNNEST  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                project ([$$36, $$33])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$36, $$33] <- [$$C.getField(1), $$C.getField(2)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$C])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                        unnest-map [$$32, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$40, 1, $$40, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            distinct ([$$40])
                             -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$40)
                                 -- STABLE_SORT [$$40(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$40])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                        unnest-map [$$39, $$40] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$37, 1, $$38, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            assign [$$37, $$38] <- ["2016-04-26", "2016-04-26"]
                                             -- ASSIGN  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-3/query3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-3/query3.plan
index 2fb6ed5..e133279 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-3/query3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-3/query3.plan
@@ -1,30 +1,57 @@
+distribute result [$$33]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$33])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$33] <- [{"business_id": $$38}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$38])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and($$28, eq($$29, 0)))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$38, $$28, $$29])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$28, $$29] <- [non-empty-stream(), agg-sql-count(switch-case(and(ge($$36, "2016"), le($$36, "2017")), true, NULL, true))]
                         -- AGGREGATE  |LOCAL|
+                          assign [$$36] <- [$$D.getField(0)]
                           -- ASSIGN  |LOCAL|
+                            unnest $$D <- scan-collection($$35)
                             -- UNNEST  |LOCAL|
+                              nested tuple source
                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                project ([$$38, $$35])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$38, $$35] <- [$$C.getField(1), $$C.getField(2)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$C])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                        unnest-map [$$34, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$42, 1, $$42, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            distinct ([$$42])
                             -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$42)
                                 -- STABLE_SORT [$$42(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$42])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                        unnest-map [$$41, $$42] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$39, 1, $$40, true, true, false)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            assign [$$39, $$40] <- ["2016", "2017"]
                                             -- ASSIGN  |PARTITIONED|
-                                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                              empty-tuple-source
+                                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-3/query4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-3/query4.plan
index 7e503bb..843985d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-3/query4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-3/query4.plan
@@ -1,21 +1,39 @@
+distribute result [$$33]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$33])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$33] <- [{"business_id": $$38}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$38])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and($$28, eq($$29, 0)))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$38, $$28, $$29])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$28, $$29] <- [non-empty-stream(), agg-sql-count(switch-case(and(ge($$36, "2016"), le($$36, "2017")), true, NULL, true))]
                         -- AGGREGATE  |LOCAL|
+                          assign [$$36] <- [$$D.getField("date_notindexed")]
                           -- ASSIGN  |LOCAL|
+                            unnest $$D <- scan-collection($$35)
                             -- UNNEST  |LOCAL|
+                              nested tuple source
                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                project ([$$38, $$35])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$38, $$35] <- [$$C.getField(1), $$C.getField(2)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$C])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                        data-scan []<-[$$34, $$C] <- TestYelp.YelpCheckin
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-4/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-4/query1.plan
index 84dc8c7..ed07d47 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-4/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-4/query1.plan
@@ -1,38 +1,70 @@
+distribute result [$$31]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$31])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$31] <- [{"business_id": $$35}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$35])
         -- STREAM_PROJECT  |PARTITIONED|
+          select ($$28)
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$35, $$28])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$28] <- [non-empty-stream()]
                         -- AGGREGATE  |LOCAL|
+                          select ($$27)
                           -- STREAM_SELECT  |LOCAL|
-                            -- SUBPLAN  |LOCAL|
-                                    {
+                            subplan {
+                                      aggregate [$$27] <- [non-empty-stream()]
                                       -- AGGREGATE  |LOCAL|
+                                        select (eq("2016-04-26", $#1))
                                         -- STREAM_SELECT  |LOCAL|
+                                          unnest $#1 <- scan-collection($$34)
                                           -- UNNEST  |LOCAL|
+                                            nested tuple source
                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                    }
+                                   }
+                            -- SUBPLAN  |LOCAL|
+                              assign [$$34] <- [$$D.getField(0)]
                               -- ASSIGN  |LOCAL|
+                                unnest $$D <- scan-collection($$33)
                                 -- UNNEST  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                project ([$$35, $$33])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$35, $$33] <- [$$C.getField(1), $$C.getField(2)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$C])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                        unnest-map [$$32, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$41, 1, $$41, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            distinct ([$$41])
                             -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$41)
                                 -- STABLE_SORT [$$41(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$41])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                        unnest-map [$$40, $$41] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$38, 1, $$39, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            assign [$$38, $$39] <- ["2016-04-26", "2016-04-26"]
                                             -- ASSIGN  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-4/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-4/query2.plan
index a689c35..0eb5b25 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-4/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-4/query2.plan
@@ -1,38 +1,70 @@
+distribute result [$$39]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$39])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$39] <- [{"business_id": $$43}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$43])
         -- STREAM_PROJECT  |PARTITIONED|
+          select ($$36)
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$43, $$36])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$36] <- [non-empty-stream()]
                         -- AGGREGATE  |LOCAL|
+                          select ($$35)
                           -- STREAM_SELECT  |LOCAL|
-                            -- SUBPLAN  |LOCAL|
-                                    {
+                            subplan {
+                                      aggregate [$$35] <- [non-empty-stream()]
                                       -- AGGREGATE  |LOCAL|
+                                        select (eq($$D, "2016-04-26"))
                                         -- STREAM_SELECT  |LOCAL|
+                                          unnest $$D <- scan-collection($$42)
                                           -- UNNEST  |LOCAL|
+                                            nested tuple source
                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                    }
+                                   }
+                            -- SUBPLAN  |LOCAL|
+                              assign [$$42] <- [$$CT.getField(0)]
                               -- ASSIGN  |LOCAL|
+                                unnest $$CT <- scan-collection($$41)
                                 -- UNNEST  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                project ([$$43, $$41])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$43, $$41] <- [$$C.getField(1), $$C.getField(2)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$C])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                        unnest-map [$$40, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$49, 1, $$49, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            distinct ([$$49])
                             -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$49)
                                 -- STABLE_SORT [$$49(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$49])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                        unnest-map [$$48, $$49] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$46, 1, $$47, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            assign [$$46, $$47] <- ["2016-04-26", "2016-04-26"]
                                             -- ASSIGN  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-4/query3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-4/query3.plan
index 8de78d4..7d5fb90 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-4/query3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-4/query3.plan
@@ -1,37 +1,68 @@
+distribute result [$$41]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$41])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$41] <- [{"business_id": $$45}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$45])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and($$36, eq($$37, 0)))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$45, $$36, $$37])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$36, $$37] <- [non-empty-stream(), agg-sql-count(switch-case($$35, true, NULL, true))]
                         -- AGGREGATE  |LOCAL|
-                          -- SUBPLAN  |LOCAL|
-                                  {
+                          subplan {
+                                    aggregate [$$35] <- [non-empty-stream()]
                                     -- AGGREGATE  |LOCAL|
+                                      select (eq("2019-06-07", $$D))
                                       -- STREAM_SELECT  |LOCAL|
+                                        unnest $$D <- scan-collection($$44)
                                         -- UNNEST  |LOCAL|
+                                          nested tuple source
                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                  }
+                                 }
+                          -- SUBPLAN  |LOCAL|
+                            assign [$$44] <- [$$CT.getField(0)]
                             -- ASSIGN  |LOCAL|
+                              unnest $$CT <- scan-collection($$43)
                               -- UNNEST  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                project ([$$45, $$43])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$45, $$43] <- [$$C.getField(1), $$C.getField(2)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$C])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                        unnest-map [$$42, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$51, 1, $$51, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            distinct ([$$51])
                             -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$51)
                                 -- STABLE_SORT [$$51(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$51])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                        unnest-map [$$50, $$51] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$48, 1, $$49, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            assign [$$48, $$49] <- ["2019-06-07", "2019-06-07"]
                                             -- ASSIGN  |PARTITIONED|
-                                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                              empty-tuple-source
+                                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-4/query4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-4/query4.plan
index 10b415f..b4dca3d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-4/query4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-4/query4.plan
@@ -1,37 +1,68 @@
+distribute result [$$41]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$41])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$41] <- [{"business_id": $$45}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$45])
         -- STREAM_PROJECT  |PARTITIONED|
+          select ($$38)
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$45, $$38])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$38] <- [non-empty-stream()]
                         -- AGGREGATE  |LOCAL|
+                          select (and($$35, eq($$36, 0)))
                           -- STREAM_SELECT  |LOCAL|
-                            -- SUBPLAN  |LOCAL|
-                                    {
+                            subplan {
+                                      aggregate [$$35, $$36] <- [non-empty-stream(), agg-sql-count(switch-case(gt($$D, "2019-06-07"), true, NULL, true))]
                                       -- AGGREGATE  |LOCAL|
+                                        unnest $$D <- scan-collection($$44)
                                         -- UNNEST  |LOCAL|
+                                          nested tuple source
                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                    }
+                                   }
+                            -- SUBPLAN  |LOCAL|
+                              assign [$$44] <- [$$CT.getField(0)]
                               -- ASSIGN  |LOCAL|
+                                unnest $$CT <- scan-collection($$43)
                                 -- UNNEST  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                project ([$$45, $$43])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$45, $$43] <- [$$C.getField(1), $$C.getField(2)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$C])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                        unnest-map [$$42, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$50, 1, $$50, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            distinct ([$$50])
                             -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$50)
                                 -- STABLE_SORT [$$50(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$50])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                        unnest-map [$$49, $$50] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$48, 0, false, true, false)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            assign [$$48] <- ["2019-06-07"]
                                             -- ASSIGN  |PARTITIONED|
-                                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                              empty-tuple-source
+                                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-4/query5.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-4/query5.plan
index f1c1609..d63087f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-4/query5.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-4/query5.plan
@@ -1,36 +1,66 @@
+distribute result [$$43]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$43])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$43] <- [{"business_id": $$47}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$47])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and($$38, eq($$39, 0)))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$47, $$38, $$39])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$38, $$39] <- [non-empty-stream(), agg-sql-count(switch-case(and($$35, eq($$36, 0)), true, NULL, true))]
                         -- AGGREGATE  |LOCAL|
-                          -- SUBPLAN  |LOCAL|
-                                  {
+                          subplan {
+                                    aggregate [$$35, $$36] <- [non-empty-stream(), agg-sql-count(switch-case(gt($$D, "2019-06-07"), true, NULL, true))]
                                     -- AGGREGATE  |LOCAL|
+                                      unnest $$D <- scan-collection($$46)
                                       -- UNNEST  |LOCAL|
+                                        nested tuple source
                                         -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                  }
+                                 }
+                          -- SUBPLAN  |LOCAL|
+                            assign [$$46] <- [$$CT.getField(0)]
                             -- ASSIGN  |LOCAL|
+                              unnest $$CT <- scan-collection($$45)
                               -- UNNEST  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                project ([$$47, $$45])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$47, $$45] <- [$$C.getField(1), $$C.getField(2)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$C])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                        unnest-map [$$44, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$52, 1, $$52, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            distinct ([$$52])
                             -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$52)
                                 -- STABLE_SORT [$$52(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$52])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                        unnest-map [$$51, $$52] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$50, 0, false, true, false)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            assign [$$50] <- ["2019-06-07"]
                                             -- ASSIGN  |PARTITIONED|
-                                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                              empty-tuple-source
+                                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-4/query6.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-4/query6.plan
index 3f101b7..5d70cfa 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-4/query6.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-4/query6.plan
@@ -1,29 +1,52 @@
+distribute result [$$43]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$43])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$43] <- [{"business_id": $$48}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$48])
         -- STREAM_PROJECT  |PARTITIONED|
+          select ($$40)
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$48, $$40])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$40] <- [empty-stream()]
                         -- AGGREGATE  |LOCAL|
+                          select (not(if-missing-or-null(and(gt(len($$46), 0), $$38), false)))
                           -- STREAM_SELECT  |LOCAL|
-                            -- SUBPLAN  |LOCAL|
-                                    {
+                            subplan {
+                                      aggregate [$$38] <- [empty-stream()]
                                       -- AGGREGATE  |LOCAL|
+                                        select (not(if-missing-or-null(gt($$D, "2019-06-07"), false)))
                                         -- STREAM_SELECT  |LOCAL|
+                                          unnest $$D <- scan-collection($$46)
                                           -- UNNEST  |LOCAL|
+                                            nested tuple source
                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                    }
+                                   }
+                            -- SUBPLAN  |LOCAL|
+                              assign [$$46] <- [$$CT.getField(0)]
                               -- ASSIGN  |LOCAL|
+                                unnest $$CT <- scan-collection($$45)
                                 -- UNNEST  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                project ([$$48, $$45])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$48, $$45] <- [$$C.getField(1), $$C.getField(2)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$C])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                        data-scan []<-[$$44, $$C] <- TestYelp.YelpCheckin
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-4/query7.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-4/query7.plan
index 0f3a84c..bdb6a57 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-4/query7.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-quantified-queries/use-case-4/query7.plan
@@ -1,39 +1,72 @@
+distribute result [$$50]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$50])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$50] <- [{"business_id": $$57}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$57])
         -- STREAM_PROJECT  |PARTITIONED|
+          select ($$46)
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$57, $$46])
             -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
+              subplan {
+                        aggregate [$$46] <- [empty-stream()]
                         -- AGGREGATE  |LOCAL|
+                          select (not(if-missing-or-null(and(gt(abs($$55), 0), lt(0, len($$54)), $$44), false)))
                           -- STREAM_SELECT  |LOCAL|
-                            -- SUBPLAN  |LOCAL|
-                                    {
+                            subplan {
+                                      aggregate [$$44] <- [empty-stream()]
                                       -- AGGREGATE  |LOCAL|
+                                        select (not(if-missing-or-null(gt($$D, "2019-06-07"), false)))
                                         -- STREAM_SELECT  |LOCAL|
+                                          unnest $$D <- scan-collection($$54)
                                           -- UNNEST  |LOCAL|
+                                            nested tuple source
                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                    }
+                                   }
+                            -- SUBPLAN  |LOCAL|
+                              assign [$$55, $$54] <- [$$CT.getField("num"), $$CT.getField(0)]
                               -- ASSIGN  |LOCAL|
+                                unnest $$CT <- scan-collection($$52)
                                 -- UNNEST  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                select (lt(0, len($$52)))
                 -- STREAM_SELECT  |PARTITIONED|
+                  project ([$$57, $$52])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$57, $$52] <- [$$C.getField(1), $$C.getField(2)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$C])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                          unnest-map [$$51, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$62, 1, $$62, true, true, true)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              distinct ([$$62])
                               -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- STABLE_SORT [$$58(ASC)]  |PARTITIONED|
+                                  order (ASC, $$62)
+                                  -- STABLE_SORT [$$62(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$62])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                          unnest-map [$$61, $$62] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$60, 0, false, true, false)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$60] <- ["2019-06-07"]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-1/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-1/query1.plan
index 85a80b7..a551bc5 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-1/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-1/query1.plan
@@ -1,23 +1,46 @@
+distribute result [$$26]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$26])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$26] <- [{"business_id": $$C.getField(1)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$C])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq("2016-04-26 19:49:16", $$D))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$C, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$28)
               -- UNNEST  |PARTITIONED|
+                assign [$$28] <- [$$C.getField(2)]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$C])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                      unnest-map [$$27, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$33, 1, $$33, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          distinct ([$$33])
                           -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$33)
                               -- STABLE_SORT [$$33(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$33])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                      unnest-map [$$32, $$33] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$30, 1, $$31, true, true, true)
+                                      -- BTREE_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$30, $$31] <- ["2016-04-26 19:49:16", "2016-04-26 19:49:16"]
                                           -- ASSIGN  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-1/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-1/query2.plan
index a65a2c1..20f5a2a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-1/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-1/query2.plan
@@ -1,26 +1,52 @@
+distribute result [$$46]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$46])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$46] <- [{"$1": $$48}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$48] <- [agg-sql-sum($$50)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$50] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(gt($$D, "2016"), lt($$D, "2017")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$D <- scan-collection($$49)
                   -- UNNEST  |PARTITIONED|
+                    project ([$$49])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$49] <- [$$C.getField(2)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$C])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                            unnest-map [$$47, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$54, 1, $$54, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                distinct ([$$54])
                                 -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$54)
                                     -- STABLE_SORT [$$54(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$54])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                            unnest-map [$$53, $$54] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$51, 1, $$52, false, false, false)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$51, $$52] <- ["2016", "2017"]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-2/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-2/query1.plan
index 3f9647b..f63c2d3 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-2/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-2/query1.plan
@@ -1,23 +1,46 @@
+distribute result [$$27]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$27])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$27] <- [{"business_id": $$C.getField(1)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$C])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq("2016-04-26", $$D))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$C, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$29)
               -- UNNEST  |PARTITIONED|
+                assign [$$29] <- [$$C.getField(2).getField(0)]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$C])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                      unnest-map [$$28, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$35, 1, $$35, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          distinct ([$$35])
                           -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$35)
                               -- STABLE_SORT [$$35(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$35])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                      unnest-map [$$34, $$35] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$32, 1, $$33, true, true, true)
+                                      -- BTREE_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$32, $$33] <- ["2016-04-26", "2016-04-26"]
                                           -- ASSIGN  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-2/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-2/query2.plan
index 9af45a6..266a897 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-2/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-2/query2.plan
@@ -1,26 +1,52 @@
+distribute result [$$47]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$47])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$47] <- [{"$1": $$49}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$49] <- [agg-sql-sum($$52)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$52] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(gt($$D, "2016"), lt($$D, "2017")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$D <- scan-collection($$50)
                   -- UNNEST  |PARTITIONED|
+                    project ([$$50])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$50] <- [$$C.getField(2).getField(0)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$C])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                            unnest-map [$$48, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$56, 1, $$56, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                distinct ([$$56])
                                 -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$56)
                                     -- STABLE_SORT [$$56(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$56])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                            unnest-map [$$55, $$56] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$53, 1, $$54, false, false, false)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$53, $$54] <- ["2016", "2017"]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-3/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-3/query1.plan
index 3f9647b..67c789c 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-3/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-3/query1.plan
@@ -1,23 +1,46 @@
+distribute result [$$27]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$27])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$27] <- [{"business_id": $$C.getField(1)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$C])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq("2016-04-26", $$D.getField(0)))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$C, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$29)
               -- UNNEST  |PARTITIONED|
+                assign [$$29] <- [$$C.getField(2)]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$C])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                      unnest-map [$$28, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$35, 1, $$35, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          distinct ([$$35])
                           -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$35)
                               -- STABLE_SORT [$$35(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$35])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                      unnest-map [$$34, $$35] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$32, 1, $$33, true, true, true)
+                                      -- BTREE_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$32, $$33] <- ["2016-04-26", "2016-04-26"]
                                           -- ASSIGN  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-3/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-3/query2.plan
index bb72552..85db7ae 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-3/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-3/query2.plan
@@ -1,28 +1,56 @@
+distribute result [$$48]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$48])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$48] <- [{"$1": $$51}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$51] <- [agg-sql-sum($$53)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$53] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(gt($$49, "2016"), lt($$49, "2017")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$49])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$49] <- [$$D.getField(0)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$D])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      unnest $$D <- scan-collection($$52)
                       -- UNNEST  |PARTITIONED|
+                        project ([$$52])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$52] <- [$$C.getField(2)]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$C])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                                unnest-map [$$50, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$57, 1, $$57, true, true, true)
+                                -- BTREE_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    distinct ([$$57])
                                     -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        order (ASC, $$57)
                                         -- STABLE_SORT [$$57(ASC)]  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$57])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                                unnest-map [$$56, $$57] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$54, 1, $$55, false, false, false)
+                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    assign [$$54, $$55] <- ["2016", "2017"]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-3/query3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-3/query3.plan
index 0202127..5a813d9 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-3/query3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-3/query3.plan
@@ -1,23 +1,46 @@
+distribute result [$$30]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$30])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$30] <- [{"business_id": $$C.getField(1)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$C])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and(eq("2016-04-26", $$D.getField(0)), eq($$D.getField(1), "19:49:16")))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$C, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$32)
               -- UNNEST  |PARTITIONED|
+                assign [$$32] <- [$$C.getField(2)]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$C])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                      unnest-map [$$31, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$39, 1, $$39, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          distinct ([$$39])
                           -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$39)
                               -- STABLE_SORT [$$39(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$39])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                      unnest-map [$$38, $$39] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$36, 1, $$37, true, true, true)
+                                      -- BTREE_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$36, $$37] <- ["2016-04-26", "2016-04-26"]
                                           -- ASSIGN  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-4/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-4/query1.plan
index 4cf8dfe..0c1035b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-4/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-4/query1.plan
@@ -1,27 +1,54 @@
+distribute result [$$37]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$37])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$37] <- [{"business_id": $$C.getField(1)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$C])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq("2016-04-26", $$D))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$C, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$40)
               -- UNNEST  |PARTITIONED|
+                project ([$$C, $$40])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$40] <- [$$CT.getField(0)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$C, $$CT])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      unnest $$CT <- scan-collection($$39)
                       -- UNNEST  |PARTITIONED|
+                        assign [$$39] <- [$$C.getField(2)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$C])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                              unnest-map [$$38, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$45, 1, $$45, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  distinct ([$$45])
                                   -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$45)
                                       -- STABLE_SORT [$$45(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$45])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                              unnest-map [$$44, $$45] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$42, 1, $$43, true, true, true)
+                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  assign [$$42, $$43] <- ["2016-04-26", "2016-04-26"]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-4/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-4/query2.plan
index 4cb1efa..43c8f74 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-4/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/use-case-4/query2.plan
@@ -1,30 +1,60 @@
+distribute result [$$57]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$57])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$57] <- [{"$1": $$59}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$59] <- [agg-sql-sum($$62)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$62] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(gt($$D, "2016"), lt($$D, "2017")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$D <- scan-collection($$61)
                   -- UNNEST  |PARTITIONED|
+                    project ([$$61])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$61] <- [$$CT.getField(0)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$CT])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          unnest $$CT <- scan-collection($$60)
                           -- UNNEST  |PARTITIONED|
+                            project ([$$60])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$60] <- [$$C.getField(2)]
                               -- ASSIGN  |PARTITIONED|
+                                project ([$$C])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                                    unnest-map [$$58, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$66, 1, $$66, true, true, true)
+                                    -- BTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        distinct ([$$66])
                                         -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            order (ASC, $$66)
                                             -- STABLE_SORT [$$66(ASC)]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$66])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                                    unnest-map [$$65, $$66] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$63, 1, $$64, false, false, false)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        assign [$$63, $$64] <- ["2016", "2017"]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-3-level-record-path/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-3-level-record-path/query1.plan
index 0202127..126c0c3 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-3-level-record-path/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-3-level-record-path/query1.plan
@@ -1,23 +1,46 @@
+distribute result [$$29]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$29])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$29] <- [{"business_id": $$C.getField(1)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$C])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq("2016-04-26", $$D))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$C, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$31)
               -- UNNEST  |PARTITIONED|
+                assign [$$31] <- [$$C.getField(2).getField(0).getField(0).getField(0)]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$C])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                      unnest-map [$$30, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$39, 1, $$39, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          distinct ([$$39])
                           -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$39)
                               -- STABLE_SORT [$$39(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$39])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                      unnest-map [$$38, $$39] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$36, 1, $$37, true, true, true)
+                                      -- BTREE_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$36, $$37] <- ["2016-04-26", "2016-04-26"]
                                           -- ASSIGN  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-3-level-record-path/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-3-level-record-path/query2.plan
index 9177af3..9001930 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-3-level-record-path/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-3-level-record-path/query2.plan
@@ -1,26 +1,52 @@
+distribute result [$$49]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$49])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$49] <- [{"$1": $$51}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$51] <- [agg-sql-sum($$56)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$56] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(gt($$D, "2016"), lt($$D, "2017")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$D <- scan-collection($$52)
                   -- UNNEST  |PARTITIONED|
+                    project ([$$52])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$52] <- [$$C.getField(2).getField(0).getField(0).getField(0)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$C])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                            unnest-map [$$50, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$60, 1, $$60, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                distinct ([$$60])
                                 -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$60)
                                     -- STABLE_SORT [$$60(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$60])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                            unnest-map [$$59, $$60] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$57, 1, $$58, false, false, false)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$57, $$58] <- ["2016", "2017"]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-composite-pk/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-composite-pk/query1.plan
index 883fa06..3e6e805 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-composite-pk/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-composite-pk/query1.plan
@@ -1,24 +1,48 @@
+distribute result [$$26]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$26])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$26] <- [{"business_id": $$28}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$28])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq("2016-04-26 19:49:16", $$D))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$28, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$29)
               -- UNNEST  |PARTITIONED|
+                project ([$$28, $$29])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$29] <- [$$C.getField(2)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$28, $$C])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                        unnest-map [$$27, $$28, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 2, $$34, $$35, 2, $$34, $$35, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            distinct ([$$34, $$35])
                             -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$34) (ASC, $$35)
                                 -- STABLE_SORT [$$34(ASC), $$35(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$34, $$35])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                        unnest-map [$$33, $$34, $$35] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$31, 1, $$32, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            assign [$$31, $$32] <- ["2016-04-26 19:49:16", "2016-04-26 19:49:16"]
                                             -- ASSIGN  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-composite-pk/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-composite-pk/query2.plan
index e4d4667..13dca10 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-composite-pk/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-composite-pk/query2.plan
@@ -1,26 +1,52 @@
+distribute result [$$46]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$46])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$46] <- [{"$1": $$49}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$49] <- [agg-sql-sum($$51)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$51] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(gt($$D, "2016"), lt($$D, "2017")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$D <- scan-collection($$50)
                   -- UNNEST  |PARTITIONED|
+                    project ([$$50])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$50] <- [$$C.getField(2)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$C])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                            unnest-map [$$47, $$48, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 2, $$55, $$56, 2, $$55, $$56, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                distinct ([$$55, $$56])
                                 -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$55) (ASC, $$56)
                                     -- STABLE_SORT [$$55(ASC), $$56(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$55, $$56])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                            unnest-map [$$54, $$55, $$56] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$52, 1, $$53, false, false, false)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$52, $$53] <- ["2016", "2017"]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-composite-sk/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-composite-sk/query1.plan
index 2ad5dca..2bd9922 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-composite-sk/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-composite-sk/query1.plan
@@ -1,25 +1,50 @@
+distribute result [$$32]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$32])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$32] <- [{"business_id": $$33}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$33])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and(eq("2016-04-26", $$D.getField(0)), eq("19:49:16", $$D.getField(1))))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$33, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$35)
               -- UNNEST  |PARTITIONED|
+                select (eq("--1UhMGODdWsrMastO9DZw", $$33))
                 -- STREAM_SELECT  |PARTITIONED|
+                  project ([$$33, $$35])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$33, $$35] <- [$$C.getField(1), $$C.getField(2)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$C])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                          unnest-map [$$34, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$44, 1, $$44, true, true, true)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              distinct ([$$44])
                               -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- STABLE_SORT [$$42(ASC)]  |PARTITIONED|
+                                  order (ASC, $$44)
+                                  -- STABLE_SORT [$$44(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$44])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDatesTimes)  |PARTITIONED|
+                                          unnest-map [$$42, $$43, $$44] <- index-search("IdxYelpCheckinDatesTimes", 0, "TestYelp", "YelpCheckin", false, false, 2, $$38, $$39, 2, $$40, $$41, true, true, true)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$38, $$39, $$40, $$41] <- ["2016-04-26", "19:49:16", "2016-04-26", "19:49:16"]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-composite-sk/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-composite-sk/query2.plan
index afcd3a0..7dc4931 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-composite-sk/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-composite-sk/query2.plan
@@ -1,28 +1,56 @@
+distribute result [$$48]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$48])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$48] <- [{"$1": $$51}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$51] <- [agg-sql-sum($$53)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$53] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(gt($$49, "2016"), lt($$49, "2017")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$49])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$49] <- [$$D.getField(0)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$D])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      unnest $$D <- scan-collection($$52)
                       -- UNNEST  |PARTITIONED|
+                        project ([$$52])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$52] <- [$$C.getField(2)]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$C])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                                unnest-map [$$50, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$58, 1, $$58, true, true, true)
+                                -- BTREE_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    distinct ([$$58])
                                     -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        order (ASC, $$58)
                                         -- STABLE_SORT [$$58(ASC)]  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$58])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDatesTimes)  |PARTITIONED|
+                                                unnest-map [$$56, $$57, $$58] <- index-search("IdxYelpCheckinDatesTimes", 0, "TestYelp", "YelpCheckin", false, false, 1, $$54, 1, $$55, false, false, false)
+                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    assign [$$54, $$55] <- ["2016", "2017"]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-composite-sk/query3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-composite-sk/query3.plan
index 4af61e1..aa09b83 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-composite-sk/query3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-composite-sk/query3.plan
@@ -1,19 +1,38 @@
+distribute result [$$54]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$54])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$54] <- [{"$1": $$58}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$58] <- [agg-sql-sum($$60)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$60] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(ge($$55, "00:00:00"), le($$55, "12:00:00"), le($$56, "2017"), ge($$56, "2016")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$56, $$55])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$56, $$55] <- [$$D.getField("date_notindexed"), $$D.getField(1)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$D])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      unnest $$D <- scan-collection($$59)
                       -- UNNEST  |PARTITIONED|
+                        project ([$$59])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$59] <- [$$C.getField(2)]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$C])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                                data-scan []<-[$$57, $$C] <- TestYelp.YelpCheckin
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                    empty-tuple-source
+                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-filter-fields/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-filter-fields/query1.plan
index 3a14007..207b9e8 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-filter-fields/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-filter-fields/query1.plan
@@ -1,25 +1,50 @@
+distribute result [$$29]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$29])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$29] <- [{"business_id": $$30}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$30])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq("2016-04-26 19:49:16", $$D))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$30, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$32)
               -- UNNEST  |PARTITIONED|
+                select (eq($$30, "--1UhMGODdWsrMastO9DZw"))
                 -- STREAM_SELECT  |PARTITIONED|
+                  project ([$$30, $$32])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$30, $$32] <- [$$C.getField(1), $$C.getField(2)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$C])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                          unnest-map [$$31, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$36, 1, $$36, true, true, true) with filter on min:[$$37] max:[$$38]
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              distinct ([$$36])
                               -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  order (ASC, $$36)
                                   -- STABLE_SORT [$$36(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$36, $$37, $$38])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                          unnest-map [$$35, $$36, $$37, $$38] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$33, 1, $$34, true, true, true)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$33, $$34] <- ["2016-04-26 19:49:16", "2016-04-26 19:49:16"]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-filter-fields/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-filter-fields/query2.plan
index a65a2c1..c3dd421 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-filter-fields/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/closed/with-filter-fields/query2.plan
@@ -1,26 +1,52 @@
+distribute result [$$46]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$46])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$46] <- [{"$1": $$48}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$48] <- [agg-sql-sum($$50)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$50] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(gt($$D, "2016"), lt($$D, "2017")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$D <- scan-collection($$49)
                   -- UNNEST  |PARTITIONED|
+                    project ([$$49])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$49] <- [$$C.getField(2)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$C])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                            unnest-map [$$47, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$54, 1, $$54, true, true, true) with filter on min:[$$55] max:[$$56]
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                distinct ([$$54])
                                 -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$54)
                                     -- STABLE_SORT [$$54(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$54, $$55, $$56])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                            unnest-map [$$53, $$54, $$55, $$56] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$51, 1, $$52, false, false, false)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$51, $$52] <- ["2016", "2017"]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query1.plan
index 0d24b2d..366e402 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query1.plan
@@ -1,22 +1,44 @@
+distribute result [$$27]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$27])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$27] <- [{"D": $$D, "F": $$F}]
       -- ASSIGN  |PARTITIONED|
+        select (gt($$F.getField("open_field_3a"), 0))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$D, $$F])
           -- STREAM_PROJECT  |PARTITIONED|
+            unnest $$F <- scan-collection($$29)
             -- UNNEST  |PARTITIONED|
+              assign [$$29] <- [$$D.getField("open_field_1").getField("open_field_2")]
               -- ASSIGN  |PARTITIONED|
+                project ([$$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- BTREE_SEARCH (TestDataverse.TestDataset.TestDataset)  |PARTITIONED|
+                    unnest-map [$$28, $$D] <- index-search("TestDataset", 0, "TestDataverse", "TestDataset", false, false, 1, $$34, 1, $$34, true, true, true)
+                    -- BTREE_SEARCH  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        distinct ([$$34])
                         -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$34)
                             -- STABLE_SORT [$$34(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$34])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- BTREE_SEARCH (TestDataverse.TestDataset.testIndex1)  |PARTITIONED|
+                                    unnest-map [$$33, $$34] <- index-search("testIndex1", 0, "TestDataverse", "TestDataset", false, false, 1, $$32, 0, true, true, false)
+                                    -- BTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        assign [$$32] <- [0]
                                         -- ASSIGN  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query2.plan
index 3585861..37fcc35 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query2.plan
@@ -1,22 +1,44 @@
+distribute result [$$28]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$28])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$28] <- [{"D": $$D, "F": $$F}]
       -- ASSIGN  |PARTITIONED|
+        select (gt($$F.getField("open_field_3b").getField("open_field_4"), 0))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$D, $$F])
           -- STREAM_PROJECT  |PARTITIONED|
+            unnest $$F <- scan-collection($$30)
             -- UNNEST  |PARTITIONED|
+              assign [$$30] <- [$$D.getField("open_field_1").getField("open_field_2")]
               -- ASSIGN  |PARTITIONED|
+                project ([$$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- BTREE_SEARCH (TestDataverse.TestDataset.TestDataset)  |PARTITIONED|
+                    unnest-map [$$29, $$D] <- index-search("TestDataset", 0, "TestDataverse", "TestDataset", false, false, 1, $$36, 1, $$36, true, true, true)
+                    -- BTREE_SEARCH  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        distinct ([$$36])
                         -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$36)
                             -- STABLE_SORT [$$36(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$36])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- BTREE_SEARCH (TestDataverse.TestDataset.testIndex2)  |PARTITIONED|
+                                    unnest-map [$$35, $$36] <- index-search("testIndex2", 0, "TestDataverse", "TestDataset", false, false, 1, $$34, 0, true, true, false)
+                                    -- BTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        assign [$$34] <- [0]
                                         -- ASSIGN  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query3.plan
index 679b2a0..808a1b7 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query3.plan
@@ -1,25 +1,50 @@
+distribute result [$$38]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$38])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$38] <- [{"D": $$D, "F1": $$F1, "F2": $$F2}]
       -- ASSIGN  |PARTITIONED|
+        select (gt($$F2, 0))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$D, $$F1, $$F2])
           -- STREAM_PROJECT  |PARTITIONED|
+            unnest $$F2 <- scan-collection($$41)
             -- UNNEST  |PARTITIONED|
+              assign [$$41] <- [$$F1.getField("open_field_3c").getField("open_field_4a")]
               -- ASSIGN  |PARTITIONED|
+                project ([$$D, $$F1])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$F1 <- scan-collection($$40)
                   -- UNNEST  |PARTITIONED|
+                    assign [$$40] <- [$$D.getField("open_field_1").getField("open_field_2")]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$D])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (TestDataverse.TestDataset.TestDataset)  |PARTITIONED|
+                          unnest-map [$$39, $$D] <- index-search("TestDataset", 0, "TestDataverse", "TestDataset", false, false, 1, $$46, 1, $$46, true, true, true)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              distinct ([$$46])
                               -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  order (ASC, $$46)
                                   -- STABLE_SORT [$$46(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$46])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (TestDataverse.TestDataset.testIndex3)  |PARTITIONED|
+                                          unnest-map [$$45, $$46] <- index-search("testIndex3", 0, "TestDataverse", "TestDataset", false, false, 1, $$44, 0, true, true, false)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$44] <- [0]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query4.plan
index 3f26cee..a584e8d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query4.plan
@@ -1,25 +1,50 @@
+distribute result [$$39]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$39])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$39] <- [{"D": $$D, "F1": $$F1, "F2": $$F2}]
       -- ASSIGN  |PARTITIONED|
+        select (gt($$F2.getField("open_field_5"), 0))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$D, $$F1, $$F2])
           -- STREAM_PROJECT  |PARTITIONED|
+            unnest $$F2 <- scan-collection($$42)
             -- UNNEST  |PARTITIONED|
+              assign [$$42] <- [$$F1.getField("open_field_3c").getField("open_field_4b")]
               -- ASSIGN  |PARTITIONED|
+                project ([$$D, $$F1])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$F1 <- scan-collection($$41)
                   -- UNNEST  |PARTITIONED|
+                    assign [$$41] <- [$$D.getField("open_field_1").getField("open_field_2")]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$D])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (TestDataverse.TestDataset.TestDataset)  |PARTITIONED|
+                          unnest-map [$$40, $$D] <- index-search("TestDataset", 0, "TestDataverse", "TestDataset", false, false, 1, $$48, 1, $$48, true, true, true)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              distinct ([$$48])
                               -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  order (ASC, $$48)
                                   -- STABLE_SORT [$$48(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$48])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (TestDataverse.TestDataset.testIndex4)  |PARTITIONED|
+                                          unnest-map [$$47, $$48] <- index-search("testIndex4", 0, "TestDataverse", "TestDataset", false, false, 1, $$46, 0, true, true, false)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$46] <- [0]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query5.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query5.plan
index f1e0798..9fd7e48 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query5.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query5.plan
@@ -1,22 +1,44 @@
+distribute result [$$27]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$27])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$27] <- [{"D": $$D, "F": $$F}]
       -- ASSIGN  |PARTITIONED|
+        select (gt($$F.getField("open_field_3a"), 0))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$D, $$F])
           -- STREAM_PROJECT  |PARTITIONED|
+            unnest $$F <- scan-collection($$29)
             -- UNNEST  |PARTITIONED|
+              assign [$$29] <- [$$D.getField(1).getField("open_field_2")]
               -- ASSIGN  |PARTITIONED|
+                project ([$$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- BTREE_SEARCH (TestDataverse.TestDataset.TestDataset)  |PARTITIONED|
+                    unnest-map [$$28, $$D] <- index-search("TestDataset", 0, "TestDataverse", "TestDataset", false, false, 1, $$34, 1, $$34, true, true, true)
+                    -- BTREE_SEARCH  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        distinct ([$$34])
                         -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$34)
                             -- STABLE_SORT [$$34(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$34])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- BTREE_SEARCH (TestDataverse.TestDataset.testIndex1c)  |PARTITIONED|
+                                    unnest-map [$$33, $$34] <- index-search("testIndex1c", 0, "TestDataverse", "TestDataset", false, false, 1, $$32, 0, true, true, false)
+                                    -- BTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        assign [$$32] <- [0]
                                         -- ASSIGN  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query6.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query6.plan
index a31846b..48f8c19 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query6.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query6.plan
@@ -1,22 +1,44 @@
+distribute result [$$28]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$28])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$28] <- [{"D": $$D, "F": $$F}]
       -- ASSIGN  |PARTITIONED|
+        select (gt($$F.getField("open_field_3b").getField("open_field_4"), 0))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$D, $$F])
           -- STREAM_PROJECT  |PARTITIONED|
+            unnest $$F <- scan-collection($$30)
             -- UNNEST  |PARTITIONED|
+              assign [$$30] <- [$$D.getField(1).getField(0)]
               -- ASSIGN  |PARTITIONED|
+                project ([$$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- BTREE_SEARCH (TestDataverse.TestDataset.TestDataset)  |PARTITIONED|
+                    unnest-map [$$29, $$D] <- index-search("TestDataset", 0, "TestDataverse", "TestDataset", false, false, 1, $$36, 1, $$36, true, true, true)
+                    -- BTREE_SEARCH  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        distinct ([$$36])
                         -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$36)
                             -- STABLE_SORT [$$36(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$36])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- BTREE_SEARCH (TestDataverse.TestDataset.testIndex2c)  |PARTITIONED|
+                                    unnest-map [$$35, $$36] <- index-search("testIndex2c", 0, "TestDataverse", "TestDataset", false, false, 1, $$34, 0, true, true, false)
+                                    -- BTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        assign [$$34] <- [0]
                                         -- ASSIGN  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query7.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query7.plan
index 4ee8831..2a9e7e8 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query7.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query7.plan
@@ -1,25 +1,50 @@
+distribute result [$$38]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$38])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$38] <- [{"D": $$D, "F1": $$F1, "F2": $$F2}]
       -- ASSIGN  |PARTITIONED|
+        select (gt($$F2, 0))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$D, $$F1, $$F2])
           -- STREAM_PROJECT  |PARTITIONED|
+            unnest $$F2 <- scan-collection($$41)
             -- UNNEST  |PARTITIONED|
+              assign [$$41] <- [$$F1.getField(0).getField("open_field_4a")]
               -- ASSIGN  |PARTITIONED|
+                project ([$$D, $$F1])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$F1 <- scan-collection($$40)
                   -- UNNEST  |PARTITIONED|
+                    assign [$$40] <- [$$D.getField(1).getField(0)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$D])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (TestDataverse.TestDataset.TestDataset)  |PARTITIONED|
+                          unnest-map [$$39, $$D] <- index-search("TestDataset", 0, "TestDataverse", "TestDataset", false, false, 1, $$46, 1, $$46, true, true, true)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              distinct ([$$46])
                               -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  order (ASC, $$46)
                                   -- STABLE_SORT [$$46(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$46])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (TestDataverse.TestDataset.testIndex3c)  |PARTITIONED|
+                                          unnest-map [$$45, $$46] <- index-search("testIndex3c", 0, "TestDataverse", "TestDataset", false, false, 1, $$44, 0, true, true, false)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$44] <- [0]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query8.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query8.plan
index c512a31..086e046 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query8.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/complex-structures/query8.plan
@@ -1,25 +1,50 @@
+distribute result [$$39]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$39])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$39] <- [{"D": $$D, "F1": $$F1, "F2": $$F2}]
       -- ASSIGN  |PARTITIONED|
+        select (gt($$F2.getField("open_field_5"), 0))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$D, $$F1, $$F2])
           -- STREAM_PROJECT  |PARTITIONED|
+            unnest $$F2 <- scan-collection($$42)
             -- UNNEST  |PARTITIONED|
+              assign [$$42] <- [$$F1.getField(0).getField(0)]
               -- ASSIGN  |PARTITIONED|
+                project ([$$D, $$F1])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$F1 <- scan-collection($$41)
                   -- UNNEST  |PARTITIONED|
+                    assign [$$41] <- [$$D.getField(1).getField(0)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$D])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (TestDataverse.TestDataset.TestDataset)  |PARTITIONED|
+                          unnest-map [$$40, $$D] <- index-search("TestDataset", 0, "TestDataverse", "TestDataset", false, false, 1, $$48, 1, $$48, true, true, true)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              distinct ([$$48])
                               -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  order (ASC, $$48)
                                   -- STABLE_SORT [$$48(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$48])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (TestDataverse.TestDataset.testIndex4c)  |PARTITIONED|
+                                          unnest-map [$$47, $$48] <- index-search("testIndex4c", 0, "TestDataverse", "TestDataset", false, false, 1, $$46, 0, true, true, false)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$46] <- [0]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/multiple-indexes/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/multiple-indexes/query1.plan
index 4c76ea0..266579e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/multiple-indexes/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/multiple-indexes/query1.plan
@@ -1,35 +1,70 @@
+distribute result [$$29]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$29])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$29] <- [{"k": $$k, "v": $$v}]
       -- ASSIGN  |PARTITIONED|
+        select (and(eq($$v.getField("a"), 284), eq($$v.getField("b"), 263)))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$k, $$v])
           -- STREAM_PROJECT  |PARTITIONED|
+            unnest $$v <- scan-collection($$31)
             -- UNNEST  |PARTITIONED|
+              assign [$$31] <- [$$k.getField("uarr_i")]
               -- ASSIGN  |PARTITIONED|
+                project ([$$k])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- BTREE_SEARCH (test.KSI.KSI)  |PARTITIONED|
+                    unnest-map [$$30, $$k] <- index-search("KSI", 0, "test", "KSI", false, false, 1, $$42, 1, $$42, true, true, true)
+                    -- BTREE_SEARCH  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        intersect [$$42] <- [[$$37], [$$41]]
                         -- INTERSECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            distinct ([$$37])
                             -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- STABLE_SORT [$$39(ASC)]  |PARTITIONED|
+                                order (ASC, $$37)
+                                -- STABLE_SORT [$$37(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$37])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.KSI.KS1_array_index1)  |PARTITIONED|
+                                        unnest-map [$$36, $$37] <- index-search("KS1_array_index1", 0, "test", "KSI", false, false, 1, $$34, 1, $$35, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            assign [$$34, $$35] <- [284, 284]
                                             -- ASSIGN  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            distinct ([$$41])
                             -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- STABLE_SORT [$$43(ASC)]  |PARTITIONED|
+                                order (ASC, $$41)
+                                -- STABLE_SORT [$$41(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$41])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.KSI.KS1_array_index2)  |PARTITIONED|
+                                        unnest-map [$$40, $$41] <- index-search("KS1_array_index2", 0, "test", "KSI", false, false, 1, $$38, 1, $$39, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            assign [$$38, $$39] <- [263, 263]
                                             -- ASSIGN  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/multiple-indexes/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/multiple-indexes/query2.plan
index 7a2f7ce..9468d19 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/multiple-indexes/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/multiple-indexes/query2.plan
@@ -1,46 +1,92 @@
+distribute result [$$31]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$31])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$31] <- [{"k": $$k, "v": $$v}]
       -- ASSIGN  |PARTITIONED|
+        select (and(eq($$v.getField("a"), 284), eq($$v.getField("b"), 263), eq($$v.getField("c"), 123)))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$k, $$v])
           -- STREAM_PROJECT  |PARTITIONED|
+            unnest $$v <- scan-collection($$33)
             -- UNNEST  |PARTITIONED|
+              assign [$$33] <- [$$k.getField("uarr_i")]
               -- ASSIGN  |PARTITIONED|
+                project ([$$k])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- BTREE_SEARCH (test.KSI.KSI)  |PARTITIONED|
+                    unnest-map [$$32, $$k] <- index-search("KSI", 0, "test", "KSI", false, false, 1, $$49, 1, $$49, true, true, true)
+                    -- BTREE_SEARCH  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        intersect [$$49] <- [[$$40], [$$44], [$$48]]
                         -- INTERSECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            distinct ([$$40])
                             -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- STABLE_SORT [$$42(ASC)]  |PARTITIONED|
+                                order (ASC, $$40)
+                                -- STABLE_SORT [$$40(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$40])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.KSI.KS1_array_index1)  |PARTITIONED|
+                                        unnest-map [$$39, $$40] <- index-search("KS1_array_index1", 0, "test", "KSI", false, false, 1, $$37, 1, $$38, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            assign [$$37, $$38] <- [284, 284]
                                             -- ASSIGN  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            distinct ([$$44])
                             -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- STABLE_SORT [$$46(ASC)]  |PARTITIONED|
+                                order (ASC, $$44)
+                                -- STABLE_SORT [$$44(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$44])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.KSI.KS1_array_index2)  |PARTITIONED|
+                                        unnest-map [$$43, $$44] <- index-search("KS1_array_index2", 0, "test", "KSI", false, false, 1, $$41, 1, $$42, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            assign [$$41, $$42] <- [263, 263]
                                             -- ASSIGN  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            distinct ([$$48])
                             -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- STABLE_SORT [$$50(ASC)]  |PARTITIONED|
+                                order (ASC, $$48)
+                                -- STABLE_SORT [$$48(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$48])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.KSI.KS1_array_index3)  |PARTITIONED|
+                                        unnest-map [$$47, $$48] <- index-search("KS1_array_index3", 0, "test", "KSI", false, false, 1, $$45, 1, $$46, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            assign [$$45, $$46] <- [123, 123]
                                             -- ASSIGN  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-1/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-1/query1.plan
index 85a80b7..3ad02cb 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-1/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-1/query1.plan
@@ -1,23 +1,46 @@
+distribute result [$$26]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$26])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$26] <- [{"business_id": $$C.getField("business_id")}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$C])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq("2016-04-26 19:49:16", $$D))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$C, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$28)
               -- UNNEST  |PARTITIONED|
+                assign [$$28] <- [$$C.getField("dates")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$C])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                      unnest-map [$$27, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$33, 1, $$33, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          distinct ([$$33])
                           -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$33)
                               -- STABLE_SORT [$$33(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$33])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                      unnest-map [$$32, $$33] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$30, 1, $$31, true, true, true)
+                                      -- BTREE_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$30, $$31] <- ["2016-04-26 19:49:16", "2016-04-26 19:49:16"]
                                           -- ASSIGN  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-1/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-1/query2.plan
index a65a2c1..a10431d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-1/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-1/query2.plan
@@ -1,26 +1,52 @@
+distribute result [$$46]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$46])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$46] <- [{"$1": $$48}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$48] <- [agg-sql-sum($$50)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$50] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(gt($$D, "2016"), lt($$D, "2017")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$D <- scan-collection($$49)
                   -- UNNEST  |PARTITIONED|
+                    project ([$$49])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$49] <- [$$C.getField("dates")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$C])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                            unnest-map [$$47, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$54, 1, $$54, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                distinct ([$$54])
                                 -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$54)
                                     -- STABLE_SORT [$$54(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$54])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                            unnest-map [$$53, $$54] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$51, 1, $$52, false, false, false)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$51, $$52] <- ["2016", "2017"]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-2/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-2/query1.plan
index 3f9647b..8d899c2 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-2/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-2/query1.plan
@@ -1,23 +1,46 @@
+distribute result [$$27]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$27])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$27] <- [{"business_id": $$C.getField("business_id")}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$C])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq("2016-04-26", $$D))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$C, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$29)
               -- UNNEST  |PARTITIONED|
+                assign [$$29] <- [$$C.getField("checkin_times").getField("dates")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$C])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                      unnest-map [$$28, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$35, 1, $$35, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          distinct ([$$35])
                           -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$35)
                               -- STABLE_SORT [$$35(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$35])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                      unnest-map [$$34, $$35] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$32, 1, $$33, true, true, true)
+                                      -- BTREE_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$32, $$33] <- ["2016-04-26", "2016-04-26"]
                                           -- ASSIGN  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-2/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-2/query2.plan
index 9af45a6..9cea3bb 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-2/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-2/query2.plan
@@ -1,26 +1,52 @@
+distribute result [$$47]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$47])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$47] <- [{"$1": $$49}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$49] <- [agg-sql-sum($$52)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$52] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(gt($$D, "2016"), lt($$D, "2017")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$D <- scan-collection($$50)
                   -- UNNEST  |PARTITIONED|
+                    project ([$$50])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$50] <- [$$C.getField("checkin_times").getField("dates")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$C])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                            unnest-map [$$48, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$56, 1, $$56, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                distinct ([$$56])
                                 -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$56)
                                     -- STABLE_SORT [$$56(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$56])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                            unnest-map [$$55, $$56] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$53, 1, $$54, false, false, false)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$53, $$54] <- ["2016", "2017"]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-3/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-3/query1.plan
index 3f9647b..862bc40 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-3/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-3/query1.plan
@@ -1,23 +1,46 @@
+distribute result [$$27]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$27])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$27] <- [{"business_id": $$C.getField("business_id")}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$C])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq("2016-04-26", $$D.getField("date")))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$C, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$29)
               -- UNNEST  |PARTITIONED|
+                assign [$$29] <- [$$C.getField("checkin_times")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$C])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                      unnest-map [$$28, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$35, 1, $$35, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          distinct ([$$35])
                           -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$35)
                               -- STABLE_SORT [$$35(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$35])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                      unnest-map [$$34, $$35] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$32, 1, $$33, true, true, true)
+                                      -- BTREE_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$32, $$33] <- ["2016-04-26", "2016-04-26"]
                                           -- ASSIGN  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-3/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-3/query2.plan
index bb72552..a8677a6 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-3/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-3/query2.plan
@@ -1,28 +1,56 @@
+distribute result [$$48]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$48])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$48] <- [{"$1": $$51}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$51] <- [agg-sql-sum($$53)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$53] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(gt($$49, "2016"), lt($$49, "2017")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$49])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$49] <- [$$D.getField("date")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$D])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      unnest $$D <- scan-collection($$52)
                       -- UNNEST  |PARTITIONED|
+                        project ([$$52])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$52] <- [$$C.getField("checkin_times")]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$C])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                                unnest-map [$$50, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$57, 1, $$57, true, true, true)
+                                -- BTREE_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    distinct ([$$57])
                                     -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        order (ASC, $$57)
                                         -- STABLE_SORT [$$57(ASC)]  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$57])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                                unnest-map [$$56, $$57] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$54, 1, $$55, false, false, false)
+                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    assign [$$54, $$55] <- ["2016", "2017"]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-3/query3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-3/query3.plan
index 0202127..54dabe9 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-3/query3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-3/query3.plan
@@ -1,23 +1,46 @@
+distribute result [$$30]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$30])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$30] <- [{"business_id": $$C.getField("business_id")}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$C])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and(eq("2016-04-26", $$D.getField("date")), eq($$D.getField("time"), "19:49:16")))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$C, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$32)
               -- UNNEST  |PARTITIONED|
+                assign [$$32] <- [$$C.getField("checkin_times")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$C])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                      unnest-map [$$31, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$39, 1, $$39, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          distinct ([$$39])
                           -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$39)
                               -- STABLE_SORT [$$39(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$39])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                      unnest-map [$$38, $$39] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$36, 1, $$37, true, true, true)
+                                      -- BTREE_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$36, $$37] <- ["2016-04-26", "2016-04-26"]
                                           -- ASSIGN  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-4/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-4/query1.plan
index 4cf8dfe..bdd6805 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-4/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-4/query1.plan
@@ -1,27 +1,54 @@
+distribute result [$$37]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$37])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$37] <- [{"business_id": $$C.getField("business_id")}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$C])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq("2016-04-26", $$D))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$C, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$40)
               -- UNNEST  |PARTITIONED|
+                project ([$$C, $$40])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$40] <- [$$CT.getField("dates")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$C, $$CT])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      unnest $$CT <- scan-collection($$39)
                       -- UNNEST  |PARTITIONED|
+                        assign [$$39] <- [$$C.getField("checkin_times")]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$C])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                              unnest-map [$$38, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$45, 1, $$45, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  distinct ([$$45])
                                   -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$45)
                                       -- STABLE_SORT [$$45(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$45])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                              unnest-map [$$44, $$45] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$42, 1, $$43, true, true, true)
+                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  assign [$$42, $$43] <- ["2016-04-26", "2016-04-26"]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-4/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-4/query2.plan
index 4cb1efa..3660433 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-4/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/use-case-4/query2.plan
@@ -1,30 +1,60 @@
+distribute result [$$57]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$57])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$57] <- [{"$1": $$59}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$59] <- [agg-sql-sum($$62)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$62] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(gt($$D, "2016"), lt($$D, "2017")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$D <- scan-collection($$61)
                   -- UNNEST  |PARTITIONED|
+                    project ([$$61])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$61] <- [$$CT.getField("dates")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$CT])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          unnest $$CT <- scan-collection($$60)
                           -- UNNEST  |PARTITIONED|
+                            project ([$$60])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$60] <- [$$C.getField("checkin_times")]
                               -- ASSIGN  |PARTITIONED|
+                                project ([$$C])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                                    unnest-map [$$58, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$66, 1, $$66, true, true, true)
+                                    -- BTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        distinct ([$$66])
                                         -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            order (ASC, $$66)
                                             -- STABLE_SORT [$$66(ASC)]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$66])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                                    unnest-map [$$65, $$66] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$63, 1, $$64, false, false, false)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        assign [$$63, $$64] <- ["2016", "2017"]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/with-3-level-record-path/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/with-3-level-record-path/query1.plan
index 0202127..17a2957 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/with-3-level-record-path/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/with-3-level-record-path/query1.plan
@@ -1,23 +1,46 @@
+distribute result [$$29]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$29])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$29] <- [{"business_id": $$C.getField("business_id")}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$C])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq("2016-04-26", $$D))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$C, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$31)
               -- UNNEST  |PARTITIONED|
+                assign [$$31] <- [$$C.getField("checkin_data").getField("checkin_temporal").getField("checkin_times").getField("dates")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$C])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                      unnest-map [$$30, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$39, 1, $$39, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          distinct ([$$39])
                           -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$39)
                               -- STABLE_SORT [$$39(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$39])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                      unnest-map [$$38, $$39] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$36, 1, $$37, true, true, true)
+                                      -- BTREE_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$36, $$37] <- ["2016-04-26", "2016-04-26"]
                                           -- ASSIGN  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/with-3-level-record-path/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/with-3-level-record-path/query2.plan
index 9177af3..23ecde4 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/with-3-level-record-path/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/with-3-level-record-path/query2.plan
@@ -1,26 +1,52 @@
+distribute result [$$49]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$49])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$49] <- [{"$1": $$51}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$51] <- [agg-sql-sum($$56)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$56] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(gt($$D, "2016"), lt($$D, "2017")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$D <- scan-collection($$52)
                   -- UNNEST  |PARTITIONED|
+                    project ([$$52])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$52] <- [$$C.getField("checkin_data").getField("checkin_temporal").getField("checkin_times").getField("dates")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$C])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                            unnest-map [$$50, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$60, 1, $$60, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                distinct ([$$60])
                                 -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$60)
                                     -- STABLE_SORT [$$60(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$60])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDates)  |PARTITIONED|
+                                            unnest-map [$$59, $$60] <- index-search("IdxYelpCheckinDates", 0, "TestYelp", "YelpCheckin", false, false, 1, $$57, 1, $$58, false, false, false)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$57, $$58] <- ["2016", "2017"]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/with-composite-sk/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/with-composite-sk/query1.plan
index 8ae90bf..d415b60 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/with-composite-sk/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/array-index/select-unnest-queries/open/with-composite-sk/query1.plan
@@ -1,25 +1,50 @@
+distribute result [$$32]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$32])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$32] <- [{"business_id": $$33}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$33])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and(eq("2016-04-26", $$D.getField("date")), eq("19:49:16", $$D.getField("time"))))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$33, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$35)
               -- UNNEST  |PARTITIONED|
+                select (eq("--1UhMGODdWsrMastO9DZw", $$33))
                 -- STREAM_SELECT  |PARTITIONED|
+                  project ([$$33, $$35])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$33, $$35] <- [$$C.getField("business_id"), $$C.getField("checkin_times")]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$C])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (TestYelp.YelpCheckin.YelpCheckin)  |PARTITIONED|
+                          unnest-map [$$34, $$C] <- index-search("YelpCheckin", 0, "TestYelp", "YelpCheckin", false, false, 1, $$44, 1, $$44, true, true, true)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              distinct ([$$44])
                               -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  order (ASC, $$44)
                                   -- STABLE_SORT [$$44(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$44])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (TestYelp.YelpCheckin.IdxYelpCheckinDatesTimes)  |PARTITIONED|
+                                          unnest-map [$$42, $$43, $$44] <- index-search("IdxYelpCheckinDatesTimes", 0, "TestYelp", "YelpCheckin", false, false, 2, $$38, $$39, 2, $$40, $$41, true, true, true)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$38, $$39, $$40, $$41] <- ["2016-04-26", "19:49:16", "2016-04-26", "19:49:16"]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/hints-indexnl-params/hints-indexnl-params-3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/hints-indexnl-params/hints-indexnl-params-3.plan
index 9627dce..8675bcf 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/hints-indexnl-params/hints-indexnl-params-3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/hints-indexnl-params/hints-indexnl-params-3.plan
@@ -1,25 +1,50 @@
+distribute result [$$37]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$37(ASC) ]  |PARTITIONED|
+    order (ASC, $$37)
     -- STABLE_SORT [$$37(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$37])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$34, $$tenk2.getField(7)))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$37] <- [$$tenk2.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$34, $$tenk2])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk2.tenk2)  |PARTITIONED|
+                  unnest-map [$$33, $$tenk2] <- index-search("tenk2", 0, "test", "tenk2", true, false, 1, $$43, 1, $$43, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$43)
                       -- STABLE_SORT [$$43(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$34, $$43])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.tenk2.idx_tenk2_1k_2k)  |PARTITIONED|
+                              unnest-map [$$41, $$42, $$43] <- index-search("idx_tenk2_1k_2k", 0, "test", "tenk2", true, true, 1, $$34, 1, $$34, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                  project ([$$34])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$34] <- [$$tenk1.getField(7)]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$tenk1])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (test.tenk1.tenk1)  |PARTITIONED|
+                                          unnest-map [$$32, $$tenk1] <- index-search("tenk1", 0, "test", "tenk1", false, false, 0, 1, $$38, true, false, false)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$38] <- [1]
                                               -- ASSIGN  |PARTITIONED|
-                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                                empty-tuple-source
+                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/hints-indexnl-params/hints-indexnl-params-4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/hints-indexnl-params/hints-indexnl-params-4.plan
index 758182a..6b11c30 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/hints-indexnl-params/hints-indexnl-params-4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/hints-indexnl-params/hints-indexnl-params-4.plan
@@ -1,25 +1,50 @@
+distribute result [$$37]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$37(ASC) ]  |PARTITIONED|
+    order (ASC, $$37)
     -- STABLE_SORT [$$37(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$37])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$34, $$tenk2.getField(7)))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$37] <- [$$tenk2.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$34, $$tenk2])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk2.tenk2)  |PARTITIONED|
+                  unnest-map [$$33, $$tenk2] <- index-search("tenk2", 0, "test", "tenk2", true, false, 1, $$42, 1, $$42, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$42)
                       -- STABLE_SORT [$$42(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$34, $$42])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.tenk2.idx_tenk2_1k)  |PARTITIONED|
+                              unnest-map [$$41, $$42] <- index-search("idx_tenk2_1k", 0, "test", "tenk2", true, true, 1, $$34, 1, $$34, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                  project ([$$34])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$34] <- [$$tenk1.getField(7)]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$tenk1])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (test.tenk1.tenk1)  |PARTITIONED|
+                                          unnest-map [$$32, $$tenk1] <- index-search("tenk1", 0, "test", "tenk1", false, false, 0, 1, $$38, true, false, false)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$38] <- [1]
                                               -- ASSIGN  |PARTITIONED|
-                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                                empty-tuple-source
+                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/hints-indexnl-params/hints-indexnl-params-5.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/hints-indexnl-params/hints-indexnl-params-5.plan
index 9627dce..8675bcf 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/hints-indexnl-params/hints-indexnl-params-5.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/hints-indexnl-params/hints-indexnl-params-5.plan
@@ -1,25 +1,50 @@
+distribute result [$$37]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$37(ASC) ]  |PARTITIONED|
+    order (ASC, $$37)
     -- STABLE_SORT [$$37(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$37])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$34, $$tenk2.getField(7)))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$37] <- [$$tenk2.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$34, $$tenk2])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk2.tenk2)  |PARTITIONED|
+                  unnest-map [$$33, $$tenk2] <- index-search("tenk2", 0, "test", "tenk2", true, false, 1, $$43, 1, $$43, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$43)
                       -- STABLE_SORT [$$43(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$34, $$43])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.tenk2.idx_tenk2_1k_2k)  |PARTITIONED|
+                              unnest-map [$$41, $$42, $$43] <- index-search("idx_tenk2_1k_2k", 0, "test", "tenk2", true, true, 1, $$34, 1, $$34, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                  project ([$$34])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$34] <- [$$tenk1.getField(7)]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$tenk1])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (test.tenk1.tenk1)  |PARTITIONED|
+                                          unnest-map [$$32, $$tenk1] <- index-search("tenk1", 0, "test", "tenk1", false, false, 0, 1, $$38, true, false, false)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$38] <- [1]
                                               -- ASSIGN  |PARTITIONED|
-                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                                empty-tuple-source
+                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/hints-indexnl-params/hints-indexnl-params-6.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/hints-indexnl-params/hints-indexnl-params-6.plan
index 758182a..6b11c30 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/hints-indexnl-params/hints-indexnl-params-6.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/hints-indexnl-params/hints-indexnl-params-6.plan
@@ -1,25 +1,50 @@
+distribute result [$$37]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$37(ASC) ]  |PARTITIONED|
+    order (ASC, $$37)
     -- STABLE_SORT [$$37(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$37])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$34, $$tenk2.getField(7)))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$37] <- [$$tenk2.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$34, $$tenk2])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk2.tenk2)  |PARTITIONED|
+                  unnest-map [$$33, $$tenk2] <- index-search("tenk2", 0, "test", "tenk2", true, false, 1, $$42, 1, $$42, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$42)
                       -- STABLE_SORT [$$42(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$34, $$42])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.tenk2.idx_tenk2_1k)  |PARTITIONED|
+                              unnest-map [$$41, $$42] <- index-search("idx_tenk2_1k", 0, "test", "tenk2", true, true, 1, $$34, 1, $$34, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                  project ([$$34])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$34] <- [$$tenk1.getField(7)]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$tenk1])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (test.tenk1.tenk1)  |PARTITIONED|
+                                          unnest-map [$$32, $$tenk1] <- index-search("tenk1", 0, "test", "tenk1", false, false, 0, 1, $$38, true, false, false)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$38] <- [1]
                                               -- ASSIGN  |PARTITIONED|
-                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                                empty-tuple-source
+                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/hints-indexnl-params/hints-indexnl-params-7.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/hints-indexnl-params/hints-indexnl-params-7.plan
index 9627dce..8675bcf 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/hints-indexnl-params/hints-indexnl-params-7.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/hints-indexnl-params/hints-indexnl-params-7.plan
@@ -1,25 +1,50 @@
+distribute result [$$37]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$37(ASC) ]  |PARTITIONED|
+    order (ASC, $$37)
     -- STABLE_SORT [$$37(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$37])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$34, $$tenk2.getField(7)))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$37] <- [$$tenk2.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$34, $$tenk2])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk2.tenk2)  |PARTITIONED|
+                  unnest-map [$$33, $$tenk2] <- index-search("tenk2", 0, "test", "tenk2", true, false, 1, $$43, 1, $$43, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$43)
                       -- STABLE_SORT [$$43(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$34, $$43])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.tenk2.idx_tenk2_1k_2k)  |PARTITIONED|
+                              unnest-map [$$41, $$42, $$43] <- index-search("idx_tenk2_1k_2k", 0, "test", "tenk2", true, true, 1, $$34, 1, $$34, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                  project ([$$34])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$34] <- [$$tenk1.getField(7)]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$tenk1])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (test.tenk1.tenk1)  |PARTITIONED|
+                                          unnest-map [$$32, $$tenk1] <- index-search("tenk1", 0, "test", "tenk1", false, false, 0, 1, $$38, true, false, false)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$38] <- [1]
                                               -- ASSIGN  |PARTITIONED|
-                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                                empty-tuple-source
+                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/hints-indexnl-params/hints-indexnl-params-8.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/hints-indexnl-params/hints-indexnl-params-8.plan
index 758182a..6b11c30 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/hints-indexnl-params/hints-indexnl-params-8.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/hints-indexnl-params/hints-indexnl-params-8.plan
@@ -1,25 +1,50 @@
+distribute result [$$37]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$37(ASC) ]  |PARTITIONED|
+    order (ASC, $$37)
     -- STABLE_SORT [$$37(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$37])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$34, $$tenk2.getField(7)))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$37] <- [$$tenk2.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$34, $$tenk2])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk2.tenk2)  |PARTITIONED|
+                  unnest-map [$$33, $$tenk2] <- index-search("tenk2", 0, "test", "tenk2", true, false, 1, $$42, 1, $$42, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$42)
                       -- STABLE_SORT [$$42(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$34, $$42])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.tenk2.idx_tenk2_1k)  |PARTITIONED|
+                              unnest-map [$$41, $$42] <- index-search("idx_tenk2_1k", 0, "test", "tenk2", true, true, 1, $$34, 1, $$34, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                  project ([$$34])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$34] <- [$$tenk1.getField(7)]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$tenk1])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (test.tenk1.tenk1)  |PARTITIONED|
+                                          unnest-map [$$32, $$tenk1] <- index-search("tenk1", 0, "test", "tenk1", false, false, 0, 1, $$38, true, false, false)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$38] <- [1]
                                               -- ASSIGN  |PARTITIONED|
-                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                                empty-tuple-source
+                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_ps.plan
index d2df75a..03130a2 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_ps.plan
@@ -1,109 +1,212 @@
+distribute result [$$39]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$39])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$39] <- [{"tweetid1": $$51, "count1": $$67, "t2info": $$38}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$51)
           -- STABLE_SORT [$$51(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$51(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$71
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- PRE_CLUSTERED_GROUP_BY[$$68]  |PARTITIONED|
-                              {
+                      group by ([$$51 := $$68]) decor ([$$67]) {
+                                aggregate [$$38] <- [listify({"tweetid2": $$43, "count2": $$44})]
                                 -- AGGREGATE  |LOCAL|
+                                  select (not(is-missing($$43)))
                                   -- STREAM_SELECT  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- PRE_CLUSTERED_GROUP_BY[$$68]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$68) (ASC, $$43)
                           -- STABLE_SORT [$$68(ASC), $$43(ASC)]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$68]  |PARTITIONED|
+                              union ($$64, $$56, $$43) ($$66, $$55, $$44) ($$45, $$45, $$67) ($$42, $$42, $$68)
                               -- UNION_ALL  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$64, $$66, $$45, $$42])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    select (eq($$45, $$66)) retain-untrue ($$43 <- MISSING)
                                     -- STREAM_SELECT  |PARTITIONED|
+                                      project ([$$42, $$45, $$55, $$56, $$64, $$66])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$66] <- [$$65.getField(7)]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                            left-outer-unnest-map [$$64, $$65] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$56, 1, $$56, true, true, true)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$42, $$45, $$55, $$56])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    split ($$57)
                                                     -- SPLIT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                                        left-outer-unnest-map [$$55, $$56, $$57] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$45, 1, $$45, true, true, true)
+                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                          exchange
                                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                            project ([$$42, $$45])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$45] <- [$$t1.getField(6)]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                  unnest-map [$$42, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$52, true, false, false)
+                                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      assign [$$52] <- [10]
                                                                       -- ASSIGN  |PARTITIONED|
+                                                                        empty-tuple-source
                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$56, $$55, $$45, $$42])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      split ($$57)
                                       -- SPLIT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                          left-outer-unnest-map [$$55, $$56, $$57] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$45, 1, $$45, true, true, true)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                              project ([$$42, $$45])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$45] <- [$$t1.getField(6)]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                    unnest-map [$$42, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$52, true, false, false)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        assign [$$52] <- [10]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$71] <- [agg-range-map($$69, $$70)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$69, $$70] <- [agg-local-sampling($$51), agg-null-writer($$51)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$51])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- PRE_CLUSTERED_GROUP_BY[$$68]  |PARTITIONED|
-                                        {
+                                group by ([$$51 := $$68]) decor ([$$67]) {
+                                          aggregate [$$38] <- [listify({"tweetid2": $$43, "count2": $$44})]
                                           -- AGGREGATE  |LOCAL|
+                                            select (not(is-missing($$43)))
                                             -- STREAM_SELECT  |LOCAL|
+                                              nested tuple source
                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- PRE_CLUSTERED_GROUP_BY[$$68]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$68) (ASC, $$43)
                                     -- STABLE_SORT [$$68(ASC), $$43(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$68]  |PARTITIONED|
+                                        union ($$64, $$56, $$43) ($$66, $$55, $$44) ($$45, $$45, $$67) ($$42, $$42, $$68)
                                         -- UNION_ALL  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$64, $$66, $$45, $$42])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              select (eq($$45, $$66)) retain-untrue ($$43 <- MISSING)
                                               -- STREAM_SELECT  |PARTITIONED|
+                                                project ([$$42, $$45, $$55, $$56, $$64, $$66])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$66] <- [$$65.getField(7)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                      left-outer-unnest-map [$$64, $$65] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$56, 1, $$56, true, true, true)
+                                                      -- BTREE_SEARCH  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          project ([$$42, $$45, $$55, $$56])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              split ($$57)
                                                               -- SPLIT  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                                                  left-outer-unnest-map [$$55, $$56, $$57] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$45, 1, $$45, true, true, true)
+                                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                                    exchange
                                                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                      project ([$$42, $$45])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        assign [$$45] <- [$$t1.getField(6)]
                                                                         -- ASSIGN  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                            -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                            unnest-map [$$42, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$52, true, false, false)
+                                                                            -- BTREE_SEARCH  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                assign [$$52] <- [10]
                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                  empty-tuple-source
                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$56, $$55, $$45, $$42])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                split ($$57)
                                                 -- SPLIT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                                    left-outer-unnest-map [$$55, $$56, $$57] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$45, 1, $$45, true, true, true)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                        project ([$$42, $$45])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$45] <- [$$t1.getField(6)]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                              unnest-map [$$42, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$52, true, false, false)
+                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  assign [$$52] <- [10]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    empty-tuple-source
                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02.plan
index c8f17db..772b036 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02.plan
@@ -1,34 +1,65 @@
+distribute result [$$43]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$43])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$43] <- [{"tweetid1": $$56, "count1": $$50, "t2info": $$42}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$56(ASC) ]  |PARTITIONED|
-          -- PRE_CLUSTERED_GROUP_BY[$$46]  |PARTITIONED|
-                  {
+          group by ([$$56 := $$46]) decor ([$$50]) {
+                    aggregate [$$42] <- [listify({"tweetid2": $$47, "count2": $$49})]
                     -- AGGREGATE  |LOCAL|
+                      select (not(is-missing($$47)))
                       -- STREAM_SELECT  |LOCAL|
+                        nested tuple source
                         -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- PRE_CLUSTERED_GROUP_BY[$$46]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$46) (ASC, $$47)
               -- STABLE_SORT [$$46(ASC), $$47(ASC)]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$46]  |PARTITIONED|
+                  select (and(eq($$50, $$49), neq($$46, $$47))) retain-untrue ($$47 <- MISSING)
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$50, $$46, $$47, $$49])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$49] <- [$$t2.getField(7)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$50, $$46, $$47, $$t2])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                            left-outer-unnest-map [$$47, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$61, 1, $$61, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$61)
                                 -- STABLE_SORT [$$61(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$50, $$46, $$61])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                        left-outer-unnest-map [$$60, $$61] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$50, 1, $$50, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                            project ([$$46, $$50])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$50] <- [$$t1.getField(6)]
                                               -- ASSIGN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                  unnest-map [$$46, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$57, true, false, false)
+                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      assign [$$57] <- [10]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_ps.plan
index ef866c9..f56edbf 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_ps.plan
@@ -1,77 +1,148 @@
+distribute result [$$43]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$43])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$43] <- [{"tweetid1": $$56, "count1": $$50, "t2info": $$42}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$56)
           -- STABLE_SORT [$$56(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$56(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$64
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- PRE_CLUSTERED_GROUP_BY[$$46]  |PARTITIONED|
-                              {
+                      group by ([$$56 := $$46]) decor ([$$50]) {
+                                aggregate [$$42] <- [listify({"tweetid2": $$47, "count2": $$49})]
                                 -- AGGREGATE  |LOCAL|
+                                  select (not(is-missing($$47)))
                                   -- STREAM_SELECT  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- PRE_CLUSTERED_GROUP_BY[$$46]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$46) (ASC, $$47)
                           -- STABLE_SORT [$$46(ASC), $$47(ASC)]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$46]  |PARTITIONED|
+                              select (and(eq($$50, $$49), neq($$46, $$47))) retain-untrue ($$47 <- MISSING)
                               -- STREAM_SELECT  |PARTITIONED|
+                                project ([$$50, $$46, $$47, $$49])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  assign [$$49] <- [$$t2.getField(7)]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$50, $$46, $$47, $$t2])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                        left-outer-unnest-map [$$47, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$61, 1, $$61, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            order (ASC, $$61)
                                             -- STABLE_SORT [$$61(ASC)]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$50, $$46, $$61])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                                    left-outer-unnest-map [$$60, $$61] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$50, 1, $$50, true, true, true)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                        project ([$$46, $$50])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$50] <- [$$t1.getField(6)]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                              unnest-map [$$46, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$57, true, false, false)
+                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  assign [$$57] <- [10]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    empty-tuple-source
                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$64] <- [agg-range-map($$62, $$63)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$62, $$63] <- [agg-local-sampling($$56), agg-null-writer($$56)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$56])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- PRE_CLUSTERED_GROUP_BY[$$46]  |PARTITIONED|
-                                        {
+                                group by ([$$56 := $$46]) decor ([$$50]) {
+                                          aggregate [$$42] <- [listify({"tweetid2": $$47, "count2": $$49})]
                                           -- AGGREGATE  |LOCAL|
+                                            select (not(is-missing($$47)))
                                             -- STREAM_SELECT  |LOCAL|
+                                              nested tuple source
                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- PRE_CLUSTERED_GROUP_BY[$$46]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$46) (ASC, $$47)
                                     -- STABLE_SORT [$$46(ASC), $$47(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$46]  |PARTITIONED|
+                                        select (and(eq($$50, $$49), neq($$46, $$47))) retain-untrue ($$47 <- MISSING)
                                         -- STREAM_SELECT  |PARTITIONED|
+                                          project ([$$50, $$46, $$47, $$49])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$49] <- [$$t2.getField(7)]
                                             -- ASSIGN  |PARTITIONED|
+                                              project ([$$50, $$46, $$47, $$t2])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                  left-outer-unnest-map [$$47, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$61, 1, $$61, true, true, true)
+                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      order (ASC, $$61)
                                                       -- STABLE_SORT [$$61(ASC)]  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          project ([$$50, $$46, $$61])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                                              left-outer-unnest-map [$$60, $$61] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$50, 1, $$50, true, true, true)
+                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                exchange
                                                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                  project ([$$46, $$50])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    assign [$$50] <- [$$t1.getField(6)]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                        unnest-map [$$46, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$57, true, false, false)
+                                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            assign [$$57] <- [10]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              empty-tuple-source
                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_03-index-only.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_03-index-only.plan
index f816bd7..472807b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_03-index-only.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_03-index-only.plan
@@ -1,49 +1,98 @@
+distribute result [$$35]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$35])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$35] <- [{"tweetid1": $$65, "count1": $$66, "tweetid2": $$40, "count2": $$42}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$65(ASC), $$40(ASC) ]  |PARTITIONED|
+          order (ASC, $$65) (ASC, $$40)
           -- STABLE_SORT [$$65(ASC), $$40(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$65, $$66, $$40, $$42])
               -- STREAM_PROJECT  |PARTITIONED|
+                select ($$67)
                 -- STREAM_SELECT  |PARTITIONED|
+                  window-aggregate [$$67] <- [win-mark-first-missing-impl($$40)] partition [$$65] order (DESC, $$40)
                   -- WINDOW_STREAM  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$65) (DESC, $$40)
                       -- STABLE_SORT [$$65(ASC), $$40(DESC)]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$65]  |PARTITIONED|
+                          union ($$62, $$54, $$40) ($$64, $$53, $$42) ($$39, $$39, $$65) ($$41, $$41, $$66)
                           -- UNION_ALL  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$62, $$64, $$39, $$41])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                select (eq($$41, $$64)) retain-untrue ($$40 <- MISSING)
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  project ([$$39, $$41, $$53, $$54, $$62, $$64])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$64] <- [$$63.getField(7)]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                        left-outer-unnest-map [$$62, $$63] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$54, 1, $$54, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$39, $$41, $$53, $$54])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                split ($$55)
                                                 -- SPLIT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                                    left-outer-unnest-map [$$53, $$54, $$55] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$41, 1, $$41, true, true, true)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                        project ([$$39, $$41])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$41] <- [$$t1.getField(6)]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                              unnest-map [$$39, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$50, true, false, false)
+                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  assign [$$50] <- [10]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    empty-tuple-source
                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$54, $$53, $$39, $$41])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  split ($$55)
                                   -- SPLIT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                      left-outer-unnest-map [$$53, $$54, $$55] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$41, 1, $$41, true, true, true)
+                                      -- BTREE_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                          project ([$$39, $$41])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$41] <- [$$t1.getField(6)]
                                             -- ASSIGN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                unnest-map [$$39, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$50, true, false, false)
+                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    assign [$$50] <- [10]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_03.plan
index dc89dd2..11e6218 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_03.plan
@@ -1,33 +1,66 @@
+distribute result [$$35]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$35])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$35] <- [{"tweetid1": $$39, "count1": $$41, "tweetid2": $$40, "count2": $$42}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$39(ASC), $$40(ASC) ]  |PARTITIONED|
+          order (ASC, $$39) (ASC, $$40)
           -- STABLE_SORT [$$39(ASC), $$40(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$39, $$41, $$40, $$42])
               -- STREAM_PROJECT  |PARTITIONED|
+                select ($$55)
                 -- STREAM_SELECT  |PARTITIONED|
+                  window-aggregate [$$55] <- [win-mark-first-missing-impl($$40)] partition [$$39] order (DESC, $$40)
                   -- WINDOW_STREAM  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$39) (DESC, $$40)
                       -- STABLE_SORT [$$39(ASC), $$40(DESC)]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$39]  |PARTITIONED|
+                          select (eq($$41, $$42)) retain-untrue ($$40 <- MISSING)
                           -- STREAM_SELECT  |PARTITIONED|
+                            project ([$$39, $$41, $$40, $$42])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$42] <- [$$t2.getField(7)]
                               -- ASSIGN  |PARTITIONED|
+                                project ([$$39, $$41, $$40, $$t2])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                    left-outer-unnest-map [$$40, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$54, 1, $$54, true, true, true)
+                                    -- BTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        order (ASC, $$54)
                                         -- STABLE_SORT [$$54(ASC)]  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$39, $$41, $$54])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                                left-outer-unnest-map [$$53, $$54] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$41, 1, $$41, true, true, true)
+                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                  exchange
                                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                    project ([$$39, $$41])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      assign [$$41] <- [$$t1.getField(6)]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                          unnest-map [$$39, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$50, true, false, false)
+                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              assign [$$50] <- [10]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                empty-tuple-source
                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/primary-between-join_01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/primary-between-join_01.plan
index 7d21217..eb4ade0 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/primary-between-join_01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/primary-between-join_01.plan
@@ -1,13 +1,26 @@
+distribute result [$$x]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$x])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-        -- BTREE_SEARCH (test1.DsTwo.DsTwo)  |PARTITIONED|
+        unnest-map [$$31, $$y] <- index-search("DsTwo", 0, "test1", "DsTwo", true, true, 0, 1, $$29, true, true, false)
+        -- BTREE_SEARCH  |PARTITIONED|
+          exchange
           -- BROADCAST_EXCHANGE  |PARTITIONED|
+            select (le($$29, 10))
             -- STREAM_SELECT  |PARTITIONED|
+              assign [$$29] <- [$$x.getField(1)]
               -- ASSIGN  |PARTITIONED|
+                project ([$$x])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- DATASOURCE_SCAN (test1.DsOne)  |PARTITIONED|
+                    data-scan []<-[$$30, $$x] <- test1.DsOne
+                    -- DATASOURCE_SCAN  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/primary-equi-join_04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/primary-equi-join_04.plan
index cda45d0..e15a244 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/primary-equi-join_04.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/primary-equi-join_04.plan
@@ -1,16 +1,32 @@
+distribute result [$$27]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$27])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$27] <- [{"customer": $$c, "order": $$o}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$o, $$c])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+            unnest-map [$$29, $$c] <- index-search("Customers", 0, "test", "Customers", true, true, 1, $$30, 1, $$30, true, true, true)
+            -- BTREE_SEARCH  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (ASC, $$30)
                 -- STABLE_SORT [$$30(ASC)]  |PARTITIONED|
+                  exchange
                   -- HASH_PARTITION_EXCHANGE [$$30]  |PARTITIONED|
+                    assign [$$30] <- [$$o.getField(1)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$o])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (test.Orders)  |PARTITIONED|
+                          data-scan []<-[$$28, $$o] <- test.Orders
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/secondary-equi-join-multiindex.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/secondary-equi-join-multiindex.plan
index ac9158e..13d92fa 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/secondary-equi-join-multiindex.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/secondary-equi-join-multiindex.plan
@@ -1,22 +1,44 @@
+distribute result [$$36]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$36])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$36] <- [{"fbu-ID": $$38, "fbm-auth-ID": $$message.getField(2), "uname": $$42, "message": $$message.getField(6)}]
       -- ASSIGN  |PARTITIONED|
+        select (eq($$38, $$message.getField(3)))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$38, $$42, $$message])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- BTREE_SEARCH (test.FacebookMessages.FacebookMessages)  |PARTITIONED|
+              unnest-map [$$39, $$message] <- index-search("FacebookMessages", 0, "test", "FacebookMessages", true, false, 1, $$49, 1, $$49, true, true, true)
+              -- BTREE_SEARCH  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  order (ASC, $$49)
                   -- STABLE_SORT [$$49(ASC)]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$38, $$42, $$49])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (test.FacebookMessages.fbmIdxAutId)  |PARTITIONED|
+                          unnest-map [$$48, $$49] <- index-search("fbmIdxAutId", 0, "test", "FacebookMessages", true, true, 1, $$38, 1, $$38, true, true, true)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                              project ([$$38, $$42])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$42] <- [$$user.getField(3)]
                                 -- ASSIGN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- BTREE_SEARCH (test.FacebookUsers.FacebookUsers)  |PARTITIONED|
+                                    unnest-map [$$38, $$user] <- index-search("FacebookUsers", 0, "test", "FacebookUsers", false, false, 1, $$44, 1, $$45, true, true, false)
+                                    -- BTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        assign [$$44, $$45] <- [11000, 12000]
                                         -- ASSIGN  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/secondary-equi-join_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/secondary-equi-join_02.plan
index fc29b18..a913401 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/secondary-equi-join_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/secondary-equi-join_02.plan
@@ -1,22 +1,44 @@
+distribute result [$$27]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$27])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$27] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$30, $$b.getField(2)))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$a, $$30, $$b])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- BTREE_SEARCH (test.CSX.CSX)  |PARTITIONED|
+                unnest-map [$$29, $$b] <- index-search("CSX", 0, "test", "CSX", true, false, 1, $$33, 1, $$33, true, true, true)
+                -- BTREE_SEARCH  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    order (ASC, $$33)
                     -- STABLE_SORT [$$33(ASC)]  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$a, $$30, $$33])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.CSX.title_index)  |PARTITIONED|
+                            unnest-map [$$32, $$33] <- index-search("title_index", 0, "test", "CSX", true, true, 1, $$30, 1, $$30, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                assign [$$30] <- [$$a.getField(2)]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$a])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                      data-scan []<-[$$28, $$a] <- test.DBLP
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/secondary-equi-join_03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/secondary-equi-join_03.plan
index 69bcc80..e156924 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/secondary-equi-join_03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/secondary-equi-join_03.plan
@@ -1,22 +1,44 @@
+distribute result [$$27]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$27])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$27] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$30, $$b.getField(2)))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$a, $$30, $$b])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                unnest-map [$$29, $$b] <- index-search("DBLP", 0, "test", "DBLP", true, false, 1, $$33, 1, $$33, true, true, true)
+                -- BTREE_SEARCH  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    order (ASC, $$33)
                     -- STABLE_SORT [$$33(ASC)]  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$a, $$30, $$33])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.DBLP.title_index)  |PARTITIONED|
+                            unnest-map [$$32, $$33] <- index-search("title_index", 0, "test", "DBLP", true, true, 1, $$30, 1, $$30, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                assign [$$30] <- [$$a.getField(2)]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$a])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                      data-scan []<-[$$28, $$a] <- test.DBLP
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/secondary-equi-join_04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/secondary-equi-join_04.plan
index f730221..7a20b44 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/secondary-equi-join_04.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/secondary-equi-join_04.plan
@@ -1,33 +1,66 @@
+distribute result [$$41]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$41])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$41] <- [{"a": $$a, "b": $$b, "c": $$c}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b, $$c])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$42, $$c.getField(1)))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$a, $$b, $$42, $$c])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- BTREE_SEARCH (test.testdst3.testdst3)  |PARTITIONED|
+                unnest-map [$$45, $$c] <- index-search("testdst3", 0, "test", "testdst3", true, false, 1, $$49, 1, $$49, true, true, true)
+                -- BTREE_SEARCH  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    order (ASC, $$49)
                     -- STABLE_SORT [$$49(ASC)]  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$a, $$b, $$42, $$49])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.testdst3.sec3_Idx)  |PARTITIONED|
+                            unnest-map [$$48, $$49] <- index-search("sec3_Idx", 0, "test", "testdst3", true, true, 1, $$42, 1, $$42, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                project ([$$a, $$b, $$42])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    join (eq($$46, $$42))
                                     -- HYBRID_HASH_JOIN [$$46][$$42]  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$46]  |PARTITIONED|
+                                        assign [$$46] <- [$$a.getField(1)]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$a])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+                                              data-scan []<-[$$43, $$a] <- test.testdst
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$42]  |PARTITIONED|
+                                        assign [$$42] <- [$$b.getField(1)]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$b])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.testdst2)  |PARTITIONED|
+                                              data-scan []<-[$$44, $$b] <- test.testdst2
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/secondary-equi-join_05.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/secondary-equi-join_05.plan
index f642053..0f7f77e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/secondary-equi-join_05.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/secondary-equi-join_05.plan
@@ -1,18 +1,36 @@
+distribute result [$$26]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$26])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$26] <- [{"bar": $$bar, "testdst": $$testdst}]
       -- ASSIGN  |PARTITIONED|
+        select (eq($$bar, $$testdst.getField(1)))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$bar, $$testdst])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+              unnest-map [$$27, $$testdst] <- index-search("testdst", 0, "test", "testdst", true, false, 1, $$31, 1, $$31, true, true, true)
+              -- BTREE_SEARCH  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  order (ASC, $$31)
                   -- STABLE_SORT [$$31(ASC)]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$bar, $$31])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                          unnest-map [$$30, $$31] <- index-search("sec_Idx", 0, "test", "testdst", true, true, 1, $$32, 1, $$32, true, true, true)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                              assign [$$32] <- [cast-lax($$bar)]
                               -- ASSIGN  |UNPARTITIONED|
+                                unnest $$bar <- scan-collection(array: [ 1, 2, 3 ])
                                 -- UNNEST  |UNPARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/secondary-equi-join_06.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/secondary-equi-join_06.plan
index f04f6a0..b9d8d69 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/secondary-equi-join_06.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-join/secondary-equi-join_06.plan
@@ -1,38 +1,70 @@
+distribute result [$$70]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$70])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$70] <- [{"bar": $$63, "testdst2": $$testdst2}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$63, $$testdst2])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$val, $$testdst2.getField(1)))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$63, $$val, $$testdst2])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- BTREE_SEARCH (test.testdst2.testdst2)  |PARTITIONED|
+                unnest-map [$$73, $$testdst2] <- index-search("testdst2", 0, "test", "testdst2", true, false, 1, $$80, 1, $$80, true, true, true)
+                -- BTREE_SEARCH  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    order (ASC, $$80)
                     -- STABLE_SORT [$$80(ASC)]  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$63, $$val, $$80])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.testdst2.sec_Idx)  |PARTITIONED|
+                            unnest-map [$$79, $$80] <- index-search("sec_Idx", 0, "test", "testdst2", true, true, 1, $$val, 1, $$val, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                project ([$$val, $$63])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  assign [$$63] <- [{"val": $$val, "$1": $$76}]
                                   -- ASSIGN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- SORT_GROUP_BY[$$78]  |PARTITIONED|
-                                              {
+                                      group by ([$$val := $$78]) decor ([]) {
+                                                aggregate [$$76] <- [agg-sql-sum($$77)]
                                                 -- AGGREGATE  |LOCAL|
+                                                  nested tuple source
                                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                              }
+                                             }
+                                      -- SORT_GROUP_BY[$$78]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$78]  |PARTITIONED|
-                                          -- SORT_GROUP_BY[$$71]  |PARTITIONED|
-                                                  {
+                                          group by ([$$78 := $$71]) decor ([]) {
+                                                    aggregate [$$77] <- [agg-sql-count(1)]
                                                     -- AGGREGATE  |LOCAL|
+                                                      nested tuple source
                                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                  }
+                                                 }
+                                          -- SORT_GROUP_BY[$$71]  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$71])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$71] <- [$$testdst.getField(1)]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  project ([$$testdst])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+                                                      data-scan []<-[$$72, $$testdst] <- test.testdst
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/btree-index-composite-key-04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/btree-index-composite-key-04.plan
index f560061..124cdc1 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/btree-index-composite-key-04.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/btree-index-composite-key-04.plan
@@ -1,31 +1,62 @@
+distribute result [$$18]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$18])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$18] <- [{"id": $$21, "fname": $$20, "lname": $$24}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$21(ASC) ]  |PARTITIONED|
+          order (ASC, $$21)
           -- STABLE_SORT [$$21(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              union ($$35, $$29, $$21) ($$37, $$27, $$20) ($$38, $$28, $$24)
               -- UNION_ALL  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$35, $$37, $$38])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    select (eq($$37, "A"))
                     -- STREAM_SELECT  |PARTITIONED|
+                      project ([$$35, $$38, $$37])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$38, $$37] <- [$$36.getField(2), $$36.getField(1)]
                         -- ASSIGN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.employee.employee)  |PARTITIONED|
+                            unnest-map [$$35, $$36] <- index-search("employee", 0, "test", "employee", false, false, 1, $$29, 1, $$29, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                split ($$30)
                                 -- SPLIT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- BTREE_SEARCH (test.employee.idx_employee_f_l_name)  |PARTITIONED|
+                                    unnest-map [$$27, $$28, $$29, $$30] <- index-search("idx_employee_f_l_name", 0, "test", "employee", false, false, 1, $$25, 1, $$26, true, true, true)
+                                    -- BTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        assign [$$25, $$26] <- ["A", "A"]
                                         -- ASSIGN  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$29, $$27, $$28])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      split ($$30)
                       -- SPLIT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (test.employee.idx_employee_f_l_name)  |PARTITIONED|
+                          unnest-map [$$27, $$28, $$29, $$30] <- index-search("idx_employee_f_l_name", 0, "test", "employee", false, false, 1, $$25, 1, $$26, true, true, true)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              assign [$$25, $$26] <- ["A", "A"]
                               -- ASSIGN  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-01.plan
index a3d4489..a9d10e4 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-01.plan
@@ -1,12 +1,24 @@
+distribute result [$$56]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$56])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$56] <- [{"id": $$59, "x": $$70, "y": int64-default-null($$62)}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$59(ASC) ]  |PARTITIONED|
+          select (le($$70, 1))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$59, $$70, $$62])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$70, $$62] <- [int64-default-null($$ds1.getField("x")), $$ds1.getField("y")]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.ds1)  |PARTITIONED|
+                  data-scan []<-[$$59, $$ds1] <- test.ds1
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-02.plan
index 09d5382..0e2707a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-02.plan
@@ -1,19 +1,38 @@
+distribute result [$$56]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$56])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$56] <- [{"id": $$59, "x": $$73, "y": int64-default-null($$62)}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$59(ASC) ]  |PARTITIONED|
+          select (le($$73, 1))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$59, $$73, $$62])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$73, $$62] <- [int64-default-null($$ds2.getField("x")), $$ds2.getField("y")]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.ds2.ds2)  |PARTITIONED|
+                  unnest-map [$$59, $$ds2] <- index-search("ds2", 0, "test", "ds2", false, false, 1, $$72, 1, $$72, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$72)
                       -- STABLE_SORT [$$72(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$72])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.ds2.idx2)  |PARTITIONED|
+                              unnest-map [$$71, $$72] <- index-search("idx2", 0, "test", "ds2", false, false, 0, 1, $$70, true, true, false)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$70] <- [1]
                                   -- ASSIGN  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-03.plan
index 40e63cb..8af256f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-03.plan
@@ -1,12 +1,24 @@
+distribute result [$$56]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$56])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$56] <- [{"id": $$59, "x": $$70, "y": int64-default-null($$62)}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$59(ASC) ]  |PARTITIONED|
+          select (le($$70, "1"))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$59, $$70, $$62])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$70, $$62] <- [string-default-null($$ds3.getField("x")), $$ds3.getField("y")]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.ds3)  |PARTITIONED|
+                  data-scan []<-[$$59, $$ds3] <- test.ds3
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-04.plan
index 3582cf3..3b308db 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-04.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-04.plan
@@ -1,12 +1,24 @@
+distribute result [$$18]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$18])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$18] <- [{"id": $$21, "x": $$20, "y": $$24}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$21(ASC) ]  |PARTITIONED|
+          select (le($$20, 1))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$21, $$24, $$20])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$24, $$20] <- [$$ds3.getField("y"), $$ds3.getField("x")]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.ds3)  |PARTITIONED|
+                  data-scan []<-[$$21, $$ds3] <- test.ds3
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                      empty-tuple-source
+                      -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-05.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-05.plan
index 1c9845f..74fd378 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-05.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-05.plan
@@ -1,27 +1,54 @@
+distribute result [$$121]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$121])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$121] <- [{"v4x": $$122, "v2x": $$123}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$122(ASC), $$123(ASC) ]  |PARTITIONED|
+          order (ASC, $$122) (ASC, $$123)
           -- STABLE_SORT [$$122(ASC), $$123(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              select (eq($$122, $$123))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$122, $$123])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$123] <- [int64-default-null($$ds2.getField("x"))]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$122, $$ds2])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.ds2.ds2)  |PARTITIONED|
+                        unnest-map [$$125, $$ds2] <- index-search("ds2", 0, "test", "ds2", true, false, 1, $$139, 1, $$139, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$139)
                             -- STABLE_SORT [$$139(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$122, $$139])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- BTREE_SEARCH (test.ds2.idx2)  |PARTITIONED|
+                                    unnest-map [$$138, $$139] <- index-search("idx2", 0, "test", "ds2", true, true, 1, $$122, 1, $$122, true, true, true)
+                                    -- BTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                        project ([$$122])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$122] <- [int64-default-null($$ds4.getField("x"))]
                                           -- ASSIGN  |PARTITIONED|
+                                            project ([$$ds4])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- DATASOURCE_SCAN (test.ds4)  |PARTITIONED|
+                                                data-scan []<-[$$124, $$ds4] <- test.ds4
+                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-06.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-06.plan
index 510ccca..1c4e351 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-06.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-06.plan
@@ -1,24 +1,48 @@
+distribute result [$$121]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$121])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$121] <- [{"v4x": $$122, "v3x": $$123}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$122(ASC), $$123(ASC) ]  |PARTITIONED|
+          order (ASC, $$122) (ASC, $$123)
           -- STABLE_SORT [$$122(ASC), $$123(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              join (eq($$122, $$123))
               -- HYBRID_HASH_JOIN [$$122][$$123]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$122]  |PARTITIONED|
+                  project ([$$122])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$122] <- [int64-default-null($$ds4.getField("x"))]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$ds4])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (test.ds4)  |PARTITIONED|
+                          data-scan []<-[$$124, $$ds4] <- test.ds4
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$123]  |PARTITIONED|
+                  project ([$$123])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$123] <- [string-default-null($$ds3.getField("x"))]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$ds3])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (test.ds3)  |PARTITIONED|
+                          data-scan []<-[$$125, $$ds3] <- test.ds3
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                              empty-tuple-source
+                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-07.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-07.plan
index 1577585..293232e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-07.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-07.plan
@@ -1,24 +1,48 @@
+distribute result [$$121]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$121])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$121] <- [{"v4x": $$122, "v1x": $$123}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$122(ASC), $$123(ASC) ]  |PARTITIONED|
+          order (ASC, $$122) (ASC, $$123)
           -- STABLE_SORT [$$122(ASC), $$123(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              join (eq($$122, $$123))
               -- HYBRID_HASH_JOIN [$$122][$$123]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$122]  |PARTITIONED|
+                  project ([$$122])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$122] <- [int64-default-null($$ds4.getField("x"))]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$ds4])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (test.ds4)  |PARTITIONED|
+                          data-scan []<-[$$124, $$ds4] <- test.ds4
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$123]  |PARTITIONED|
+                  project ([$$123])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$123] <- [int64-default-null($$ds1.getField("x"))]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$ds1])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (test.ds1)  |PARTITIONED|
+                          data-scan []<-[$$125, $$ds1] <- test.ds1
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                              empty-tuple-source
+                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-08.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-08.plan
index 1577585..293232e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-08.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-08.plan
@@ -1,24 +1,48 @@
+distribute result [$$121]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$121])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$121] <- [{"v4x": $$122, "v1x": $$123}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$122(ASC), $$123(ASC) ]  |PARTITIONED|
+          order (ASC, $$122) (ASC, $$123)
           -- STABLE_SORT [$$122(ASC), $$123(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              join (eq($$122, $$123))
               -- HYBRID_HASH_JOIN [$$122][$$123]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$122]  |PARTITIONED|
+                  project ([$$122])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$122] <- [int64-default-null($$ds4.getField("x"))]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$ds4])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (test.ds4)  |PARTITIONED|
+                          data-scan []<-[$$124, $$ds4] <- test.ds4
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$123]  |PARTITIONED|
+                  project ([$$123])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$123] <- [int64-default-null($$ds1.getField("x"))]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$ds1])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (test.ds1)  |PARTITIONED|
+                          data-scan []<-[$$125, $$ds1] <- test.ds1
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                              empty-tuple-source
+                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-09.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-09.plan
index d60ee1e..faaf42d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-09.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-09.plan
@@ -1,24 +1,48 @@
+distribute result [$$83]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$83])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$83] <- [{"v4x": $$84, "ds2x": $$85}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$84(ASC), $$85(ASC) ]  |PARTITIONED|
+          order (ASC, $$84) (ASC, $$85)
           -- STABLE_SORT [$$84(ASC), $$85(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              join (eq($$84, $$85))
               -- HYBRID_HASH_JOIN [$$84][$$85]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$84]  |PARTITIONED|
+                  project ([$$84])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$84] <- [int64-default-null($$ds4.getField("x"))]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$ds4])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (test.ds4)  |PARTITIONED|
+                          data-scan []<-[$$86, $$ds4] <- test.ds4
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$85]  |PARTITIONED|
+                  project ([$$85])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$85] <- [$$ds2.getField("x")]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$ds2])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (test.ds2)  |PARTITIONED|
+                          data-scan []<-[$$87, $$ds2] <- test.ds2
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                              empty-tuple-source
+                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-10.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-10.plan
index 9e39687..510032a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-10.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-10.plan
@@ -1,19 +1,38 @@
+distribute result [$$42]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$42])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$42] <- [{"id": $$48, "f_dt_fmt": $$60}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$48(ASC) ]  |PARTITIONED|
+          select (lt($$60, datetime: { 2020-12-20T00:00:00.000 }))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$48, $$60])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$60] <- [datetime-default-null($$ds5.getField("f_dt_fmt"), "MM/DD/YYYY hh:mm:ss.nnna")]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.ds5.ds5)  |PARTITIONED|
+                  unnest-map [$$48, $$ds5] <- index-search("ds5", 0, "test", "ds5", false, false, 1, $$59, 1, $$59, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$59)
                       -- STABLE_SORT [$$59(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$59])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.ds5.idx5_dt_fmt)  |PARTITIONED|
+                              unnest-map [$$58, $$59] <- index-search("idx5_dt_fmt", 0, "test", "ds5", false, false, 0, 1, $$57, true, false, false)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$57] <- [datetime: { 2020-12-20T00:00:00.000 }]
                                   -- ASSIGN  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-11.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-11.plan
index 505a834..f430938 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-11.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-11.plan
@@ -1,19 +1,38 @@
+distribute result [$$42]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$42])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$42] <- [{"id": $$48, "f_d_fmt": $$60}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$48(ASC) ]  |PARTITIONED|
+          select (lt($$60, date: { 2020-12-20 }))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$48, $$60])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$60] <- [date-default-null($$ds5.getField("f_d_fmt"), "MM/DD/YYYY")]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.ds5.ds5)  |PARTITIONED|
+                  unnest-map [$$48, $$ds5] <- index-search("ds5", 0, "test", "ds5", false, false, 1, $$59, 1, $$59, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$59)
                       -- STABLE_SORT [$$59(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$59])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.ds5.idx5_d_fmt)  |PARTITIONED|
+                              unnest-map [$$58, $$59] <- index-search("idx5_d_fmt", 0, "test", "ds5", false, false, 0, 1, $$57, true, false, false)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$57] <- [date: { 2020-12-20 }]
                                   -- ASSIGN  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-12.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-12.plan
index 11a2618..32d4ee0 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-12.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-12.plan
@@ -1,19 +1,38 @@
+distribute result [$$42]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$42])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$42] <- [{"id": $$48, "f_t_fmt": $$60}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$48(ASC) ]  |PARTITIONED|
+          select (lt($$60, time: { 18:13:03.000 }))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$48, $$60])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$60] <- [time-default-null($$ds5.getField("f_t_fmt"), "hh:mm:ss.nnna")]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.ds5.ds5)  |PARTITIONED|
+                  unnest-map [$$48, $$ds5] <- index-search("ds5", 0, "test", "ds5", false, false, 1, $$59, 1, $$59, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$59)
                       -- STABLE_SORT [$$59(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$59])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.ds5.idx5_t_fmt)  |PARTITIONED|
+                              unnest-map [$$58, $$59] <- index-search("idx5_t_fmt", 0, "test", "ds5", false, false, 0, 1, $$57, true, false, false)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$57] <- [time: { 18:13:03.000 }]
                                   -- ASSIGN  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-13.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-13.plan
index 7736d99..3fbb87b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-13.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-13.plan
@@ -1,19 +1,38 @@
+distribute result [$$42]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$42])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$42] <- [{"id": $$48, "f_dt": $$60}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$48(ASC) ]  |PARTITIONED|
+          select (lt($$60, datetime: { 2020-12-20T00:00:00.000 }))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$48, $$60])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$60] <- [datetime-default-null($$ds6.getField("f_dt"))]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.ds6.ds6)  |PARTITIONED|
+                  unnest-map [$$48, $$ds6] <- index-search("ds6", 0, "test", "ds6", false, false, 1, $$59, 1, $$59, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$59)
                       -- STABLE_SORT [$$59(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$59])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.ds6.idx6_dt)  |PARTITIONED|
+                              unnest-map [$$58, $$59] <- index-search("idx6_dt", 0, "test", "ds6", false, false, 0, 1, $$57, true, false, false)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$57] <- [datetime: { 2020-12-20T00:00:00.000 }]
                                   -- ASSIGN  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-14.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-14.plan
index d9444e7..4903586 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-14.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-14.plan
@@ -1,19 +1,38 @@
+distribute result [$$42]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$42])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$42] <- [{"id": $$48, "f_d": $$60}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$48(ASC) ]  |PARTITIONED|
+          select (lt($$60, date: { 2020-12-20 }))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$48, $$60])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$60] <- [date-default-null($$ds6.getField("f_d"))]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.ds6.ds6)  |PARTITIONED|
+                  unnest-map [$$48, $$ds6] <- index-search("ds6", 0, "test", "ds6", false, false, 1, $$59, 1, $$59, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$59)
                       -- STABLE_SORT [$$59(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$59])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.ds6.idx6_d)  |PARTITIONED|
+                              unnest-map [$$58, $$59] <- index-search("idx6_d", 0, "test", "ds6", false, false, 0, 1, $$57, true, false, false)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$57] <- [date: { 2020-12-20 }]
                                   -- ASSIGN  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-15.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-15.plan
index e4b5cd7..911212d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-15.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-15.plan
@@ -1,19 +1,38 @@
+distribute result [$$42]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$42])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$42] <- [{"id": $$48, "f_t": $$60}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$48(ASC) ]  |PARTITIONED|
+          select (lt($$60, time: { 18:13:03.000 }))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$48, $$60])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$60] <- [time-default-null($$ds6.getField("f_t"))]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.ds6.ds6)  |PARTITIONED|
+                  unnest-map [$$48, $$ds6] <- index-search("ds6", 0, "test", "ds6", false, false, 1, $$59, 1, $$59, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$59)
                       -- STABLE_SORT [$$59(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$59])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.ds6.idx6_t)  |PARTITIONED|
+                              unnest-map [$$58, $$59] <- index-search("idx6_t", 0, "test", "ds6", false, false, 0, 1, $$57, true, false, false)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$57] <- [time: { 18:13:03.000 }]
                                   -- ASSIGN  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-16.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-16.plan
index 753d23d..d796360 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-16.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-16.plan
@@ -1,12 +1,24 @@
+distribute result [$$42]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$42])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$42] <- [{"id": $$48, "f_dt_fmt": $$57}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$48(ASC) ]  |PARTITIONED|
+          select (lt($$57, datetime: { 2020-12-20T00:00:00.000 }))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$48, $$57])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$57] <- [datetime-default-null($$ds5.getField("f_dt_fmt"), "MM-DD-YYYY hh:mm:ss.nnna")]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.ds5)  |PARTITIONED|
+                  data-scan []<-[$$48, $$ds5] <- test.ds5
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-17.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-17.plan
index f6647d4..ee97f2a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-17.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-17.plan
@@ -1,12 +1,24 @@
+distribute result [$$42]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$42])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$42] <- [{"id": $$48, "f_d": $$57}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$48(ASC) ]  |PARTITIONED|
+          select (lt($$57, date: { 2020-12-20 }))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$48, $$57])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$57] <- [date-default-null($$ds6.getField("f_d"))]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.ds6)  |PARTITIONED|
+                  data-scan []<-[$$48, $$ds6] <- test.ds6
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-18.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-18.plan
index 753d23d..7e4f90a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-18.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-18.plan
@@ -1,12 +1,24 @@
+distribute result [$$42]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$42])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$42] <- [{"id": $$48, "f_t_fmt": $$57}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$48(ASC) ]  |PARTITIONED|
+          select (lt($$57, time: { 18:13:03.000 }))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$48, $$57])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$57] <- [time-default-null($$ds5.getField("f_t_fmt"), "hh:mm:ss.nnna")]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.ds5)  |PARTITIONED|
+                  data-scan []<-[$$48, $$ds5] <- test.ds5
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-19.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-19.plan
index 2327f39..f156770 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-19.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-19.plan
@@ -1,27 +1,54 @@
+distribute result [$$109]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$109])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$109] <- [{"v6f_dt": $$110, "v5f_dt_fmt": $$111}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$110(ASC), $$111(ASC) ]  |PARTITIONED|
+          order (ASC, $$110) (ASC, $$111)
           -- STABLE_SORT [$$110(ASC), $$111(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              select (eq($$110, $$111))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$110, $$111])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$111] <- [datetime-default-null($$ds5.getField("f_dt_fmt"), "MM/DD/YYYY hh:mm:ss.nnna")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$110, $$ds5])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.ds5.ds5)  |PARTITIONED|
+                        unnest-map [$$113, $$ds5] <- index-search("ds5", 0, "test", "ds5", true, false, 1, $$123, 1, $$123, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$123)
                             -- STABLE_SORT [$$123(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$110, $$123])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- BTREE_SEARCH (test.ds5.idx5_dt_fmt)  |PARTITIONED|
+                                    unnest-map [$$122, $$123] <- index-search("idx5_dt_fmt", 0, "test", "ds5", true, true, 1, $$110, 1, $$110, true, true, true)
+                                    -- BTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                        project ([$$110])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$110] <- [datetime-default-null($$ds6.getField("f_dt"))]
                                           -- ASSIGN  |PARTITIONED|
+                                            project ([$$ds6])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- DATASOURCE_SCAN (test.ds6)  |PARTITIONED|
+                                                data-scan []<-[$$112, $$ds6] <- test.ds6
+                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-20.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-20.plan
index d71b03a..7cf933b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-20.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-20.plan
@@ -1,19 +1,38 @@
+distribute result [$$55]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$55])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$55] <- [{"id": $$58, "s_f2": $$71}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$58(ASC) ]  |PARTITIONED|
+          select (lt($$71, "4"))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$58, $$71])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$71] <- [string-default-null($$ds7.getField(2))]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.ds7.ds7)  |PARTITIONED|
+                  unnest-map [$$58, $$ds7] <- index-search("ds7", 0, "test", "ds7", false, false, 1, $$70, 1, $$70, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$70)
                       -- STABLE_SORT [$$70(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$70])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.ds7.idx2)  |PARTITIONED|
+                              unnest-map [$$69, $$70] <- index-search("idx2", 0, "test", "ds7", false, false, 0, 1, $$68, true, false, false)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$68] <- ["4"]
                                   -- ASSIGN  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-21.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-21.plan
index e5fd2d4..a150acf 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-21.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-21.plan
@@ -1,12 +1,24 @@
+distribute result [$$55]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$55])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$55] <- [{"id": $$58, "s_f2": $$68}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$58(ASC) ]  |PARTITIONED|
+          select (lt($$68, 4))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$58, $$68])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$68] <- [string-default-null($$ds7.getField(2))]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.ds7)  |PARTITIONED|
+                  data-scan []<-[$$58, $$ds7] <- test.ds7
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-22.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-22.plan
index e5fd2d4..5d102ca 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-22.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-22.plan
@@ -1,12 +1,24 @@
+distribute result [$$55]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$55])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$55] <- [{"id": $$58, "s_f2": $$68}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$58(ASC) ]  |PARTITIONED|
+          select (lt($$68, "4"))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$58, $$68])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$68] <- [int64-default-null($$ds7.getField(2))]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.ds7)  |PARTITIONED|
+                  data-scan []<-[$$58, $$ds7] <- test.ds7
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-23.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-23.plan
index 5972aae..cfa24e6 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-23.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-23.plan
@@ -1,19 +1,38 @@
+distribute result [$$55]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$55])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$55] <- [{"id": $$58, "s_f2": $$71}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$58(ASC) ]  |PARTITIONED|
+          select (lt($$71, 4))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$58, $$71])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$71] <- [int64-default-null($$ds7.getField(2))]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.ds7.ds7)  |PARTITIONED|
+                  unnest-map [$$58, $$ds7] <- index-search("ds7", 0, "test", "ds7", false, false, 1, $$70, 1, $$70, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$70)
                       -- STABLE_SORT [$$70(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$70])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.ds7.idx3)  |PARTITIONED|
+                              unnest-map [$$69, $$70] <- index-search("idx3", 0, "test", "ds7", false, false, 0, 1, $$68, true, true, false)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$68] <- [4]
                                   -- ASSIGN  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-24.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-24.plan
index 85d3144..5d8a9d7 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-24.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-24.plan
@@ -1,19 +1,38 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$17] <- [{"id": $$20, "s_f2": $$19}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$20(ASC) ]  |PARTITIONED|
+          select (lt($$19, "4"))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$20, $$19])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$19] <- [$$ds7.getField(2)]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.ds7.ds7)  |PARTITIONED|
+                  unnest-map [$$20, $$ds7] <- index-search("ds7", 0, "test", "ds7", false, false, 1, $$25, 1, $$25, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$25)
                       -- STABLE_SORT [$$25(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$25])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.ds7.idx1)  |PARTITIONED|
+                              unnest-map [$$24, $$25] <- index-search("idx1", 0, "test", "ds7", false, false, 0, 1, $$23, true, false, false)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$23] <- ["4"]
                                   -- ASSIGN  |PARTITIONED|
-                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                    empty-tuple-source
+                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-25.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-25.plan
index d71b03a..5383bea 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-25.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/cast-default-null/cast-default-null-25.plan
@@ -1,19 +1,38 @@
+distribute result [$$55]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$55])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$55] <- [{"id": $$58, "s_f2": $$60}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$58(ASC) ]  |PARTITIONED|
+          select (lt($$60, "4"))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$58, $$60])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$60] <- [$$ds7.getField(2)]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.ds7.ds7)  |PARTITIONED|
+                  unnest-map [$$58, $$ds7] <- index-search("ds7", 0, "test", "ds7", false, false, 1, $$70, 1, $$70, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$70)
                       -- STABLE_SORT [$$70(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$70])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.ds7.idx2)  |PARTITIONED|
+                              unnest-map [$$69, $$70] <- index-search("idx2", 0, "test", "ds7", false, false, 0, 1, $$68, true, false, false)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$68] <- ["4"]
                                   -- ASSIGN  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/disjunctive-predicate/disjunctive-predicate-1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/disjunctive-predicate/disjunctive-predicate-1.plan
index aae34f1..4e5845f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/disjunctive-predicate/disjunctive-predicate-1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/disjunctive-predicate/disjunctive-predicate-1.plan
@@ -1,10 +1,20 @@
+distribute result [$$x]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$x])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-        -- BTREE_SEARCH (test.TestSet.TestSet)  |PARTITIONED|
+        unnest-map [$$20, $$x] <- index-search("TestSet", 0, "test", "TestSet", true, true, 1, $$21, 1, $$21, true, true, true)
+        -- BTREE_SEARCH  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            order (ASC, $$21)
             -- STABLE_SORT [$$21(ASC)]  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$21]  |PARTITIONED|
+                unnest $$21 <- scan-collection(array: [ "one", "two" ])
                 -- UNNEST  |UNPARTITIONED|
+                  empty-tuple-source
                   -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/disjunctive-predicate/disjunctive-predicate-2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/disjunctive-predicate/disjunctive-predicate-2.plan
index 7f726b6..784a3b2 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/disjunctive-predicate/disjunctive-predicate-2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/disjunctive-predicate/disjunctive-predicate-2.plan
@@ -1,16 +1,32 @@
+distribute result [$$x]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$x])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (eq($$21, $$x.getField(1)))
       -- STREAM_SELECT  |PARTITIONED|
+        project ([$$21, $$x])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- BTREE_SEARCH (test.TestSet.TestSet)  |PARTITIONED|
+            unnest-map [$$20, $$x] <- index-search("TestSet", 0, "test", "TestSet", true, false, 1, $$23, 1, $$23, true, true, true)
+            -- BTREE_SEARCH  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (ASC, $$23)
                 -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$21, $$23])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.TestSet.TestSetIndex)  |PARTITIONED|
+                        unnest-map [$$22, $$23] <- index-search("TestSetIndex", 0, "test", "TestSet", true, true, 1, $$21, 1, $$21, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                            unnest $$21 <- scan-collection(array: [ "one", "two" ])
                             -- UNNEST  |UNPARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/disjunctive-predicate/disjunctive-predicate-3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/disjunctive-predicate/disjunctive-predicate-3.plan
index 318f7d5..8c71c9d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/disjunctive-predicate/disjunctive-predicate-3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/disjunctive-predicate/disjunctive-predicate-3.plan
@@ -1,15 +1,30 @@
+distribute result [$$x]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$x])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        join (eq($$21, $$19))
         -- HYBRID_HASH_JOIN [$$19][$$21]  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            assign [$$19] <- [$$x.getField(2)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$x])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.TestSet)  |PARTITIONED|
+                  data-scan []<-[$$20, $$x] <- test.TestSet
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+          exchange
           -- BROADCAST_EXCHANGE  |PARTITIONED|
+            unnest $$21 <- scan-collection(array: [ "one", "two" ])
             -- UNNEST  |UNPARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/disjunctive-predicate/disjunctive-predicate-4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/disjunctive-predicate/disjunctive-predicate-4.plan
index dcffc94..3ed1f2f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/disjunctive-predicate/disjunctive-predicate-4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/disjunctive-predicate/disjunctive-predicate-4.plan
@@ -1,11 +1,22 @@
+distribute result [$$x]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$x])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (or(eq($$19, "one"), $$22, $$22))
       -- STREAM_SELECT  |PARTITIONED|
+        assign [$$22] <- [eq($$19, "two")]
         -- ASSIGN  |PARTITIONED|
+          assign [$$19] <- [$$x.getField(1)]
           -- ASSIGN  |PARTITIONED|
+            project ([$$x])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.TestSet)  |PARTITIONED|
+                data-scan []<-[$$20, $$x] <- test.TestSet
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/disjunctive-predicate/disjunctive-predicate-5.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/disjunctive-predicate/disjunctive-predicate-5.plan
index 242b032..ca8da70 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/disjunctive-predicate/disjunctive-predicate-5.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/disjunctive-predicate/disjunctive-predicate-5.plan
@@ -1,12 +1,24 @@
+distribute result [$$x]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    limit 2
     -- STREAM_LIMIT  |UNPARTITIONED|
+      project ([$$x])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$20(ASC) ]  |PARTITIONED|
+          limit 2
           -- STREAM_LIMIT  |PARTITIONED|
+            project ([$$20, $$x])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$19] <- [$$x.getField(1)]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.TestSet)  |PARTITIONED|
+                  data-scan []<-[$$20, $$x] <- test.TestSet condition (or(eq($$x.getField(1), "one"), eq($$x.getField(1), "two"), eq($$x.getField(1), "two"))) limit 2
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/function-on-pk/function-on-pk-01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/function-on-pk/function-on-pk-01.plan
index f621777..9693f00 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/function-on-pk/function-on-pk-01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/function-on-pk/function-on-pk-01.plan
@@ -1,10 +1,20 @@
+distribute result [$$18]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$18])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$18] <- [{"a": $$ds1.getField(1), "b": $$ds1.getField(2)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$ds1])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq(numeric-add($$19, 1), 3))
           -- STREAM_SELECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- DATASOURCE_SCAN (test.ds1)  |PARTITIONED|
+              data-scan []<-[$$19, $$ds1] <- test.ds1
+              -- DATASOURCE_SCAN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                  empty-tuple-source
+                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/function-on-pk/function-on-pk-02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/function-on-pk/function-on-pk-02.plan
index f621777..cfb460b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/function-on-pk/function-on-pk-02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/function-on-pk/function-on-pk-02.plan
@@ -1,10 +1,20 @@
+distribute result [$$18]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$18])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$18] <- [{"a": $$ds1.getField(1), "b": $$ds1.getField(2)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$ds1])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq(3, numeric-add($$19, 1)))
           -- STREAM_SELECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- DATASOURCE_SCAN (test.ds1)  |PARTITIONED|
+              data-scan []<-[$$19, $$ds1] <- test.ds1
+              -- DATASOURCE_SCAN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                  empty-tuple-source
+                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-10.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-10.plan
index 7af465d..7b23753 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-10.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-10.plan
@@ -1,19 +1,38 @@
+distribute result [$$19]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$19(ASC) ]  |PARTITIONED|
+    order (ASC, $$19)
     -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$19])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$tenk.getField(7), 0))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$19] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                  unnest-map [$$17, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 1, $$24, 1, $$24, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$24)
                       -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$24])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.tenk.idx_1k_2k)  |PARTITIONED|
+                              unnest-map [$$22, $$23, $$24] <- index-search("idx_1k_2k", 0, "test", "tenk", false, false, 1, $$20, 1, $$21, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$20, $$21] <- [0, 0]
                                   -- ASSIGN  |PARTITIONED|
-                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                    empty-tuple-source
+                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-11.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-11.plan
index 51bb0f2..4d1a7c7 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-11.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-11.plan
@@ -1,18 +1,36 @@
+distribute result [$$23]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+    order (ASC, $$23)
     -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$23])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$22, $$20))
             -- HYBRID_HASH_JOIN [$$20][$$22]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$23, $$20])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$23, $$20] <- [$$tenk.getField(0), $$tenk.getField(7)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$tenk])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                        data-scan []<-[$$21, $$tenk] <- test.tenk
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                unnest $$22 <- scan-collection(array: [ 0, 1 ])
                 -- UNNEST  |UNPARTITIONED|
-                  -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
\ No newline at end of file
+                  empty-tuple-source
+                  -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-12.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-12.plan
index 55140ef..60d58ac 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-12.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-12.plan
@@ -1,20 +1,40 @@
+distribute result [$$23]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+    order (ASC, $$23)
     -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$23])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$22, $$tenk.getField(7)))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$23] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$22, $$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                  unnest-map [$$21, $$tenk] <- index-search("tenk", 0, "test", "tenk", true, false, 1, $$27, 1, $$27, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$27)
                       -- STABLE_SORT [$$27(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$22, $$27])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.tenk.idx_1k_2k)  |PARTITIONED|
+                              unnest-map [$$25, $$26, $$27] <- index-search("idx_1k_2k", 0, "test", "tenk", true, true, 1, $$28, 1, $$28, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                  assign [$$28] <- [cast-lax($$22)]
                                   -- ASSIGN  |UNPARTITIONED|
+                                    unnest $$22 <- scan-collection(array: [ 0, 1 ])
                                     -- UNNEST  |UNPARTITIONED|
-                                      -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
\ No newline at end of file
+                                      empty-tuple-source
+                                      -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-13.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-13.plan
index 102a5e7..1f1eeb2 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-13.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-13.plan
@@ -1,19 +1,38 @@
+distribute result [$$19]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$19(ASC) ]  |PARTITIONED|
+    order (ASC, $$19)
     -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$19])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$tenk.getField(7), 0))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$19] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                  unnest-map [$$17, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 1, $$23, 1, $$23, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$23)
                       -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$23])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.tenk.idx_1k)  |PARTITIONED|
+                              unnest-map [$$22, $$23] <- index-search("idx_1k", 0, "test", "tenk", false, false, 1, $$20, 1, $$21, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$20, $$21] <- [0, 0]
                                   -- ASSIGN  |PARTITIONED|
-                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                    empty-tuple-source
+                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-3.plan
index f958053..b4793ca 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-3.plan
@@ -1,12 +1,24 @@
+distribute result [$$19]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$19(ASC) ]  |PARTITIONED|
+    order (ASC, $$19)
     -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$19])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$tenk.getField(7), 0))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$19] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                  data-scan []<-[$$17, $$tenk] <- test.tenk
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                      empty-tuple-source
+                      -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-4.plan
index 7af465d..7b23753 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-4.plan
@@ -1,19 +1,38 @@
+distribute result [$$19]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$19(ASC) ]  |PARTITIONED|
+    order (ASC, $$19)
     -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$19])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$tenk.getField(7), 0))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$19] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                  unnest-map [$$17, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 1, $$24, 1, $$24, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$24)
                       -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$24])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.tenk.idx_1k_2k)  |PARTITIONED|
+                              unnest-map [$$22, $$23, $$24] <- index-search("idx_1k_2k", 0, "test", "tenk", false, false, 1, $$20, 1, $$21, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$20, $$21] <- [0, 0]
                                   -- ASSIGN  |PARTITIONED|
-                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                    empty-tuple-source
+                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-5.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-5.plan
index f958053..b4793ca 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-5.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-5.plan
@@ -1,12 +1,24 @@
+distribute result [$$19]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$19(ASC) ]  |PARTITIONED|
+    order (ASC, $$19)
     -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$19])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$tenk.getField(7), 0))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$19] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                  data-scan []<-[$$17, $$tenk] <- test.tenk
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                      empty-tuple-source
+                      -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-6.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-6.plan
index 5a83b61..dc675ba 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-6.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-6.plan
@@ -1,19 +1,38 @@
+distribute result [$$23]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+    order (ASC, $$23)
     -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$23])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and(eq($$tenk.getField(7), 0), eq($$tenk.getField(8), 0)))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$23] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                  unnest-map [$$20, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 1, $$27, 1, $$27, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$27)
                       -- STABLE_SORT [$$27(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$27])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.tenk.idx_2k)  |PARTITIONED|
+                              unnest-map [$$26, $$27] <- index-search("idx_2k", 0, "test", "tenk", false, false, 1, $$24, 1, $$25, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$24, $$25] <- [0, 0]
                                   -- ASSIGN  |PARTITIONED|
-                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                    empty-tuple-source
+                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-7.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-7.plan
index a84e5c8..058dfda 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-7.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-7.plan
@@ -1,30 +1,60 @@
+distribute result [$$23]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+    order (ASC, $$23)
     -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$23])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and(eq($$tenk.getField(7), 0), eq($$tenk.getField(8), 0)))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$23] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                  unnest-map [$$20, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 1, $$35, 1, $$35, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      intersect [$$35] <- [[$$30], [$$34]]
                       -- INTERSECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$30)
                           -- STABLE_SORT [$$30(ASC)]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$30])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.tenk.idx_1k_2k)  |PARTITIONED|
+                                  unnest-map [$$28, $$29, $$30] <- index-search("idx_1k_2k", 0, "test", "tenk", false, false, 2, $$24, $$25, 2, $$26, $$27, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      assign [$$24, $$25, $$26, $$27] <- [0, 0, 0, 0]
                                       -- ASSIGN  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$34)
                           -- STABLE_SORT [$$34(ASC)]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$34])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.tenk.idx_2k)  |PARTITIONED|
+                                  unnest-map [$$33, $$34] <- index-search("idx_2k", 0, "test", "tenk", false, false, 1, $$31, 1, $$32, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      assign [$$31, $$32] <- [0, 0]
                                       -- ASSIGN  |PARTITIONED|
-                                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                        empty-tuple-source
+                                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-8.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-8.plan
index 1d31f3b..a3f92bd 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-8.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-8.plan
@@ -1,19 +1,38 @@
+distribute result [$$23]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+    order (ASC, $$23)
     -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$23])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and(eq($$tenk.getField(7), 0), eq($$tenk.getField(8), 0)))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$23] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                  unnest-map [$$20, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 1, $$30, 1, $$30, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$30)
                       -- STABLE_SORT [$$30(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$30])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.tenk.idx_1k_2k)  |PARTITIONED|
+                              unnest-map [$$28, $$29, $$30] <- index-search("idx_1k_2k", 0, "test", "tenk", false, false, 2, $$24, $$25, 2, $$26, $$27, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$24, $$25, $$26, $$27] <- [0, 0, 0, 0]
                                   -- ASSIGN  |PARTITIONED|
-                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                    empty-tuple-source
+                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-9.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-9.plan
index 102a5e7..1f1eeb2 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-9.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-skip-index/hints-skip-index-9.plan
@@ -1,19 +1,38 @@
+distribute result [$$19]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$19(ASC) ]  |PARTITIONED|
+    order (ASC, $$19)
     -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$19])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$tenk.getField(7), 0))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$19] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                  unnest-map [$$17, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 1, $$23, 1, $$23, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$23)
                       -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$23])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.tenk.idx_1k)  |PARTITIONED|
+                              unnest-map [$$22, $$23] <- index-search("idx_1k", 0, "test", "tenk", false, false, 1, $$20, 1, $$21, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$20, $$21] <- [0, 0]
                                   -- ASSIGN  |PARTITIONED|
-                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                    empty-tuple-source
+                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-10.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-10.plan
index 102a5e7..1f1eeb2 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-10.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-10.plan
@@ -1,19 +1,38 @@
+distribute result [$$19]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$19(ASC) ]  |PARTITIONED|
+    order (ASC, $$19)
     -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$19])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$tenk.getField(7), 0))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$19] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                  unnest-map [$$17, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 1, $$23, 1, $$23, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$23)
                       -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$23])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.tenk.idx_1k)  |PARTITIONED|
+                              unnest-map [$$22, $$23] <- index-search("idx_1k", 0, "test", "tenk", false, false, 1, $$20, 1, $$21, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$20, $$21] <- [0, 0]
                                   -- ASSIGN  |PARTITIONED|
-                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                    empty-tuple-source
+                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-11.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-11.plan
index 7af465d..7b23753 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-11.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-11.plan
@@ -1,19 +1,38 @@
+distribute result [$$19]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$19(ASC) ]  |PARTITIONED|
+    order (ASC, $$19)
     -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$19])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$tenk.getField(7), 0))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$19] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                  unnest-map [$$17, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 1, $$24, 1, $$24, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$24)
                       -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$24])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.tenk.idx_1k_2k)  |PARTITIONED|
+                              unnest-map [$$22, $$23, $$24] <- index-search("idx_1k_2k", 0, "test", "tenk", false, false, 1, $$20, 1, $$21, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$20, $$21] <- [0, 0]
                                   -- ASSIGN  |PARTITIONED|
-                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                    empty-tuple-source
+                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-12.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-12.plan
index d68a5a1..5a1f5ad 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-12.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-12.plan
@@ -1,37 +1,74 @@
+distribute result [$$23]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+    order (ASC, $$23)
     -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$23])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and(eq($$tenk.getField(7), 0), eq($$tenk.getField(9), 0)))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$23] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                  unnest-map [$$20, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 1, $$34, 1, $$34, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      intersect [$$34] <- [[$$28], [$$33]]
                       -- INTERSECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$28)
                           -- STABLE_SORT [$$28(ASC)]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$28])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.tenk.idx_1k_2k)  |PARTITIONED|
+                                  unnest-map [$$26, $$27, $$28] <- index-search("idx_1k_2k", 0, "test", "tenk", false, false, 1, $$24, 1, $$25, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$24, $$25])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$24, $$25] <- [$$29, $$30]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$29, $$30] <- [0, 0]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$33)
                           -- STABLE_SORT [$$33(ASC)]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$33])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.tenk.idx_5k_10k)  |PARTITIONED|
+                                  unnest-map [$$31, $$32, $$33] <- index-search("idx_5k_10k", 0, "test", "tenk", false, false, 1, $$29, 1, $$30, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      replicate
                                       -- REPLICATE  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$29, $$30] <- [0, 0]
                                           -- ASSIGN  |PARTITIONED|
-                                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                            empty-tuple-source
+                                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-13.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-13.plan
index 102a5e7..1f1eeb2 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-13.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-13.plan
@@ -1,19 +1,38 @@
+distribute result [$$19]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$19(ASC) ]  |PARTITIONED|
+    order (ASC, $$19)
     -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$19])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$tenk.getField(7), 0))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$19] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                  unnest-map [$$17, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 1, $$23, 1, $$23, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$23)
                       -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$23])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.tenk.idx_1k)  |PARTITIONED|
+                              unnest-map [$$22, $$23] <- index-search("idx_1k", 0, "test", "tenk", false, false, 1, $$20, 1, $$21, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$20, $$21] <- [0, 0]
                                   -- ASSIGN  |PARTITIONED|
-                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                    empty-tuple-source
+                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-14.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-14.plan
index 8f99941..e1adaf9 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-14.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-14.plan
@@ -1,19 +1,38 @@
+distribute result [$$19]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$19(ASC) ]  |PARTITIONED|
+    order (ASC, $$19)
     -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$19])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$tenk.getField(8), 0))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$19] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                  unnest-map [$$17, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 1, $$23, 1, $$23, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$23)
                       -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$23])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.tenk.idx_2k)  |PARTITIONED|
+                              unnest-map [$$22, $$23] <- index-search("idx_2k", 0, "test", "tenk", false, false, 1, $$20, 1, $$21, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$20, $$21] <- [0, 0]
                                   -- ASSIGN  |PARTITIONED|
-                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                    empty-tuple-source
+                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-15.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-15.plan
index 5a83b61..dc675ba 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-15.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-15.plan
@@ -1,19 +1,38 @@
+distribute result [$$23]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+    order (ASC, $$23)
     -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$23])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and(eq($$tenk.getField(7), 0), eq($$tenk.getField(8), 0)))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$23] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                  unnest-map [$$20, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 1, $$27, 1, $$27, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$27)
                       -- STABLE_SORT [$$27(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$27])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.tenk.idx_2k)  |PARTITIONED|
+                              unnest-map [$$26, $$27] <- index-search("idx_2k", 0, "test", "tenk", false, false, 1, $$24, 1, $$25, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$24, $$25] <- [0, 0]
                                   -- ASSIGN  |PARTITIONED|
-                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                    empty-tuple-source
+                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-16.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-16.plan
index ce4ed8e..bfe5612 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-16.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-16.plan
@@ -1,37 +1,74 @@
+distribute result [$$23]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+    order (ASC, $$23)
     -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$23])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and(eq($$tenk.getField(7), 0), eq($$tenk.getField(8), 0)))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$23] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                  unnest-map [$$20, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 1, $$32, 1, $$32, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      intersect [$$32] <- [[$$27], [$$31]]
                       -- INTERSECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$27)
                           -- STABLE_SORT [$$27(ASC)]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$27])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.tenk.idx_1k)  |PARTITIONED|
+                                  unnest-map [$$26, $$27] <- index-search("idx_1k", 0, "test", "tenk", false, false, 1, $$24, 1, $$25, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$24, $$25])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$24, $$25] <- [$$28, $$29]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$28, $$29] <- [0, 0]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$31)
                           -- STABLE_SORT [$$31(ASC)]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$31])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.tenk.idx_2k)  |PARTITIONED|
+                                  unnest-map [$$30, $$31] <- index-search("idx_2k", 0, "test", "tenk", false, false, 1, $$28, 1, $$29, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      replicate
                                       -- REPLICATE  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$28, $$29] <- [0, 0]
                                           -- ASSIGN  |PARTITIONED|
-                                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                            empty-tuple-source
+                                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-17.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-17.plan
index f04dd37..e0b89e8 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-17.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-17.plan
@@ -1,19 +1,38 @@
+distribute result [$$23]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+    order (ASC, $$23)
     -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$23])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and(eq($$tenk.getField(7), 0), eq($$tenk.getField(8), 0)))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$23] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                  unnest-map [$$20, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 1, $$28, 1, $$28, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$28)
                       -- STABLE_SORT [$$28(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$28])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.tenk.idx_1k_2k)  |PARTITIONED|
+                              unnest-map [$$26, $$27, $$28] <- index-search("idx_1k_2k", 0, "test", "tenk", false, false, 1, $$24, 1, $$25, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$24, $$25] <- [0, 0]
                                   -- ASSIGN  |PARTITIONED|
-                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                    empty-tuple-source
+                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-18.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-18.plan
index 102a5e7..1f1eeb2 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-18.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-18.plan
@@ -1,19 +1,38 @@
+distribute result [$$19]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$19(ASC) ]  |PARTITIONED|
+    order (ASC, $$19)
     -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$19])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$tenk.getField(7), 0))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$19] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                  unnest-map [$$17, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 1, $$23, 1, $$23, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$23)
                       -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$23])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.tenk.idx_1k)  |PARTITIONED|
+                              unnest-map [$$22, $$23] <- index-search("idx_1k", 0, "test", "tenk", false, false, 1, $$20, 1, $$21, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$20, $$21] <- [0, 0]
                                   -- ASSIGN  |PARTITIONED|
-                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                    empty-tuple-source
+                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-19.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-19.plan
index 102a5e7..1f1eeb2 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-19.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-19.plan
@@ -1,19 +1,38 @@
+distribute result [$$19]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$19(ASC) ]  |PARTITIONED|
+    order (ASC, $$19)
     -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$19])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$tenk.getField(7), 0))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$19] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                  unnest-map [$$17, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 1, $$23, 1, $$23, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$23)
                       -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$23])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.tenk.idx_1k)  |PARTITIONED|
+                              unnest-map [$$22, $$23] <- index-search("idx_1k", 0, "test", "tenk", false, false, 1, $$20, 1, $$21, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$20, $$21] <- [0, 0]
                                   -- ASSIGN  |PARTITIONED|
-                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                    empty-tuple-source
+                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-20.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-20.plan
index c226460..63039a1 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-20.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-20.plan
@@ -1,28 +1,56 @@
+distribute result [$$47]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$47])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$47] <- [{"revenue": $$50}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$50] <- [agg-sql-sum($$52)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$52] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(ge($$48, "2016-01-01 00:00:00.000000"), lt($$48, "2017-01-01 00:00:00.000000")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$48])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$48] <- [$$ol.getField("ol_delivery_d")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$ol])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      unnest $$ol <- scan-collection($$51)
                       -- UNNEST  |PARTITIONED|
+                        project ([$$51])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$51] <- [$$o.getField("o_orderline")]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$o])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- BTREE_SEARCH (test.orders.orders)  |PARTITIONED|
+                                unnest-map [$$49, $$o] <- index-search("orders", 0, "test", "orders", false, false, 1, $$56, 1, $$56, true, true, true)
+                                -- BTREE_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    distinct ([$$56])
                                     -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        order (ASC, $$56)
                                         -- STABLE_SORT [$$56(ASC)]  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$56])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- BTREE_SEARCH (test.orders.orderline_delivery_d)  |PARTITIONED|
+                                                unnest-map [$$55, $$56] <- index-search("orderline_delivery_d", 0, "test", "orders", false, false, 1, $$53, 1, $$54, true, false, false)
+                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    assign [$$53, $$54] <- ["2016-01-01 00:00:00.000000", "2017-01-01 00:00:00.000000"]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-21.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-21.plan
index 5bde8ba..0ebd498 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-21.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-21.plan
@@ -1,28 +1,56 @@
+distribute result [$$47]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$47])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$47] <- [{"revenue": $$50}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$50] <- [agg-sql-sum($$52)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$52] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(ge($$48, "2016-01-01 00:00:00.000000"), lt($$48, "2017-01-01 00:00:00.000000")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$48])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$48] <- [$$ol.getField("ol_delivery_d")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$ol])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      unnest $$ol <- scan-collection($$51)
                       -- UNNEST  |PARTITIONED|
+                        project ([$$51])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$51] <- [$$o.getField("o_orderline")]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$o])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- BTREE_SEARCH (test.orders.orders)  |PARTITIONED|
+                                unnest-map [$$49, $$o] <- index-search("orders", 0, "test", "orders", false, false, 1, $$55, 1, $$55, true, true, true)
+                                -- BTREE_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    distinct ([$$55])
                                     -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        order (ASC, $$55)
                                         -- STABLE_SORT [$$55(ASC)]  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$55])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- BTREE_SEARCH (test.orders.orderline_delivery_d)  |PARTITIONED|
+                                                unnest-map [$$54, $$55] <- index-search("orderline_delivery_d", 0, "test", "orders", false, false, 1, $$53, 0, true, true, false)
+                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    assign [$$53] <- ["2016-01-01 00:00:00.000000"]
                                                     -- ASSIGN  |PARTITIONED|
-                                                      -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                                      empty-tuple-source
+                                                      -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-3.plan
index 7af465d..7b23753 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-3.plan
@@ -1,19 +1,38 @@
+distribute result [$$19]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$19(ASC) ]  |PARTITIONED|
+    order (ASC, $$19)
     -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$19])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$tenk.getField(7), 0))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$19] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                  unnest-map [$$17, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 1, $$24, 1, $$24, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$24)
                       -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$24])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.tenk.idx_1k_2k)  |PARTITIONED|
+                              unnest-map [$$22, $$23, $$24] <- index-search("idx_1k_2k", 0, "test", "tenk", false, false, 1, $$20, 1, $$21, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$20, $$21] <- [0, 0]
                                   -- ASSIGN  |PARTITIONED|
-                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                    empty-tuple-source
+                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-4.plan
index ce4ed8e..bfe5612 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-4.plan
@@ -1,37 +1,74 @@
+distribute result [$$23]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+    order (ASC, $$23)
     -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$23])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and(eq($$tenk.getField(7), 0), eq($$tenk.getField(8), 0)))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$23] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                  unnest-map [$$20, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 1, $$32, 1, $$32, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      intersect [$$32] <- [[$$27], [$$31]]
                       -- INTERSECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$27)
                           -- STABLE_SORT [$$27(ASC)]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$27])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.tenk.idx_1k)  |PARTITIONED|
+                                  unnest-map [$$26, $$27] <- index-search("idx_1k", 0, "test", "tenk", false, false, 1, $$24, 1, $$25, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$24, $$25])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$24, $$25] <- [$$28, $$29]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$28, $$29] <- [0, 0]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$31)
                           -- STABLE_SORT [$$31(ASC)]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$31])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.tenk.idx_2k)  |PARTITIONED|
+                                  unnest-map [$$30, $$31] <- index-search("idx_2k", 0, "test", "tenk", false, false, 1, $$28, 1, $$29, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      replicate
                                       -- REPLICATE  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$28, $$29] <- [0, 0]
                                           -- ASSIGN  |PARTITIONED|
-                                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                            empty-tuple-source
+                                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-5.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-5.plan
index d68a5a1..5a1f5ad 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-5.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-5.plan
@@ -1,37 +1,74 @@
+distribute result [$$23]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+    order (ASC, $$23)
     -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$23])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and(eq($$tenk.getField(7), 0), eq($$tenk.getField(9), 0)))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$23] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                  unnest-map [$$20, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 1, $$34, 1, $$34, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      intersect [$$34] <- [[$$28], [$$33]]
                       -- INTERSECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$28)
                           -- STABLE_SORT [$$28(ASC)]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$28])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.tenk.idx_1k_2k)  |PARTITIONED|
+                                  unnest-map [$$26, $$27, $$28] <- index-search("idx_1k_2k", 0, "test", "tenk", false, false, 1, $$24, 1, $$25, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$24, $$25])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$24, $$25] <- [$$29, $$30]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$29, $$30] <- [0, 0]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$33)
                           -- STABLE_SORT [$$33(ASC)]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$33])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.tenk.idx_5k_10k)  |PARTITIONED|
+                                  unnest-map [$$31, $$32, $$33] <- index-search("idx_5k_10k", 0, "test", "tenk", false, false, 1, $$29, 1, $$30, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      replicate
                                       -- REPLICATE  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$29, $$30] <- [0, 0]
                                           -- ASSIGN  |PARTITIONED|
-                                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                            empty-tuple-source
+                                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-6.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-6.plan
index 1d31f3b..a3f92bd 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-6.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-6.plan
@@ -1,19 +1,38 @@
+distribute result [$$23]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+    order (ASC, $$23)
     -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$23])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and(eq($$tenk.getField(7), 0), eq($$tenk.getField(8), 0)))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$23] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                  unnest-map [$$20, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 1, $$30, 1, $$30, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$30)
                       -- STABLE_SORT [$$30(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$30])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.tenk.idx_1k_2k)  |PARTITIONED|
+                              unnest-map [$$28, $$29, $$30] <- index-search("idx_1k_2k", 0, "test", "tenk", false, false, 2, $$24, $$25, 2, $$26, $$27, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$24, $$25, $$26, $$27] <- [0, 0, 0, 0]
                                   -- ASSIGN  |PARTITIONED|
-                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                    empty-tuple-source
+                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-7.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-7.plan
index 1d31f3b..a3f92bd 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-7.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-7.plan
@@ -1,19 +1,38 @@
+distribute result [$$23]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+    order (ASC, $$23)
     -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$23])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and(eq($$tenk.getField(7), 0), eq($$tenk.getField(8), 0)))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$23] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                  unnest-map [$$20, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 1, $$30, 1, $$30, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$30)
                       -- STABLE_SORT [$$30(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$30])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.tenk.idx_1k_2k)  |PARTITIONED|
+                              unnest-map [$$28, $$29, $$30] <- index-search("idx_1k_2k", 0, "test", "tenk", false, false, 2, $$24, $$25, 2, $$26, $$27, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$24, $$25, $$26, $$27] <- [0, 0, 0, 0]
                                   -- ASSIGN  |PARTITIONED|
-                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                    empty-tuple-source
+                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-8.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-8.plan
index 8594229..132cc41 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-8.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-8.plan
@@ -1,30 +1,60 @@
+distribute result [$$23]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+    order (ASC, $$23)
     -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$23])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and(eq($$tenk.getField(7), 0), eq($$tenk.getField(8), 0)))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$23] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                  unnest-map [$$20, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 1, $$36, 1, $$36, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      intersect [$$36] <- [[$$30], [$$35]]
                       -- INTERSECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$30)
                           -- STABLE_SORT [$$30(ASC)]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$30])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.tenk.idx_1k_2k)  |PARTITIONED|
+                                  unnest-map [$$28, $$29, $$30] <- index-search("idx_1k_2k", 0, "test", "tenk", false, false, 2, $$24, $$25, 2, $$26, $$27, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      assign [$$24, $$25, $$26, $$27] <- [0, 0, 0, 0]
                                       -- ASSIGN  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$35)
                           -- STABLE_SORT [$$35(ASC)]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$35])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.tenk.idx_2k_5k)  |PARTITIONED|
+                                  unnest-map [$$33, $$34, $$35] <- index-search("idx_2k_5k", 0, "test", "tenk", false, false, 1, $$31, 1, $$32, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      assign [$$31, $$32] <- [0, 0]
                                       -- ASSIGN  |PARTITIONED|
-                                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                        empty-tuple-source
+                                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-9.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-9.plan
index 8594229..132cc41 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-9.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/hints-use-index/hints-use-index-9.plan
@@ -1,30 +1,60 @@
+distribute result [$$23]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+    order (ASC, $$23)
     -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$23])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and(eq($$tenk.getField(7), 0), eq($$tenk.getField(8), 0)))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$23] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                  unnest-map [$$20, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 1, $$36, 1, $$36, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      intersect [$$36] <- [[$$30], [$$35]]
                       -- INTERSECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$30)
                           -- STABLE_SORT [$$30(ASC)]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$30])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.tenk.idx_1k_2k)  |PARTITIONED|
+                                  unnest-map [$$28, $$29, $$30] <- index-search("idx_1k_2k", 0, "test", "tenk", false, false, 2, $$24, $$25, 2, $$26, $$27, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      assign [$$24, $$25, $$26, $$27] <- [0, 0, 0, 0]
                                       -- ASSIGN  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$35)
                           -- STABLE_SORT [$$35(ASC)]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$35])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.tenk.idx_2k_5k)  |PARTITIONED|
+                                  unnest-map [$$33, $$34, $$35] <- index-search("idx_2k_5k", 0, "test", "tenk", false, false, 1, $$31, 1, $$32, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      assign [$$31, $$32] <- [0, 0]
                                       -- ASSIGN  |PARTITIONED|
-                                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                        empty-tuple-source
+                                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/intersection-misc/intersection-misc-01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/intersection-misc/intersection-misc-01.plan
index 774c135..c1b8755 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/intersection-misc/intersection-misc-01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/intersection-misc/intersection-misc-01.plan
@@ -1,128 +1,250 @@
+distribute result [$$118]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$118])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$118] <- [{"t1": $$88, "t2": $$t2, "t3": $$112}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$88, $$t2, $$112])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- SORT_MERGE_EXCHANGE [$$135(ASC), $$125(ASC), $$137(ASC) ]  |PARTITIONED|
+            order (ASC, $$135) (ASC, $$125) (ASC, $$137)
             -- STABLE_SORT [$$135(ASC), $$125(ASC), $$137(ASC)]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$88, $$t2, $$112, $$135, $$125, $$137])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    join (eq($$130, $$137))
                     -- HYBRID_HASH_JOIN [$$130][$$137]  |PARTITIONED|
+                      exchange
                       -- HASH_PARTITION_EXCHANGE [$$130]  |PARTITIONED|
+                        project ([$$88, $$t2, $$135, $$125, $$130])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            join (eq($$135, $$129))
                             -- HYBRID_HASH_JOIN [$$135][$$129]  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$135]  |PARTITIONED|
+                                assign [$$88] <- [{"c3": $$135}]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$135])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    select ($$82)
                                     -- STREAM_SELECT  |PARTITIONED|
+                                      project ([$$82, $$135])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- PRE_CLUSTERED_GROUP_BY[$$123]  |PARTITIONED|
-                                                  {
+                                          group by ([$$142 := $$123]) decor ([$$135]) {
+                                                    aggregate [$$82] <- [non-empty-stream()]
                                                     -- AGGREGATE  |LOCAL|
+                                                      select (not(is-missing($$141)))
                                                       -- STREAM_SELECT  |LOCAL|
+                                                        nested tuple source
                                                         -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                  }
+                                                 }
+                                          -- PRE_CLUSTERED_GROUP_BY[$$123]  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              order (ASC, $$123)
                                               -- STABLE_SORT [$$123(ASC)]  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$123]  |PARTITIONED|
+                                                  project ([$$135, $$141, $$123])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      left outer join (eq($$132, $$78))
                                                       -- HYBRID_HASH_JOIN [$$132][$$78]  |PARTITIONED|
+                                                        exchange
                                                         -- HASH_PARTITION_EXCHANGE [$$132]  |PARTITIONED|
+                                                          project ([$$135, $$123, $$132])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            select (eq($$d.getField("c5"), 1))
                                                             -- STREAM_SELECT  |PARTITIONED|
+                                                              assign [$$135, $$132] <- [$$d.getField("c3"), $$d.getField("c1")]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- BTREE_SEARCH (test.d.d)  |PARTITIONED|
+                                                                  unnest-map [$$123, $$d] <- index-search("d", 0, "test", "d", false, false, 1, $$148, 1, $$148, true, true, true)
+                                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      replicate
                                                                       -- REPLICATE  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          order (ASC, $$148)
                                                                           -- STABLE_SORT [$$148(ASC)]  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              project ([$$148])
                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                  -- BTREE_SEARCH (test.d.idx_c5)  |PARTITIONED|
+                                                                                  unnest-map [$$147, $$148] <- index-search("idx_c5", 0, "test", "d", false, false, 1, $$145, 1, $$146, true, true, true)
+                                                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                                                    exchange
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                      assign [$$145, $$146] <- [1, 1]
                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                        empty-tuple-source
                                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          replicate
                                                           -- REPLICATE  |PARTITIONED|
+                                                            exchange
                                                             -- HASH_PARTITION_EXCHANGE [$$78]  |PARTITIONED|
+                                                              project ([$$141, $$78])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$141, $$78] <- [true, $$c.getField("c11")]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  project ([$$c])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- DATASOURCE_SCAN (test.c)  |PARTITIONED|
+                                                                      data-scan []<-[$$124, $$c] <- test.c
+                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          empty-tuple-source
                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$129]  |PARTITIONED|
+                                assign [$$130, $$129] <- [$$t2.getField("c4"), $$t2.getField("c2")]
                                 -- ASSIGN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (test.d)  |PARTITIONED|
+                                    data-scan []<-[$$125, $$t2] <- test.d
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      exchange
                       -- HASH_PARTITION_EXCHANGE [$$137]  |PARTITIONED|
+                        assign [$$112] <- [{"c4": $$137}]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$137])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            select ($$101)
                             -- STREAM_SELECT  |PARTITIONED|
+                              project ([$$101, $$137])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- PRE_CLUSTERED_GROUP_BY[$$126]  |PARTITIONED|
-                                          {
+                                  group by ([$$144 := $$126]) decor ([$$137]) {
+                                            aggregate [$$101] <- [non-empty-stream()]
                                             -- AGGREGATE  |LOCAL|
+                                              select (not(is-missing($$143)))
                                               -- STREAM_SELECT  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                         }
+                                  -- PRE_CLUSTERED_GROUP_BY[$$126]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$126)
                                       -- STABLE_SORT [$$126(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$126]  |PARTITIONED|
+                                          project ([$$137, $$143, $$126])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              left outer join (eq($$133, $$97))
                                               -- HYBRID_HASH_JOIN [$$133][$$97]  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$133]  |PARTITIONED|
+                                                  project ([$$137, $$126, $$133])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    select (and(eq($$d.getField("c5"), 1), ge($$122, "2019-01-01"), le($$122, "2019-02-01")))
                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                      assign [$$137, $$122, $$133] <- [$$d.getField("c4"), $$d.getField("c6"), $$d.getField("c1")]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- BTREE_SEARCH (test.d.d)  |PARTITIONED|
+                                                          unnest-map [$$126, $$d] <- index-search("d", 0, "test", "d", false, false, 1, $$157, 1, $$157, true, true, true)
+                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              intersect [$$157] <- [[$$152], [$$156]]
                                                               -- INTERSECT  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  project ([$$152])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    assign [$$152] <- [$$148]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        replicate
                                                                         -- REPLICATE  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            order (ASC, $$148)
                                                                             -- STABLE_SORT [$$148(ASC)]  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                project ([$$148])
                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                    -- BTREE_SEARCH (test.d.idx_c5)  |PARTITIONED|
+                                                                                    unnest-map [$$147, $$148] <- index-search("idx_c5", 0, "test", "d", false, false, 1, $$145, 1, $$146, true, true, true)
+                                                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                        assign [$$145, $$146] <- [1, 1]
                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                          empty-tuple-source
                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  order (ASC, $$156)
                                                                   -- STABLE_SORT [$$156(ASC)]  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      project ([$$156])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                          -- BTREE_SEARCH (test.d.idx_c6)  |PARTITIONED|
+                                                                          unnest-map [$$155, $$156] <- index-search("idx_c6", 0, "test", "d", false, false, 1, $$153, 1, $$154, true, true, false)
+                                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              assign [$$153, $$154] <- ["2019-01-01", "2019-02-01"]
                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                empty-tuple-source
                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  project ([$$143, $$97])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    assign [$$143, $$97] <- [$$141, $$78]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        replicate
                                                         -- REPLICATE  |PARTITIONED|
+                                                          exchange
                                                           -- HASH_PARTITION_EXCHANGE [$$78]  |PARTITIONED|
+                                                            project ([$$141, $$78])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$141, $$78] <- [true, $$c.getField("c11")]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                project ([$$c])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (test.c)  |PARTITIONED|
+                                                                    data-scan []<-[$$124, $$c] <- test.c
+                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        empty-tuple-source
                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/intersection-misc/intersection-misc-02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/intersection-misc/intersection-misc-02.plan
index 81f2d40..72ff9a6 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/intersection-misc/intersection-misc-02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/intersection-misc/intersection-misc-02.plan
@@ -1,116 +1,226 @@
+distribute result [$$118]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$118])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$118] <- [{"t1": $$88, "t2": $$t2, "t3": $$112}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$88, $$t2, $$112])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- SORT_MERGE_EXCHANGE [$$135(ASC), $$125(ASC), $$137(ASC) ]  |PARTITIONED|
+            order (ASC, $$135) (ASC, $$125) (ASC, $$137)
             -- STABLE_SORT [$$135(ASC), $$125(ASC), $$137(ASC)]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$88, $$t2, $$112, $$135, $$125, $$137])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    join (eq($$130, $$137))
                     -- HYBRID_HASH_JOIN [$$130][$$137]  |PARTITIONED|
+                      exchange
                       -- HASH_PARTITION_EXCHANGE [$$130]  |PARTITIONED|
+                        project ([$$88, $$t2, $$135, $$125, $$130])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            join (eq($$135, $$129))
                             -- HYBRID_HASH_JOIN [$$135][$$129]  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$135]  |PARTITIONED|
+                                assign [$$88] <- [{"c3": $$135}]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$135])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    select ($$82)
                                     -- STREAM_SELECT  |PARTITIONED|
+                                      project ([$$82, $$135])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- PRE_CLUSTERED_GROUP_BY[$$123]  |PARTITIONED|
-                                                  {
+                                          group by ([$$142 := $$123]) decor ([$$135]) {
+                                                    aggregate [$$82] <- [non-empty-stream()]
                                                     -- AGGREGATE  |LOCAL|
+                                                      select (not(is-missing($$141)))
                                                       -- STREAM_SELECT  |LOCAL|
+                                                        nested tuple source
                                                         -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                  }
+                                                 }
+                                          -- PRE_CLUSTERED_GROUP_BY[$$123]  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              order (ASC, $$123)
                                               -- STABLE_SORT [$$123(ASC)]  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$123]  |PARTITIONED|
+                                                  project ([$$135, $$141, $$123])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      left outer join (eq($$132, $$78))
                                                       -- HYBRID_HASH_JOIN [$$132][$$78]  |PARTITIONED|
+                                                        exchange
                                                         -- HASH_PARTITION_EXCHANGE [$$132]  |PARTITIONED|
+                                                          project ([$$135, $$123, $$132])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            select (eq($$d.getField("c5"), 1))
                                                             -- STREAM_SELECT  |PARTITIONED|
+                                                              assign [$$135, $$132] <- [$$d.getField("c3"), $$d.getField("c1")]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  replicate
                                                                   -- REPLICATE  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- BTREE_SEARCH (test.d.d)  |PARTITIONED|
+                                                                      unnest-map [$$123, $$d] <- index-search("d", 0, "test", "d", false, false, 1, $$148, 1, $$148, true, true, true)
+                                                                      -- BTREE_SEARCH  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          order (ASC, $$148)
                                                                           -- STABLE_SORT [$$148(ASC)]  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              project ([$$148])
                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                  -- BTREE_SEARCH (test.d.idx_c5)  |PARTITIONED|
+                                                                                  unnest-map [$$147, $$148] <- index-search("idx_c5", 0, "test", "d", false, false, 1, $$145, 1, $$146, true, true, true)
+                                                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                                                    exchange
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                      assign [$$145, $$146] <- [1, 1]
                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                        empty-tuple-source
                                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          replicate
                                                           -- REPLICATE  |PARTITIONED|
+                                                            exchange
                                                             -- HASH_PARTITION_EXCHANGE [$$78]  |PARTITIONED|
+                                                              project ([$$141, $$78])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$141, $$78] <- [true, $$c.getField("c11")]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  project ([$$c])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- DATASOURCE_SCAN (test.c)  |PARTITIONED|
+                                                                      data-scan []<-[$$124, $$c] <- test.c
+                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          empty-tuple-source
                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$129]  |PARTITIONED|
+                                assign [$$130, $$129] <- [$$t2.getField("c4"), $$t2.getField("c2")]
                                 -- ASSIGN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (test.d)  |PARTITIONED|
+                                    data-scan []<-[$$125, $$t2] <- test.d
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      exchange
                       -- HASH_PARTITION_EXCHANGE [$$137]  |PARTITIONED|
+                        assign [$$112] <- [{"c4": $$137}]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$137])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            select ($$101)
                             -- STREAM_SELECT  |PARTITIONED|
+                              project ([$$101, $$137])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- PRE_CLUSTERED_GROUP_BY[$$126]  |PARTITIONED|
-                                          {
+                                  group by ([$$144 := $$126]) decor ([$$137]) {
+                                            aggregate [$$101] <- [non-empty-stream()]
                                             -- AGGREGATE  |LOCAL|
+                                              select (not(is-missing($$143)))
                                               -- STREAM_SELECT  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                         }
+                                  -- PRE_CLUSTERED_GROUP_BY[$$126]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$126)
                                       -- STABLE_SORT [$$126(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$126]  |PARTITIONED|
+                                          project ([$$137, $$143, $$126])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              left outer join (eq($$133, $$97))
                                               -- HYBRID_HASH_JOIN [$$133][$$97]  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$133]  |PARTITIONED|
+                                                  project ([$$137, $$126, $$133])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    select (and(eq($$d.getField("c5"), 1), ge($$122, "2019-01-01"), le($$122, "2019-02-01")))
                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                      assign [$$137, $$122, $$133] <- [$$d.getField("c4"), $$d.getField("c6"), $$d.getField("c1")]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        project ([$$126, $$d])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$126, $$d] <- [$$123, $$d]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              replicate
                                                               -- REPLICATE  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- BTREE_SEARCH (test.d.d)  |PARTITIONED|
+                                                                  unnest-map [$$123, $$d] <- index-search("d", 0, "test", "d", false, false, 1, $$148, 1, $$148, true, true, true)
+                                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      order (ASC, $$148)
                                                                       -- STABLE_SORT [$$148(ASC)]  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          project ([$$148])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                              -- BTREE_SEARCH (test.d.idx_c5)  |PARTITIONED|
+                                                                              unnest-map [$$147, $$148] <- index-search("idx_c5", 0, "test", "d", false, false, 1, $$145, 1, $$146, true, true, true)
+                                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  assign [$$145, $$146] <- [1, 1]
                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                    empty-tuple-source
                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  project ([$$143, $$97])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    assign [$$143, $$97] <- [$$141, $$78]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        replicate
                                                         -- REPLICATE  |PARTITIONED|
+                                                          exchange
                                                           -- HASH_PARTITION_EXCHANGE [$$78]  |PARTITIONED|
+                                                            project ([$$141, $$78])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$141, $$78] <- [true, $$c.getField("c11")]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                project ([$$c])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (test.c)  |PARTITIONED|
+                                                                    data-scan []<-[$$124, $$c] <- test.c
+                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        empty-tuple-source
                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/intersection-misc/intersection-misc-03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/intersection-misc/intersection-misc-03.plan
index 0145b58..8915c30 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/intersection-misc/intersection-misc-03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/intersection-misc/intersection-misc-03.plan
@@ -1,110 +1,214 @@
+distribute result [$$118]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$118])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$118] <- [{"t1": $$88, "t2": $$t2, "t3": $$112}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$88, $$t2, $$112])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- SORT_MERGE_EXCHANGE [$$135(ASC), $$125(ASC), $$137(ASC) ]  |PARTITIONED|
+            order (ASC, $$135) (ASC, $$125) (ASC, $$137)
             -- STABLE_SORT [$$135(ASC), $$125(ASC), $$137(ASC)]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$88, $$t2, $$112, $$135, $$125, $$137])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    join (eq($$130, $$137))
                     -- HYBRID_HASH_JOIN [$$130][$$137]  |PARTITIONED|
+                      exchange
                       -- HASH_PARTITION_EXCHANGE [$$130]  |PARTITIONED|
+                        project ([$$88, $$t2, $$135, $$125, $$130])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            join (eq($$135, $$129))
                             -- HYBRID_HASH_JOIN [$$135][$$129]  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$135]  |PARTITIONED|
+                                assign [$$88] <- [{"c3": $$135}]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$135])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    select ($$82)
                                     -- STREAM_SELECT  |PARTITIONED|
+                                      project ([$$82, $$135])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- PRE_CLUSTERED_GROUP_BY[$$123]  |PARTITIONED|
-                                                  {
+                                          group by ([$$142 := $$123]) decor ([$$135]) {
+                                                    aggregate [$$82] <- [non-empty-stream()]
                                                     -- AGGREGATE  |LOCAL|
+                                                      select (not(is-missing($$141)))
                                                       -- STREAM_SELECT  |LOCAL|
+                                                        nested tuple source
                                                         -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                  }
+                                                 }
+                                          -- PRE_CLUSTERED_GROUP_BY[$$123]  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              order (ASC, $$123)
                                               -- STABLE_SORT [$$123(ASC)]  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$123]  |PARTITIONED|
+                                                  project ([$$135, $$141, $$123])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      left outer join (eq($$132, $$78))
                                                       -- HYBRID_HASH_JOIN [$$132][$$78]  |PARTITIONED|
+                                                        exchange
                                                         -- HASH_PARTITION_EXCHANGE [$$132]  |PARTITIONED|
+                                                          project ([$$135, $$123, $$132])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            select (eq($$d.getField("c5"), 1))
                                                             -- STREAM_SELECT  |PARTITIONED|
+                                                              assign [$$135, $$132] <- [$$d.getField("c3"), $$d.getField("c1")]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- BTREE_SEARCH (test.d.d)  |PARTITIONED|
+                                                                  unnest-map [$$123, $$d] <- index-search("d", 0, "test", "d", false, false, 1, $$148, 1, $$148, true, true, true)
+                                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      order (ASC, $$148)
                                                                       -- STABLE_SORT [$$148(ASC)]  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          project ([$$148])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                              -- BTREE_SEARCH (test.d.idx_c5)  |PARTITIONED|
+                                                                              unnest-map [$$147, $$148] <- index-search("idx_c5", 0, "test", "d", false, false, 1, $$145, 1, $$146, true, true, true)
+                                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  assign [$$145, $$146] <- [1, 1]
                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                    empty-tuple-source
                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          replicate
                                                           -- REPLICATE  |PARTITIONED|
+                                                            exchange
                                                             -- HASH_PARTITION_EXCHANGE [$$78]  |PARTITIONED|
+                                                              project ([$$141, $$78])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$141, $$78] <- [true, $$c.getField("c11")]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  project ([$$c])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- DATASOURCE_SCAN (test.c)  |PARTITIONED|
+                                                                      data-scan []<-[$$124, $$c] <- test.c
+                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          empty-tuple-source
                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$129]  |PARTITIONED|
+                                assign [$$130, $$129] <- [$$t2.getField("c4"), $$t2.getField("c2")]
                                 -- ASSIGN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (test.d)  |PARTITIONED|
+                                    data-scan []<-[$$125, $$t2] <- test.d
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      exchange
                       -- HASH_PARTITION_EXCHANGE [$$137]  |PARTITIONED|
+                        assign [$$112] <- [{"c4": $$137}]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$137])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            select ($$101)
                             -- STREAM_SELECT  |PARTITIONED|
+                              project ([$$101, $$137])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- PRE_CLUSTERED_GROUP_BY[$$126]  |PARTITIONED|
-                                          {
+                                  group by ([$$144 := $$126]) decor ([$$137]) {
+                                            aggregate [$$101] <- [non-empty-stream()]
                                             -- AGGREGATE  |LOCAL|
+                                              select (not(is-missing($$143)))
                                               -- STREAM_SELECT  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                         }
+                                  -- PRE_CLUSTERED_GROUP_BY[$$126]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$126)
                                       -- STABLE_SORT [$$126(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$126]  |PARTITIONED|
+                                          project ([$$137, $$143, $$126])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              left outer join (eq($$133, $$97))
                                               -- HYBRID_HASH_JOIN [$$133][$$97]  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$133]  |PARTITIONED|
+                                                  project ([$$137, $$126, $$133])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    select (and(eq($$d.getField("c5"), 1), ge($$122, "2019-01-01"), le($$122, "2019-02-01")))
                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                      assign [$$137, $$122, $$133] <- [$$d.getField("c4"), $$d.getField("c6"), $$d.getField("c1")]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- BTREE_SEARCH (test.d.d)  |PARTITIONED|
+                                                          unnest-map [$$126, $$d] <- index-search("d", 0, "test", "d", false, false, 1, $$152, 1, $$152, true, true, true)
+                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              order (ASC, $$152)
                                                               -- STABLE_SORT [$$152(ASC)]  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  project ([$$152])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- BTREE_SEARCH (test.d.idx_c6)  |PARTITIONED|
+                                                                      unnest-map [$$151, $$152] <- index-search("idx_c6", 0, "test", "d", false, false, 1, $$149, 1, $$150, true, true, false)
+                                                                      -- BTREE_SEARCH  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          assign [$$149, $$150] <- ["2019-01-01", "2019-02-01"]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            empty-tuple-source
                                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  project ([$$143, $$97])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    assign [$$143, $$97] <- [$$141, $$78]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        replicate
                                                         -- REPLICATE  |PARTITIONED|
+                                                          exchange
                                                           -- HASH_PARTITION_EXCHANGE [$$78]  |PARTITIONED|
+                                                            project ([$$141, $$78])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$141, $$78] <- [true, $$c.getField("c11")]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                project ([$$c])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (test.c)  |PARTITIONED|
+                                                                    data-scan []<-[$$124, $$c] <- test.c
+                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        empty-tuple-source
                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/intersection-misc/intersection-misc-04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/intersection-misc/intersection-misc-04.plan
index d3cde62..6f49e59 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/intersection-misc/intersection-misc-04.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index-selection/intersection-misc/intersection-misc-04.plan
@@ -1,106 +1,206 @@
+distribute result [$$118]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$118])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$118] <- [{"t1": $$88, "t2": $$t2, "t3": $$112}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$88, $$t2, $$112])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- SORT_MERGE_EXCHANGE [$$135(ASC), $$125(ASC), $$137(ASC) ]  |PARTITIONED|
+            order (ASC, $$135) (ASC, $$125) (ASC, $$137)
             -- STABLE_SORT [$$135(ASC), $$125(ASC), $$137(ASC)]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$88, $$t2, $$112, $$135, $$125, $$137])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    join (eq($$130, $$137))
                     -- HYBRID_HASH_JOIN [$$130][$$137]  |PARTITIONED|
+                      exchange
                       -- HASH_PARTITION_EXCHANGE [$$130]  |PARTITIONED|
+                        project ([$$88, $$t2, $$135, $$125, $$130])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            join (eq($$135, $$129))
                             -- HYBRID_HASH_JOIN [$$135][$$129]  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$135]  |PARTITIONED|
+                                assign [$$88] <- [{"c3": $$135}]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$135])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    select ($$82)
                                     -- STREAM_SELECT  |PARTITIONED|
+                                      project ([$$82, $$135])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- PRE_CLUSTERED_GROUP_BY[$$123]  |PARTITIONED|
-                                                  {
+                                          group by ([$$142 := $$123]) decor ([$$135]) {
+                                                    aggregate [$$82] <- [non-empty-stream()]
                                                     -- AGGREGATE  |LOCAL|
+                                                      select (not(is-missing($$141)))
                                                       -- STREAM_SELECT  |LOCAL|
+                                                        nested tuple source
                                                         -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                  }
+                                                 }
+                                          -- PRE_CLUSTERED_GROUP_BY[$$123]  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              order (ASC, $$123)
                                               -- STABLE_SORT [$$123(ASC)]  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$123]  |PARTITIONED|
+                                                  project ([$$135, $$141, $$123])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      left outer join (eq($$132, $$78))
                                                       -- HYBRID_HASH_JOIN [$$132][$$78]  |PARTITIONED|
+                                                        exchange
                                                         -- HASH_PARTITION_EXCHANGE [$$132]  |PARTITIONED|
+                                                          project ([$$135, $$123, $$132])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            select (eq($$d.getField("c5"), 1))
                                                             -- STREAM_SELECT  |PARTITIONED|
+                                                              assign [$$135, $$132] <- [$$d.getField("c3"), $$d.getField("c1")]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  replicate
                                                                   -- REPLICATE  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- DATASOURCE_SCAN (test.d)  |PARTITIONED|
+                                                                      data-scan []<-[$$123, $$d] <- test.d
+                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          empty-tuple-source
                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          replicate
                                                           -- REPLICATE  |PARTITIONED|
+                                                            exchange
                                                             -- HASH_PARTITION_EXCHANGE [$$78]  |PARTITIONED|
+                                                              project ([$$141, $$78])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$141, $$78] <- [true, $$c.getField("c11")]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  project ([$$c])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- DATASOURCE_SCAN (test.c)  |PARTITIONED|
+                                                                      data-scan []<-[$$124, $$c] <- test.c
+                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          empty-tuple-source
                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$129]  |PARTITIONED|
+                                assign [$$130, $$129] <- [$$t2.getField("c4"), $$t2.getField("c2")]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$125, $$t2])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$125, $$t2] <- [$$123, $$d]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        replicate
                                         -- REPLICATE  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (test.d)  |PARTITIONED|
+                                            data-scan []<-[$$123, $$d] <- test.d
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      exchange
                       -- HASH_PARTITION_EXCHANGE [$$137]  |PARTITIONED|
+                        assign [$$112] <- [{"c4": $$137}]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$137])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            select ($$101)
                             -- STREAM_SELECT  |PARTITIONED|
+                              project ([$$101, $$137])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- PRE_CLUSTERED_GROUP_BY[$$126]  |PARTITIONED|
-                                          {
+                                  group by ([$$144 := $$126]) decor ([$$137]) {
+                                            aggregate [$$101] <- [non-empty-stream()]
                                             -- AGGREGATE  |LOCAL|
+                                              select (not(is-missing($$143)))
                                               -- STREAM_SELECT  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                         }
+                                  -- PRE_CLUSTERED_GROUP_BY[$$126]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$126)
                                       -- STABLE_SORT [$$126(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$126]  |PARTITIONED|
+                                          project ([$$137, $$143, $$126])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              left outer join (eq($$133, $$97))
                                               -- HYBRID_HASH_JOIN [$$133][$$97]  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$133]  |PARTITIONED|
+                                                  project ([$$137, $$126, $$133])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    select (and(eq($$d.getField("c5"), 1), ge($$122, "2019-01-01"), le($$122, "2019-02-01")))
                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                      assign [$$137, $$122, $$133] <- [$$d.getField("c4"), $$d.getField("c6"), $$d.getField("c1")]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        project ([$$126, $$d])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$126, $$d] <- [$$123, $$d]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              replicate
                                                               -- REPLICATE  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- DATASOURCE_SCAN (test.d)  |PARTITIONED|
+                                                                  data-scan []<-[$$123, $$d] <- test.d
+                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      empty-tuple-source
                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  project ([$$143, $$97])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    assign [$$143, $$97] <- [$$141, $$78]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        replicate
                                                         -- REPLICATE  |PARTITIONED|
+                                                          exchange
                                                           -- HASH_PARTITION_EXCHANGE [$$78]  |PARTITIONED|
+                                                            project ([$$141, $$78])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$141, $$78] <- [true, $$c.getField("c11")]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                project ([$$c])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (test.c)  |PARTITIONED|
+                                                                    data-scan []<-[$$124, $$c] <- test.c
+                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        empty-tuple-source
                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-composite-key-03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-composite-key-03.plan
index 0f21ecf..4fd110c 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-composite-key-03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-composite-key-03.plan
@@ -1,15 +1,30 @@
+distribute result [$$l]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (and(eq($$l.getField(1), "Julio"), eq($$l.getField(2), "Isa")))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$l])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.employee.employee)  |PARTITIONED|
+          unnest-map [$$17, $$l] <- index-search("employee", 0, "test", "employee", false, false, 1, $$25, 1, $$25, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$25)
               -- STABLE_SORT [$$25(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$25])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (test.employee.idx_employee_fal)  |PARTITIONED|
+                      unnest-map [$$22, $$23, $$24, $$25] <- index-search("idx_employee_fal", 0, "test", "employee", false, false, 1, $$20, 1, $$21, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$20, $$21] <- ["Julio", "Julio"]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-33.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-33.plan
index 49dab53..8a36682 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-33.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-33.plan
@@ -1,15 +1,30 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (gt($$emp.getField(1), "Roger"))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+          unnest-map [$$14, $$emp] <- index-search("testdst", 0, "test", "testdst", false, false, 1, $$19, 1, $$19, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$19)
               -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$19])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                      unnest-map [$$17, $$18, $$19] <- index-search("sec_Idx", 0, "test", "testdst", false, false, 1, $$16, 0, false, true, false)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$16] <- ["Roger"]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-34.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-34.plan
index 49dab53..acaaf22 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-34.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-34.plan
@@ -1,15 +1,30 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (ge($$emp.getField(1), "Susan"))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+          unnest-map [$$14, $$emp] <- index-search("testdst", 0, "test", "testdst", false, false, 1, $$19, 1, $$19, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$19)
               -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$19])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                      unnest-map [$$17, $$18, $$19] <- index-search("sec_Idx", 0, "test", "testdst", false, false, 1, $$16, 0, true, true, false)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$16] <- ["Susan"]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-35.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-35.plan
index 49dab53..bfa7f29 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-35.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-35.plan
@@ -1,15 +1,30 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (lt($$emp.getField(1), "Isa"))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+          unnest-map [$$14, $$emp] <- index-search("testdst", 0, "test", "testdst", false, false, 1, $$19, 1, $$19, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$19)
               -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$19])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                      unnest-map [$$17, $$18, $$19] <- index-search("sec_Idx", 0, "test", "testdst", false, false, 0, 1, $$16, true, false, false)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$16] <- ["Isa"]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-36.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-36.plan
index 49dab53..dfef03a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-36.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-36.plan
@@ -1,15 +1,30 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (le($$emp.getField(1), "Vanpatten"))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+          unnest-map [$$14, $$emp] <- index-search("testdst", 0, "test", "testdst", false, false, 1, $$19, 1, $$19, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$19)
               -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$19])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                      unnest-map [$$17, $$18, $$19] <- index-search("sec_Idx", 0, "test", "testdst", false, false, 0, 1, $$16, true, true, false)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$16] <- ["Vanpatten"]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-40.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-40.plan
index 90f0e84..e889e8c 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-40.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-40.plan
@@ -1,15 +1,30 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (and(eq($$emp.getField(1), "Young Seok"), eq($$emp.getField(2), "Kim")))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+          unnest-map [$$17, $$emp] <- index-search("testdst", 0, "test", "testdst", false, false, 1, $$26, 1, $$26, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$26)
               -- STABLE_SORT [$$26(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$26])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                      unnest-map [$$24, $$25, $$26] <- index-search("sec_Idx", 0, "test", "testdst", false, false, 2, $$20, $$21, 2, $$22, $$23, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$20, $$21, $$22, $$23] <- ["Young Seok", "Kim", "Young Seok", "Kim"]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-42.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-42.plan
index e7a5c31..4c85d8f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-42.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-42.plan
@@ -1,15 +1,30 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (and(gt($$emp.getField(1), "Alex"), lt($$emp.getField(2), "Zach")))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+          unnest-map [$$17, $$emp] <- index-search("testdst", 0, "test", "testdst", false, false, 1, $$23, 1, $$23, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$23)
               -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$23])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                      unnest-map [$$21, $$22, $$23] <- index-search("sec_Idx", 0, "test", "testdst", false, false, 1, $$20, 0, true, true, false)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$20] <- ["Alex"]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-43.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-43.plan
index e7a5c31..4fba1ff 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-43.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-43.plan
@@ -1,15 +1,30 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (and(gt($$emp.getField(1), "Allan"), lt($$emp.getField(2), "Zubi")))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+          unnest-map [$$17, $$emp] <- index-search("testdst", 0, "test", "testdst", false, false, 1, $$23, 1, $$23, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$23)
               -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$23])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                      unnest-map [$$21, $$22, $$23] <- index-search("sec_Idx", 0, "test", "testdst", false, false, 1, $$20, 0, true, true, false)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$20] <- ["Allan"]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-44.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-44.plan
index e7a5c31..3302d9c 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-44.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-44.plan
@@ -1,15 +1,30 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (and(gt($$emp.getField(1), "Allan"), eq($$emp.getField(2), "Xu")))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+          unnest-map [$$17, $$emp] <- index-search("testdst", 0, "test", "testdst", false, false, 1, $$23, 1, $$23, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$23)
               -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$23])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                      unnest-map [$$21, $$22, $$23] <- index-search("sec_Idx", 0, "test", "testdst", false, false, 1, $$20, 0, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$20] <- ["Allan"]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-45.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-45.plan
index 0746bd8..f6bd189 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-45.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-45.plan
@@ -1,15 +1,30 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (and(eq($$emp.getField(1), "Julio"), lt($$emp.getField(2), "Xu")))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+          unnest-map [$$17, $$emp] <- index-search("testdst", 0, "test", "testdst", false, false, 1, $$24, 1, $$24, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$24)
               -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$24])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                      unnest-map [$$22, $$23, $$24] <- index-search("sec_Idx", 0, "test", "testdst", false, false, 1, $$20, 1, $$21, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$20, $$21] <- ["Julio", "Julio"]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-46.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-46.plan
index e7a5c31..3277e46 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-46.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-46.plan
@@ -1,15 +1,30 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (and(ge($$emp.getField(1), "Michael"), le($$emp.getField(2), "Xu")))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+          unnest-map [$$17, $$emp] <- index-search("testdst", 0, "test", "testdst", false, false, 1, $$23, 1, $$23, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$23)
               -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$23])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                      unnest-map [$$21, $$22, $$23] <- index-search("sec_Idx", 0, "test", "testdst", false, false, 1, $$20, 0, true, true, false)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$20] <- ["Michael"]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-47.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-47.plan
index e9f5574..6eff1a9 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-47.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-47.plan
@@ -1,17 +1,34 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$emp])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (and(lt($$21, "Tomes"), gt($$21, "Kevin"), gt($$22, "Craig"), lt($$22, "Mary")))
       -- STREAM_SELECT  |PARTITIONED|
+        assign [$$22, $$21] <- [$$emp.getField(1), $$emp.getField(2)]
         -- ASSIGN  |PARTITIONED|
+          project ([$$emp])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+              unnest-map [$$23, $$emp] <- index-search("testdst", 0, "test", "testdst", false, false, 1, $$30, 1, $$30, true, true, true)
+              -- BTREE_SEARCH  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  order (ASC, $$30)
                   -- STABLE_SORT [$$30(ASC)]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$30])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                          unnest-map [$$28, $$29, $$30] <- index-search("sec_Idx", 0, "test", "testdst", false, false, 2, $$24, $$25, 2, $$26, $$27, true, true, false)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              assign [$$24, $$25, $$26, $$27] <- ["Craig", "Kevin", "Mary", "Tomes"]
                               -- ASSIGN  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-48.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-48.plan
index e9f5574..4f0472b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-48.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-48.plan
@@ -1,17 +1,34 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$emp])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (and(le($$21, "Tomes"), ge($$21, "Kevin"), ge($$22, "Craig"), le($$22, "Mary")))
       -- STREAM_SELECT  |PARTITIONED|
+        assign [$$22, $$21] <- [$$emp.getField(1), $$emp.getField(2)]
         -- ASSIGN  |PARTITIONED|
+          project ([$$emp])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+              unnest-map [$$23, $$emp] <- index-search("testdst", 0, "test", "testdst", false, false, 1, $$30, 1, $$30, true, true, true)
+              -- BTREE_SEARCH  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  order (ASC, $$30)
                   -- STABLE_SORT [$$30(ASC)]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$30])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                          unnest-map [$$28, $$29, $$30] <- index-search("sec_Idx", 0, "test", "testdst", false, false, 2, $$24, $$25, 2, $$26, $$27, true, true, false)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              assign [$$24, $$25, $$26, $$27] <- ["Craig", "Kevin", "Mary", "Tomes"]
                               -- ASSIGN  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-49.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-49.plan
index e7a5c31..0fb24bb 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-49.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-49.plan
@@ -1,15 +1,30 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (and(le($$emp.getField(1), "Craig"), gt($$emp.getField(2), "Kevin")))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+          unnest-map [$$17, $$emp] <- index-search("testdst", 0, "test", "testdst", false, false, 1, $$23, 1, $$23, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$23)
               -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$23])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                      unnest-map [$$21, $$22, $$23] <- index-search("sec_Idx", 0, "test", "testdst", false, false, 0, 1, $$20, true, true, false)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$20] <- ["Craig"]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-51.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-51.plan
index e9f5574..fc73613 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-51.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-51.plan
@@ -1,17 +1,34 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$emp])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (and(le($$21, "Tomes"), gt($$21, "Kevin"), gt($$22, "Craig"), le($$22, "Mary")))
       -- STREAM_SELECT  |PARTITIONED|
+        assign [$$22, $$21] <- [$$emp.getField(1), $$emp.getField(2)]
         -- ASSIGN  |PARTITIONED|
+          project ([$$emp])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+              unnest-map [$$23, $$emp] <- index-search("testdst", 0, "test", "testdst", false, false, 1, $$30, 1, $$30, true, true, true)
+              -- BTREE_SEARCH  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  order (ASC, $$30)
                   -- STABLE_SORT [$$30(ASC)]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$30])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                          unnest-map [$$28, $$29, $$30] <- index-search("sec_Idx", 0, "test", "testdst", false, false, 2, $$24, $$25, 2, $$26, $$27, true, true, false)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              assign [$$24, $$25, $$26, $$27] <- ["Craig", "Kevin", "Mary", "Tomes"]
                               -- ASSIGN  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-52.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-52.plan
index e9f5574..5421c88 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-52.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-52.plan
@@ -1,17 +1,34 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$emp])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (and(lt($$21, "Tomes"), ge($$21, "Kevin"), ge($$22, "Craig"), lt($$22, "Mary")))
       -- STREAM_SELECT  |PARTITIONED|
+        assign [$$22, $$21] <- [$$emp.getField(1), $$emp.getField(2)]
         -- ASSIGN  |PARTITIONED|
+          project ([$$emp])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+              unnest-map [$$23, $$emp] <- index-search("testdst", 0, "test", "testdst", false, false, 1, $$30, 1, $$30, true, true, true)
+              -- BTREE_SEARCH  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  order (ASC, $$30)
                   -- STABLE_SORT [$$30(ASC)]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$30])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                          unnest-map [$$28, $$29, $$30] <- index-search("sec_Idx", 0, "test", "testdst", false, false, 2, $$24, $$25, 2, $$26, $$27, true, true, false)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              assign [$$24, $$25, $$26, $$27] <- ["Craig", "Kevin", "Mary", "Tomes"]
                               -- ASSIGN  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-53.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-53.plan
index e9f5574..0996548 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-53.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-53.plan
@@ -1,17 +1,34 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$emp])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (and(ge($$21, "Tomes"), le($$21, "Kevin"), ge($$22, "Craig"), le($$22, "Mary")))
       -- STREAM_SELECT  |PARTITIONED|
+        assign [$$22, $$21] <- [$$emp.getField(1), $$emp.getField(2)]
         -- ASSIGN  |PARTITIONED|
+          project ([$$emp])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+              unnest-map [$$23, $$emp] <- index-search("testdst", 0, "test", "testdst", false, false, 1, $$30, 1, $$30, true, true, true)
+              -- BTREE_SEARCH  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  order (ASC, $$30)
                   -- STABLE_SORT [$$30(ASC)]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$30])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                          unnest-map [$$28, $$29, $$30] <- index-search("sec_Idx", 0, "test", "testdst", false, false, 2, $$24, $$25, 2, $$26, $$27, true, true, false)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              assign [$$24, $$25, $$26, $$27] <- ["Craig", "Tomes", "Mary", "Kevin"]
                               -- ASSIGN  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-54.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-54.plan
index 0b28fcd..9b2792d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-54.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-54.plan
@@ -1,15 +1,30 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (gt($$emp.getField(1), "Max"))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+          unnest-map [$$14, $$emp] <- index-search("testdst", 0, "test", "testdst", false, false, 1, $$18, 1, $$18, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$18)
               -- STABLE_SORT [$$18(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$18])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                      unnest-map [$$17, $$18] <- index-search("sec_Idx", 0, "test", "testdst", false, false, 1, $$16, 0, false, true, false)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$16] <- ["Max"]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-55.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-55.plan
index 0b28fcd..e365f68 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-55.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-55.plan
@@ -1,15 +1,30 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (ge($$emp.getField(1), "Sofia"))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+          unnest-map [$$14, $$emp] <- index-search("testdst", 0, "test", "testdst", false, false, 1, $$18, 1, $$18, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$18)
               -- STABLE_SORT [$$18(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$18])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                      unnest-map [$$17, $$18] <- index-search("sec_Idx", 0, "test", "testdst", false, false, 1, $$16, 0, true, true, false)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$16] <- ["Sofia"]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-56.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-56.plan
index 0b28fcd..932a057 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-56.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-56.plan
@@ -1,15 +1,30 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (lt($$emp.getField(1), "Chen"))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+          unnest-map [$$14, $$emp] <- index-search("testdst", 0, "test", "testdst", false, false, 1, $$18, 1, $$18, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$18)
               -- STABLE_SORT [$$18(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$18])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                      unnest-map [$$17, $$18] <- index-search("sec_Idx", 0, "test", "testdst", false, false, 0, 1, $$16, true, false, false)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$16] <- ["Chen"]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-57.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-57.plan
index 0b28fcd..093f61d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-57.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-57.plan
@@ -1,15 +1,30 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (le($$emp.getField(1), "Julio"))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+          unnest-map [$$14, $$emp] <- index-search("testdst", 0, "test", "testdst", false, false, 1, $$18, 1, $$18, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$18)
               -- STABLE_SORT [$$18(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$18])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                      unnest-map [$$17, $$18] <- index-search("sec_Idx", 0, "test", "testdst", false, false, 0, 1, $$16, true, true, false)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$16] <- ["Julio"]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-58.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-58.plan
index c311b11..2e4fc6d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-58.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-58.plan
@@ -1,17 +1,34 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$emp])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (and(gt($$17, "Neil"), lt($$17, "Roger")))
       -- STREAM_SELECT  |PARTITIONED|
+        assign [$$17] <- [$$emp.getField(1)]
         -- ASSIGN  |PARTITIONED|
+          project ([$$emp])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+              unnest-map [$$18, $$emp] <- index-search("testdst", 0, "test", "testdst", false, false, 1, $$22, 1, $$22, true, true, true)
+              -- BTREE_SEARCH  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  order (ASC, $$22)
                   -- STABLE_SORT [$$22(ASC)]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$22])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                          unnest-map [$$21, $$22] <- index-search("sec_Idx", 0, "test", "testdst", false, false, 1, $$19, 1, $$20, false, false, false)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              assign [$$19, $$20] <- ["Neil", "Roger"]
                               -- ASSIGN  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-59.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-59.plan
index c311b11..e6de17d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-59.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-59.plan
@@ -1,17 +1,34 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$emp])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (and(ge($$17, "Max"), le($$17, "Roger")))
       -- STREAM_SELECT  |PARTITIONED|
+        assign [$$17] <- [$$emp.getField(1)]
         -- ASSIGN  |PARTITIONED|
+          project ([$$emp])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+              unnest-map [$$18, $$emp] <- index-search("testdst", 0, "test", "testdst", false, false, 1, $$22, 1, $$22, true, true, true)
+              -- BTREE_SEARCH  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  order (ASC, $$22)
                   -- STABLE_SORT [$$22(ASC)]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$22])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                          unnest-map [$$21, $$22] <- index-search("sec_Idx", 0, "test", "testdst", false, false, 1, $$19, 1, $$20, true, true, false)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              assign [$$19, $$20] <- ["Max", "Roger"]
                               -- ASSIGN  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-60.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-60.plan
index 49dab53..2ebc435 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-60.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-60.plan
@@ -1,15 +1,30 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (eq($$emp.getField(1), "Max"))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+          unnest-map [$$14, $$emp] <- index-search("testdst", 0, "test", "testdst", false, false, 1, $$19, 1, $$19, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$19)
               -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$19])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                      unnest-map [$$18, $$19] <- index-search("sec_Idx", 0, "test", "testdst", false, false, 1, $$16, 1, $$17, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$16, $$17] <- ["Max", "Max"]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-61.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-61.plan
index e9f5574..c04eb4f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-61.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-61.plan
@@ -1,17 +1,34 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$emp])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (and(lt($$21, "Tomes"), gt($$21, "Kevin"), gt($$22, "Craig"), le($$22, "Mary")))
       -- STREAM_SELECT  |PARTITIONED|
+        assign [$$22, $$21] <- [$$emp.getField(1), $$emp.getField(2)]
         -- ASSIGN  |PARTITIONED|
+          project ([$$emp])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+              unnest-map [$$23, $$emp] <- index-search("testdst", 0, "test", "testdst", false, false, 1, $$30, 1, $$30, true, true, true)
+              -- BTREE_SEARCH  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  order (ASC, $$30)
                   -- STABLE_SORT [$$30(ASC)]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$30])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                          unnest-map [$$28, $$29, $$30] <- index-search("sec_Idx", 0, "test", "testdst", false, false, 2, $$24, $$25, 2, $$26, $$27, true, true, false)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              assign [$$24, $$25, $$26, $$27] <- ["Craig", "Kevin", "Mary", "Tomes"]
                               -- ASSIGN  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-62.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-62.plan
index 0746bd8..7bbcf62 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-62.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-62.plan
@@ -1,15 +1,30 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (and(eq($$emp.getField(1), "Julio"), gt($$emp.getField(2), "Xu")))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+          unnest-map [$$17, $$emp] <- index-search("testdst", 0, "test", "testdst", false, false, 1, $$24, 1, $$24, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$24)
               -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$24])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                      unnest-map [$$22, $$23, $$24] <- index-search("sec_Idx", 0, "test", "testdst", false, false, 1, $$20, 1, $$21, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$20, $$21] <- ["Julio", "Julio"]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-63.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-63.plan
index e7a5c31..c86bb53 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-63.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-63.plan
@@ -1,15 +1,30 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (and(lt($$emp.getField(1), "Julio"), eq($$emp.getField(2), "Xu")))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+          unnest-map [$$17, $$emp] <- index-search("testdst", 0, "test", "testdst", false, false, 1, $$23, 1, $$23, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$23)
               -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$23])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                      unnest-map [$$21, $$22, $$23] <- index-search("sec_Idx", 0, "test", "testdst", false, false, 0, 1, $$20, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$20] <- ["Julio"]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-68.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-68.plan
index 11f5d9f..094236b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-68.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-68.plan
@@ -1,32 +1,64 @@
+distribute result [$$24]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$24])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$24] <- [{"o_custkey": $$27, "o_orderkey": $$28, "o_orderstatus": $$33}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$27(ASC), $$28(ASC) ]  |PARTITIONED|
+          order (ASC, $$27) (ASC, $$28)
           -- STABLE_SORT [$$27(ASC), $$28(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$27, $$28, $$33])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (and(eq($$Orders.getField(5), "1-URGENT"), le($$27, 43), ge($$27, 40)))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$33, $$27] <- [$$Orders.getField(2), $$Orders.getField(1)]
                   -- ASSIGN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (tpch.Orders.Orders)  |PARTITIONED|
+                      unnest-map [$$28, $$Orders] <- index-search("Orders", 0, "tpch", "Orders", false, false, 1, $$42, 1, $$42, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          intersect [$$42] <- [[$$37], [$$41]]
                           -- INTERSECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$37)
                               -- STABLE_SORT [$$37(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$37])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- BTREE_SEARCH (tpch.Orders.idx_custkey)  |PARTITIONED|
+                                      unnest-map [$$36, $$37] <- index-search("idx_custkey", 0, "tpch", "Orders", false, false, 1, $$34, 1, $$35, true, true, false)
+                                      -- BTREE_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$34, $$35] <- [40, 43]
                                           -- ASSIGN  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$41)
                               -- STABLE_SORT [$$41(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$41])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- BTREE_SEARCH (tpch.Orders.idx_orderpriority)  |PARTITIONED|
+                                      unnest-map [$$40, $$41] <- index-search("idx_orderpriority", 0, "tpch", "Orders", false, false, 1, $$38, 1, $$39, true, true, true)
+                                      -- BTREE_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$38, $$39] <- ["1-URGENT", "1-URGENT"]
                                           -- ASSIGN  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-68_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-68_ps.plan
index c135758..5d97d0b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-68_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-68_ps.plan
@@ -1,69 +1,138 @@
+distribute result [$$24]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$24])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$24] <- [{"o_custkey": $$27, "o_orderkey": $$28, "o_orderstatus": $$33}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$27) (ASC, $$28)
           -- STABLE_SORT [$$27(ASC), $$28(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$27(ASC), $$28(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$46
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$27, $$28, $$33])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (and(eq($$Orders.getField(5), "1-URGENT"), le($$27, 43), ge($$27, 40)))
                         -- STREAM_SELECT  |PARTITIONED|
+                          assign [$$33, $$27] <- [$$Orders.getField(2), $$Orders.getField(1)]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (tpch.Orders.Orders)  |PARTITIONED|
+                              unnest-map [$$28, $$Orders] <- index-search("Orders", 0, "tpch", "Orders", false, false, 1, $$42, 1, $$42, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  intersect [$$42] <- [[$$37], [$$41]]
                                   -- INTERSECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$37)
                                       -- STABLE_SORT [$$37(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$37])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- BTREE_SEARCH (tpch.Orders.idx_custkey)  |PARTITIONED|
+                                              unnest-map [$$36, $$37] <- index-search("idx_custkey", 0, "tpch", "Orders", false, false, 1, $$34, 1, $$35, true, true, false)
+                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  assign [$$34, $$35] <- [40, 43]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$41)
                                       -- STABLE_SORT [$$41(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$41])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- BTREE_SEARCH (tpch.Orders.idx_orderpriority)  |PARTITIONED|
+                                              unnest-map [$$40, $$41] <- index-search("idx_orderpriority", 0, "tpch", "Orders", false, false, 1, $$38, 1, $$39, true, true, true)
+                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  assign [$$38, $$39] <- ["1-URGENT", "1-URGENT"]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$46] <- [agg-range-map($$43, $$44, $$45)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$43, $$44, $$45] <- [agg-local-sampling($$27, $$28), agg-null-writer($$27), agg-null-writer($$28)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$27, $$28])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$27, $$28, $$33])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  select (and(eq($$Orders.getField(5), "1-URGENT"), le($$27, 43), ge($$27, 40)))
                                   -- STREAM_SELECT  |PARTITIONED|
+                                    assign [$$33, $$27] <- [$$Orders.getField(2), $$Orders.getField(1)]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (tpch.Orders.Orders)  |PARTITIONED|
+                                        unnest-map [$$28, $$Orders] <- index-search("Orders", 0, "tpch", "Orders", false, false, 1, $$42, 1, $$42, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            intersect [$$42] <- [[$$37], [$$41]]
                                             -- INTERSECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                order (ASC, $$37)
                                                 -- STABLE_SORT [$$37(ASC)]  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$$37])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- BTREE_SEARCH (tpch.Orders.idx_custkey)  |PARTITIONED|
+                                                        unnest-map [$$36, $$37] <- index-search("idx_custkey", 0, "tpch", "Orders", false, false, 1, $$34, 1, $$35, true, true, false)
+                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            assign [$$34, $$35] <- [40, 43]
                                                             -- ASSIGN  |PARTITIONED|
+                                                              empty-tuple-source
                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                order (ASC, $$41)
                                                 -- STABLE_SORT [$$41(ASC)]  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$$41])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- BTREE_SEARCH (tpch.Orders.idx_orderpriority)  |PARTITIONED|
+                                                        unnest-map [$$40, $$41] <- index-search("idx_orderpriority", 0, "tpch", "Orders", false, false, 1, $$38, 1, $$39, true, true, true)
+                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            assign [$$38, $$39] <- ["1-URGENT", "1-URGENT"]
                                                             -- ASSIGN  |PARTITIONED|
+                                                              empty-tuple-source
                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-sidx-idxonly-01-disable-idxonly.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-sidx-idxonly-01-disable-idxonly.plan
index aa1f23c..9e50df0 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-sidx-idxonly-01-disable-idxonly.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-sidx-idxonly-01-disable-idxonly.plan
@@ -1,19 +1,38 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$17] <- [{"pk": $$20, "sk": $$19}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$20(ASC) ]  |PARTITIONED|
+          select (lt($$19, 3))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$20, $$19])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$19] <- [$$o.getField(1)]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.MyData.MyData)  |PARTITIONED|
+                  unnest-map [$$20, $$o] <- index-search("MyData", 0, "test", "MyData", false, false, 1, $$25, 1, $$25, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$25)
                       -- STABLE_SORT [$$25(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$25])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.MyData.btree_index_docid)  |PARTITIONED|
+                              unnest-map [$$24, $$25] <- index-search("btree_index_docid", 0, "test", "MyData", false, false, 0, 1, $$23, true, false, false)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$23] <- [3]
                                   -- ASSIGN  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-sidx-idxonly-01-disable-idxonly_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-sidx-idxonly-01-disable-idxonly_ps.plan
index 6fbe462..0dcc7c0 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-sidx-idxonly-01-disable-idxonly_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-sidx-idxonly-01-disable-idxonly_ps.plan
@@ -1,47 +1,94 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$17] <- [{"pk": $$20, "sk": $$19}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$20(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$28
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      select (lt($$19, 3))
                       -- STREAM_SELECT  |PARTITIONED|
+                        project ([$$20, $$19])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$19] <- [$$o.getField(1)]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.MyData.MyData)  |PARTITIONED|
+                              unnest-map [$$20, $$o] <- index-search("MyData", 0, "test", "MyData", false, false, 1, $$25, 1, $$25, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  order (ASC, $$25)
                                   -- STABLE_SORT [$$25(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$25])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (test.MyData.btree_index_docid)  |PARTITIONED|
+                                          unnest-map [$$24, $$25] <- index-search("btree_index_docid", 0, "test", "MyData", false, false, 0, 1, $$23, true, false, false)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$23] <- [3]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$28] <- [agg-range-map($$26, $$27)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$26, $$27] <- [agg-local-sampling($$20), agg-null-writer($$20)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$20])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                select (lt($$19, 3))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  project ([$$20, $$19])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$19] <- [$$o.getField(1)]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.MyData.MyData)  |PARTITIONED|
+                                        unnest-map [$$20, $$o] <- index-search("MyData", 0, "test", "MyData", false, false, 1, $$25, 1, $$25, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            order (ASC, $$25)
                                             -- STABLE_SORT [$$25(ASC)]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$25])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (test.MyData.btree_index_docid)  |PARTITIONED|
+                                                    unnest-map [$$24, $$25] <- index-search("btree_index_docid", 0, "test", "MyData", false, false, 0, 1, $$23, true, false, false)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        assign [$$23] <- [3]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-sidx-idxonly-01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-sidx-idxonly-01.plan
index 9bf7df8..4309eb2 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-sidx-idxonly-01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-sidx-idxonly-01.plan
@@ -1,30 +1,60 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$17] <- [{"pk": $$20, "sk": $$19}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$20(ASC) ]  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              union ($$30, $$25, $$20) ($$32, $$24, $$19)
               -- UNION_ALL  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  select (lt($$32, 3))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$30, $$32])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$32] <- [$$31.getField(1)]
                       -- ASSIGN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (test.MyData.MyData)  |PARTITIONED|
+                          unnest-map [$$30, $$31] <- index-search("MyData", 0, "test", "MyData", false, false, 1, $$25, 1, $$25, true, true, true)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              split ($$26)
                               -- SPLIT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.MyData.btree_index_docid)  |PARTITIONED|
+                                  unnest-map [$$24, $$25, $$26] <- index-search("btree_index_docid", 0, "test", "MyData", false, false, 0, 1, $$23, true, false, false)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      assign [$$23] <- [3]
                                       -- ASSIGN  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$25, $$24])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      split ($$26)
                       -- SPLIT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (test.MyData.btree_index_docid)  |PARTITIONED|
+                          unnest-map [$$24, $$25, $$26] <- index-search("btree_index_docid", 0, "test", "MyData", false, false, 0, 1, $$23, true, false, false)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              assign [$$23] <- [3]
                               -- ASSIGN  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-sidx-idxonly-01_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-sidx-idxonly-01_ps.plan
index ae40d81..84f11ca 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-sidx-idxonly-01_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-sidx-idxonly-01_ps.plan
@@ -1,65 +1,130 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$17] <- [{"pk": $$20, "sk": $$19}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$20(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$35
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      union ($$30, $$25, $$20) ($$32, $$24, $$19)
                       -- UNION_ALL  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          select (lt($$32, 3))
                           -- STREAM_SELECT  |PARTITIONED|
+                            project ([$$30, $$32])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$32] <- [$$31.getField(1)]
                               -- ASSIGN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.MyData.MyData)  |PARTITIONED|
+                                  unnest-map [$$30, $$31] <- index-search("MyData", 0, "test", "MyData", false, false, 1, $$25, 1, $$25, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      split ($$26)
                                       -- SPLIT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (test.MyData.btree_index_docid)  |PARTITIONED|
+                                          unnest-map [$$24, $$25, $$26] <- index-search("btree_index_docid", 0, "test", "MyData", false, false, 0, 1, $$23, true, false, false)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$23] <- [3]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$25, $$24])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              split ($$26)
                               -- SPLIT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.MyData.btree_index_docid)  |PARTITIONED|
+                                  unnest-map [$$24, $$25, $$26] <- index-search("btree_index_docid", 0, "test", "MyData", false, false, 0, 1, $$23, true, false, false)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      assign [$$23] <- [3]
                                       -- ASSIGN  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$35] <- [agg-range-map($$33, $$34)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$33, $$34] <- [agg-local-sampling($$20), agg-null-writer($$20)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$20])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                union ($$30, $$25, $$20) ($$32, $$24, $$19)
                                 -- UNION_ALL  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    select (lt($$32, 3))
                                     -- STREAM_SELECT  |PARTITIONED|
+                                      project ([$$30, $$32])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$32] <- [$$31.getField(1)]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (test.MyData.MyData)  |PARTITIONED|
+                                            unnest-map [$$30, $$31] <- index-search("MyData", 0, "test", "MyData", false, false, 1, $$25, 1, $$25, true, true, true)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                split ($$26)
                                                 -- SPLIT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (test.MyData.btree_index_docid)  |PARTITIONED|
+                                                    unnest-map [$$24, $$25, $$26] <- index-search("btree_index_docid", 0, "test", "MyData", false, false, 0, 1, $$23, true, false, false)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        assign [$$23] <- [3]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$25, $$24])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        split ($$26)
                                         -- SPLIT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (test.MyData.btree_index_docid)  |PARTITIONED|
+                                            unnest-map [$$24, $$25, $$26] <- index-search("btree_index_docid", 0, "test", "MyData", false, false, 0, 1, $$23, true, false, false)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$23] <- [3]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-sidx-idxonly-10.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-sidx-idxonly-10.plan
index 2dcfdd2..79c4a4d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-sidx-idxonly-10.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-sidx-idxonly-10.plan
@@ -1,35 +1,70 @@
+distribute result [$$70]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    aggregate [$$70] <- [agg-sql-sum($$77)]
     -- AGGREGATE  |UNPARTITIONED|
+      exchange
       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+        aggregate [$$77] <- [agg-sql-count(1)]
         -- AGGREGATE  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            union
             -- UNION_ALL  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(ge($$92, 0), lt($$92, 1000000), lt($$93, date: { 2002-11-09 }), ge($$93, date: { 1997-05-19 })))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$92, $$93])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$92, $$93] <- [$$69.getField(10), $$69.getField(6)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$69])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$69] <- [$$91.getField(12)]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$91])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- BTREE_SEARCH (twitter.ds_tweet.ds_tweet)  |PARTITIONED|
+                                unnest-map [$$90, $$91] <- index-search("ds_tweet", 0, "twitter", "ds_tweet", false, false, 1, $$84, 1, $$84, true, true, true)
+                                -- BTREE_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    split ($$85)
                                     -- SPLIT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (twitter.ds_tweet.create_at_status_count_idx)  |PARTITIONED|
+                                        unnest-map [$$82, $$83, $$84, $$85] <- index-search("create_at_status_count_idx", 0, "twitter", "ds_tweet", false, false, 2, $$78, $$79, 2, $$80, $$81, true, true, false)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            assign [$$78, $$79, $$80, $$81] <- [date: { 1997-05-19 }, 0, date: { 2002-11-09 }, 1000000]
                                             -- ASSIGN  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(ge($$83, 0), lt($$83, 1000000), lt($$82, date: { 2002-11-09 }), ge($$82, date: { 1997-05-19 })))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$82, $$83])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        split ($$85)
                         -- SPLIT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (twitter.ds_tweet.create_at_status_count_idx)  |PARTITIONED|
+                            unnest-map [$$82, $$83, $$84, $$85] <- index-search("create_at_status_count_idx", 0, "twitter", "ds_tweet", false, false, 2, $$78, $$79, 2, $$80, $$81, true, true, false)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                assign [$$78, $$79, $$80, $$81] <- [date: { 1997-05-19 }, 0, date: { 2002-11-09 }, 1000000]
                                 -- ASSIGN  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-ternary-inlj/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-ternary-inlj/query1.plan
index 671d511..16f36e4 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-ternary-inlj/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-ternary-inlj/query1.plan
@@ -1,35 +1,70 @@
+distribute result [$$61]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$61])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$61] <- [{"$1": $$67}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$67] <- [agg-sql-sum($$69)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$69] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (eq($$63, $$B.getField("k")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$63, $$B])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- BTREE_SEARCH (TestDataverse.IndexDatasetB.IndexDatasetB)  |PARTITIONED|
+                    unnest-map [$$65, $$B] <- index-search("IndexDatasetB", 0, "TestDataverse", "IndexDatasetB", true, false, 1, $$73, 1, $$73, true, true, true)
+                    -- BTREE_SEARCH  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        order (ASC, $$73)
                         -- STABLE_SORT [$$73(ASC)]  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$63, $$73])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- BTREE_SEARCH (TestDataverse.IndexDatasetB.indexB)  |PARTITIONED|
+                                unnest-map [$$72, $$73] <- index-search("indexB", 0, "TestDataverse", "IndexDatasetB", true, true, 1, $$63, 1, $$63, true, true, true)
+                                -- BTREE_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    project ([$$63])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      select (eq($$63, $$A.getField("k")))
                                       -- STREAM_SELECT  |PARTITIONED|
+                                        project ([$$63, $$A])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (TestDataverse.IndexDatasetA.IndexDatasetA)  |PARTITIONED|
+                                            unnest-map [$$64, $$A] <- index-search("IndexDatasetA", 0, "TestDataverse", "IndexDatasetA", true, false, 1, $$71, 1, $$71, true, true, true)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                order (ASC, $$71)
                                                 -- STABLE_SORT [$$71(ASC)]  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$$63, $$71])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- BTREE_SEARCH (TestDataverse.IndexDatasetA.indexA)  |PARTITIONED|
+                                                        unnest-map [$$70, $$71] <- index-search("indexA", 0, "TestDataverse", "IndexDatasetA", true, true, 1, $$63, 1, $$63, true, true, true)
+                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                          exchange
                                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                            project ([$$63])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- DATASOURCE_SCAN (TestDataverse.ProbeDataset)  |PARTITIONED|
+                                                                data-scan []<-[$$63, $$P] <- TestDataverse.ProbeDataset
+                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                                                    empty-tuple-source
+                                                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-ternary-inlj/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-ternary-inlj/query2.plan
index c0f794e..e27fe7b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-ternary-inlj/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-ternary-inlj/query2.plan
@@ -1,37 +1,74 @@
+distribute result [$$61]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$61])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$61] <- [{"$1": $$67}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$67] <- [agg-sql-sum($$69)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$69] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (eq($$62, $$B.getField("k")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$62, $$B])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- BTREE_SEARCH (TestDataverse.IndexDatasetB.IndexDatasetB)  |PARTITIONED|
+                    unnest-map [$$65, $$B] <- index-search("IndexDatasetB", 0, "TestDataverse", "IndexDatasetB", true, false, 1, $$73, 1, $$73, true, true, true)
+                    -- BTREE_SEARCH  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        order (ASC, $$73)
                         -- STABLE_SORT [$$73(ASC)]  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$62, $$73])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- BTREE_SEARCH (TestDataverse.IndexDatasetB.indexB)  |PARTITIONED|
+                                unnest-map [$$72, $$73] <- index-search("indexB", 0, "TestDataverse", "IndexDatasetB", true, true, 1, $$62, 1, $$62, true, true, true)
+                                -- BTREE_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    project ([$$62])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      select (eq($$62, $$A.getField("k")))
                                       -- STREAM_SELECT  |PARTITIONED|
+                                        project ([$$62, $$A])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (TestDataverse.IndexDatasetA.IndexDatasetA)  |PARTITIONED|
+                                            unnest-map [$$64, $$A] <- index-search("IndexDatasetA", 0, "TestDataverse", "IndexDatasetA", true, false, 1, $$71, 1, $$71, true, true, true)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                order (ASC, $$71)
                                                 -- STABLE_SORT [$$71(ASC)]  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$$62, $$71])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- BTREE_SEARCH (TestDataverse.IndexDatasetA.indexA)  |PARTITIONED|
+                                                        unnest-map [$$70, $$71] <- index-search("indexA", 0, "TestDataverse", "IndexDatasetA", true, true, 1, $$62, 1, $$62, true, true, true)
+                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                          exchange
                                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                            project ([$$62])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$62] <- [$$P.getField(1)]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                project ([$$P])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (TestDataverse.ProbeDataset)  |PARTITIONED|
+                                                                    data-scan []<-[$$63, $$P] <- TestDataverse.ProbeDataset
+                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                                                        empty-tuple-source
+                                                                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-ternary-inlj/query3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-ternary-inlj/query3.plan
index b94c26d..fed008c 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-ternary-inlj/query3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-ternary-inlj/query3.plan
@@ -1,49 +1,98 @@
+distribute result [$$75]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$75])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$75] <- [{"$1": $$82}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$82] <- [agg-sql-sum($$85)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$85] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (eq($$76, $$C.getField("k")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$76, $$C])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- BTREE_SEARCH (TestDataverse.IndexDatasetC.IndexDatasetC)  |PARTITIONED|
+                    unnest-map [$$80, $$C] <- index-search("IndexDatasetC", 0, "TestDataverse", "IndexDatasetC", true, false, 1, $$91, 1, $$91, true, true, true)
+                    -- BTREE_SEARCH  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        order (ASC, $$91)
                         -- STABLE_SORT [$$91(ASC)]  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$76, $$91])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- BTREE_SEARCH (TestDataverse.IndexDatasetC.indexC)  |PARTITIONED|
+                                unnest-map [$$90, $$91] <- index-search("indexC", 0, "TestDataverse", "IndexDatasetC", true, true, 1, $$76, 1, $$76, true, true, true)
+                                -- BTREE_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    project ([$$76])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      select (eq($$76, $$B.getField("k")))
                                       -- STREAM_SELECT  |PARTITIONED|
+                                        project ([$$76, $$B])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (TestDataverse.IndexDatasetB.IndexDatasetB)  |PARTITIONED|
+                                            unnest-map [$$79, $$B] <- index-search("IndexDatasetB", 0, "TestDataverse", "IndexDatasetB", true, false, 1, $$89, 1, $$89, true, true, true)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                order (ASC, $$89)
                                                 -- STABLE_SORT [$$89(ASC)]  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$$76, $$89])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- BTREE_SEARCH (TestDataverse.IndexDatasetB.indexB)  |PARTITIONED|
+                                                        unnest-map [$$88, $$89] <- index-search("indexB", 0, "TestDataverse", "IndexDatasetB", true, true, 1, $$76, 1, $$76, true, true, true)
+                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                          exchange
                                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                            project ([$$76])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              select (eq($$76, $$A.getField("k")))
                                                               -- STREAM_SELECT  |PARTITIONED|
+                                                                project ([$$76, $$A])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- BTREE_SEARCH (TestDataverse.IndexDatasetA.IndexDatasetA)  |PARTITIONED|
+                                                                    unnest-map [$$78, $$A] <- index-search("IndexDatasetA", 0, "TestDataverse", "IndexDatasetA", true, false, 1, $$87, 1, $$87, true, true, true)
+                                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        order (ASC, $$87)
                                                                         -- STABLE_SORT [$$87(ASC)]  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            project ([$$76, $$87])
                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                -- BTREE_SEARCH (TestDataverse.IndexDatasetA.indexA)  |PARTITIONED|
+                                                                                unnest-map [$$86, $$87] <- index-search("indexA", 0, "TestDataverse", "IndexDatasetA", true, true, 1, $$76, 1, $$76, true, true, true)
+                                                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                    project ([$$76])
                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                      assign [$$76] <- [$$P.getField(1)]
                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                        project ([$$P])
                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                            -- DATASOURCE_SCAN (TestDataverse.ProbeDataset)  |PARTITIONED|
+                                                                                            data-scan []<-[$$77, $$P] <- TestDataverse.ProbeDataset
+                                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                              exchange
                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                                                                                empty-tuple-source
+                                                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-ternary-inlj/query4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-ternary-inlj/query4.plan
index 4e1a931..05db8a7 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-ternary-inlj/query4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/btree-ternary-inlj/query4.plan
@@ -1,32 +1,64 @@
+distribute result [$$66]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$66])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$66] <- [{"$1": $$71}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$71] <- [agg-sql-sum($$76)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$76] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                join (eq($$70, $$57))
                 -- HYBRID_HASH_JOIN [$$57][$$70]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$57])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (tpcds.customer_address.customer_address)  |PARTITIONED|
+                        unnest-map [$$69, $$ca] <- index-search("customer_address", 0, "tpcds", "customer_address", true, true, 1, $$74, 1, $$74, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$74)
                             -- STABLE_SORT [$$74(ASC)]  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$74]  |PARTITIONED|
+                                project ([$$74, $$57])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- BTREE_SEARCH (tpcds.customer_demographics.customer_demographics)  |PARTITIONED|
+                                    unnest-map [$$68, $$cd2] <- index-search("customer_demographics", 0, "tpcds", "customer_demographics", true, true, 1, $$72, 1, $$72, true, true, true)
+                                    -- BTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        order (ASC, $$72)
                                         -- STABLE_SORT [$$72(ASC)]  |PARTITIONED|
+                                          exchange
                                           -- HASH_PARTITION_EXCHANGE [$$72]  |PARTITIONED|
+                                            project ([$$74, $$57, $$72])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$74, $$57, $$72] <- [$$c.getField(4), $$c.getField(12), $$c.getField(2)]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$c])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (tpcds.customer)  |PARTITIONED|
+                                                    data-scan []<-[$$67, $$c] <- tpcds.customer
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    unnest $$70 <- scan-collection(array: [ 4, 5 ])
                     -- UNNEST  |UNPARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q1.plan
index 5eee969..584200b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q1.plan
@@ -1,29 +1,52 @@
+distribute result [$$91]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$91])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$91] <- [{"ol_number": $$ol_number, "sum_qty": $$95, "sum_amount": $$96, "avg_qty": $$97, "avg_amount": $$98, "COUNT_order": $$99}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$ol_number(ASC) ]  |PARTITIONED|
-          -- SORT_GROUP_BY[$$107]  |PARTITIONED|
-                  {
+          group by ([$$ol_number := $$107]) decor ([]) {
+                    aggregate [$$95, $$96, $$97, $$98, $$99] <- [agg-global-sql-sum($$102), agg-global-sql-sum($$103), agg-global-sql-avg($$104), agg-global-sql-avg($$105), agg-sql-sum($$106)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- SORT_GROUP_BY[$$107]  |PARTITIONED|
+            exchange
             -- HASH_PARTITION_EXCHANGE [$$107]  |PARTITIONED|
-              -- SORT_GROUP_BY[$$92]  |PARTITIONED|
-                      {
+              group by ([$$107 := $$92]) decor ([]) {
+                        aggregate [$$102, $$103, $$104, $$105, $$106] <- [agg-local-sql-sum($$71), agg-local-sql-sum($$76), agg-local-sql-avg($$71), agg-local-sql-avg($$76), agg-sql-count(1)]
                         -- AGGREGATE  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SORT_GROUP_BY[$$92]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$71, $$76, $$92])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    select (gt($$ol.getField("ol_delivery_d"), "2014-07-01 00:00:00"))
                     -- STREAM_SELECT  |PARTITIONED|
+                      assign [$$76, $$71, $$92] <- [$$ol.getField("ol_amount"), $$ol.getField("ol_quantity"), $$ol.getField("ol_number")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$ol])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          unnest $$ol <- scan-collection($$100)
                           -- UNNEST  |PARTITIONED|
+                            project ([$$100])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$100] <- [$$o.getField("o_orderline")]
                               -- ASSIGN  |PARTITIONED|
+                                project ([$$o])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                    data-scan []<-[$$94, $$o] <- test.orders
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q10.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q10.plan
index 7cc19d7..21f93be 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q10.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q10.plan
@@ -1,59 +1,112 @@
+distribute result [$$148]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    limit 20
     -- STREAM_LIMIT  |UNPARTITIONED|
+      project ([$$148])
       -- STREAM_PROJECT  |PARTITIONED|
+        assign [$$148] <- [{"c_id": $$c_id, "c_last": $$c_last, "revenue": $$164, "c_city": $$c_city, "c_phone": $$c_phone, "n_name": $$n_name}]
         -- ASSIGN  |PARTITIONED|
+          exchange
           -- SORT_MERGE_EXCHANGE [$$164(DESC) ]  |PARTITIONED|
+            limit 20
             -- STREAM_LIMIT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (topK: 20) (DESC, $$164)
                 -- STABLE_SORT [topK: 20] [$$164(DESC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- SORT_GROUP_BY[$$171, $$172, $$173, $$174, $$175]  |PARTITIONED|
-                            {
+                    group by ([$$c_id := $$171; $$c_last := $$172; $$c_city := $$173; $$c_phone := $$174; $$n_name := $$175]) decor ([]) {
+                              aggregate [$$164] <- [agg-global-sql-sum($$170)]
                               -- AGGREGATE  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                            }
+                           }
+                    -- SORT_GROUP_BY[$$171, $$172, $$173, $$174, $$175]  |PARTITIONED|
+                      exchange
                       -- HASH_PARTITION_EXCHANGE [$$171, $$172, $$173, $$174, $$175]  |PARTITIONED|
-                        -- SORT_GROUP_BY[$$155, $$150, $$151, $$152, $$153]  |PARTITIONED|
-                                {
+                        group by ([$$171 := $$155; $$172 := $$150; $$173 := $$151; $$174 := $$152; $$175 := $$153]) decor ([]) {
+                                  aggregate [$$170] <- [agg-local-sql-sum($$145)]
                                   -- AGGREGATE  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                }
+                               }
+                        -- SORT_GROUP_BY[$$155, $$150, $$151, $$152, $$153]  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$145, $$155, $$150, $$151, $$152, $$153])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                join (and(eq($$155, $$159), eq($$160, $$161), eq($$162, $$163)))
                                 -- HYBRID_HASH_JOIN [$$155, $$160, $$162][$$159, $$161, $$163]  |PARTITIONED|
+                                  exchange
                                   -- HASH_PARTITION_EXCHANGE [$$155, $$160, $$162]  |PARTITIONED|
+                                    project ([$$155, $$150, $$151, $$152, $$153, $$160, $$162])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        join (eq($$165, $$166))
                                         -- HYBRID_HASH_JOIN [$$165][$$166]  |PARTITIONED|
+                                          exchange
                                           -- HASH_PARTITION_EXCHANGE [$$165]  |PARTITIONED|
+                                            project ([$$153, $$165])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$153, $$165] <- [$$n.getField("n_name"), $$n.getField("n_nationkey")]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$n])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (test.nation)  |PARTITIONED|
+                                                    data-scan []<-[$$156, $$n] <- test.nation
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                          exchange
                                           -- HASH_PARTITION_EXCHANGE [$$166]  |PARTITIONED|
+                                            project ([$$155, $$150, $$151, $$152, $$160, $$162, $$166])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$166, $$152, $$151, $$150, $$162, $$160, $$155] <- [get-item(string-to-codepoint($$c.getField("c_state")), 0), $$c.getField("c_phone"), $$c.getField("c_city"), $$c.getField("c_last"), $$c.getField("c_w_id"), $$c.getField("c_d_id"), $$c.getField("c_id")]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$c])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (test.customer)  |PARTITIONED|
+                                                    data-scan []<-[$$157, $$c] <- test.customer
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                  exchange
                                   -- HASH_PARTITION_EXCHANGE [$$159, $$161, $$163]  |PARTITIONED|
+                                    project ([$$145, $$159, $$161, $$163])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$145] <- [$$ol.getField("ol_amount")]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$163, $$161, $$159, $$ol])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          unnest $$ol <- scan-collection($$168)
                                           -- UNNEST  |PARTITIONED|
+                                            project ([$$163, $$161, $$159, $$168])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              select (and(lt($$154, "2016-01-01 00:00:00.000000"), ge($$154, "2015-10-01 00:00:00.000000")))
                                               -- STREAM_SELECT  |PARTITIONED|
+                                                project ([$$163, $$161, $$159, $$154, $$168])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$163, $$161, $$159, $$154, $$168] <- [$$o.getField("o_w_id"), $$o.getField("o_d_id"), $$o.getField("o_c_id"), $$o.getField("o_entry_d"), $$o.getField("o_orderline")]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$o])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                                        data-scan []<-[$$158, $$o] <- test.orders
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q11.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q11.plan
index 5133ed2..557531f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q11.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q11.plan
@@ -1,119 +1,232 @@
+distribute result [$$166]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$166])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$166] <- [{"s_i_id": $$s_i_id, "ordercount": $$178}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$178(DESC) ]  |PARTITIONED|
+          order (DESC, $$178)
           -- STABLE_SORT [$$178(DESC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$s_i_id, $$178])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  join (gt($$177, $$189))
                   -- NESTED_LOOP  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- SORT_GROUP_BY[$$204]  |PARTITIONED|
-                              {
+                      group by ([$$s_i_id := $$204]) decor ([]) {
+                                aggregate [$$177, $$178] <- [agg-global-sql-sum($$202), agg-global-sql-sum($$203)]
                                 -- AGGREGATE  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- SORT_GROUP_BY[$$204]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$204]  |PARTITIONED|
-                          -- SORT_GROUP_BY[$$168]  |PARTITIONED|
-                                  {
+                          group by ([$$204 := $$168]) decor ([]) {
+                                    aggregate [$$202, $$203] <- [agg-local-sql-sum($$132), agg-local-sql-sum($$132)]
                                     -- AGGREGATE  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                  }
+                                 }
+                          -- SORT_GROUP_BY[$$168]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$132, $$168])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  join (eq($$175, $$176))
                                   -- HYBRID_HASH_JOIN [$$176][$$175]  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$176]  |PARTITIONED|
+                                      project ([$$176])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          join (eq($$187, $$188))
                                           -- HYBRID_HASH_JOIN [$$188][$$187]  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$188])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$188] <- [$$193]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    replicate
                                                     -- REPLICATE  |PARTITIONED|
+                                                      exchange
                                                       -- HASH_PARTITION_EXCHANGE [$$193]  |PARTITIONED|
+                                                        project ([$$193])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          select (eq($$181.getField("n_name"), "Germany"))
                                                           -- STREAM_SELECT  |PARTITIONED|
+                                                            assign [$$193] <- [$$181.getField("n_nationkey")]
                                                             -- ASSIGN  |PARTITIONED|
+                                                              project ([$$181])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- DATASOURCE_SCAN (test.nation)  |PARTITIONED|
+                                                                  data-scan []<-[$$186, $$181] <- test.nation
+                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      empty-tuple-source
                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$176, $$187])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$176, $$187] <- [$$191, $$192]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    replicate
                                                     -- REPLICATE  |PARTITIONED|
+                                                      exchange
                                                       -- HASH_PARTITION_EXCHANGE [$$192]  |PARTITIONED|
+                                                        project ([$$191, $$192])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$191, $$192] <- [$$182.getField("su_suppkey"), $$182.getField("su_nationkey")]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            project ([$$182])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- DATASOURCE_SCAN (test.supplier)  |PARTITIONED|
+                                                                data-scan []<-[$$185, $$182] <- test.supplier
+                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    empty-tuple-source
                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$175]  |PARTITIONED|
+                                      project ([$$132, $$168, $$175])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$175] <- [numeric-mod(numeric-multiply($$s.getField("s_w_id"), $$168), 10000)]
                                         -- ASSIGN  |PARTITIONED|
+                                          assign [$$168, $$132] <- [$$s.getField("s_i_id"), $$s.getField("s_order_cnt")]
                                           -- ASSIGN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              replicate
                                               -- REPLICATE  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  project ([$$s])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.stock)  |PARTITIONED|
+                                                      data-scan []<-[$$171, $$s] <- test.stock
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                    exchange
                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                      project ([$$189])
                       -- STREAM_PROJECT  |UNPARTITIONED|
+                        assign [$$189] <- [get-item($$157, 0)]
                         -- ASSIGN  |UNPARTITIONED|
+                          aggregate [$$157] <- [listify($$156)]
                           -- AGGREGATE  |UNPARTITIONED|
+                            project ([$$156])
                             -- STREAM_PROJECT  |UNPARTITIONED|
+                              assign [$$156] <- [numeric-multiply($$201, 5.0E-5)]
                               -- ASSIGN  |UNPARTITIONED|
+                                aggregate [$$201] <- [agg-global-sql-sum($$205)]
                                 -- AGGREGATE  |UNPARTITIONED|
+                                  exchange
                                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                                    aggregate [$$205] <- [agg-local-sql-sum($$153)]
                                     -- AGGREGATE  |PARTITIONED|
+                                      project ([$$153])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          join (eq($$190, $$191))
                                           -- HYBRID_HASH_JOIN [$$191][$$190]  |PARTITIONED|
+                                            exchange
                                             -- HASH_PARTITION_EXCHANGE [$$191]  |PARTITIONED|
+                                              project ([$$191])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  join (eq($$192, $$193))
                                                   -- HYBRID_HASH_JOIN [$$193][$$192]  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      replicate
                                                       -- REPLICATE  |PARTITIONED|
+                                                        exchange
                                                         -- HASH_PARTITION_EXCHANGE [$$193]  |PARTITIONED|
+                                                          project ([$$193])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            select (eq($$181.getField("n_name"), "Germany"))
                                                             -- STREAM_SELECT  |PARTITIONED|
+                                                              assign [$$193] <- [$$181.getField("n_nationkey")]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                project ([$$181])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (test.nation)  |PARTITIONED|
+                                                                    data-scan []<-[$$186, $$181] <- test.nation
+                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        empty-tuple-source
                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      replicate
                                                       -- REPLICATE  |PARTITIONED|
+                                                        exchange
                                                         -- HASH_PARTITION_EXCHANGE [$$192]  |PARTITIONED|
+                                                          project ([$$191, $$192])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            assign [$$191, $$192] <- [$$182.getField("su_suppkey"), $$182.getField("su_nationkey")]
                                                             -- ASSIGN  |PARTITIONED|
+                                                              project ([$$182])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- DATASOURCE_SCAN (test.supplier)  |PARTITIONED|
+                                                                  data-scan []<-[$$185, $$182] <- test.supplier
+                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      empty-tuple-source
                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                            exchange
                                             -- HASH_PARTITION_EXCHANGE [$$190]  |PARTITIONED|
+                                              project ([$$153, $$190])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$190, $$153] <- [numeric-mod(numeric-multiply($$183.getField("s_w_id"), $$183.getField("s_i_id")), 10000), $$183.getField("s_order_cnt")]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  project ([$$183])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    assign [$$183] <- [$$s]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        replicate
                                                         -- REPLICATE  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            project ([$$s])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- DATASOURCE_SCAN (test.stock)  |PARTITIONED|
+                                                                data-scan []<-[$$171, $$s] <- test.stock
+                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    empty-tuple-source
                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q12.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q12.plan
index 1c561d0..f0c4e02 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q12.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q12.plan
@@ -1,29 +1,52 @@
+distribute result [$$84]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$84])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$84] <- [{"o_ol_cnt": $$o_ol_cnt, "high_line_COUNT": $$89, "low_line_COUNT": $$90}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$o_ol_cnt(ASC) ]  |PARTITIONED|
-          -- SORT_GROUP_BY[$$96]  |PARTITIONED|
-                  {
+          group by ([$$o_ol_cnt := $$96]) decor ([]) {
+                    aggregate [$$89, $$90] <- [agg-global-sql-sum($$94), agg-global-sql-sum($$95)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- SORT_GROUP_BY[$$96]  |PARTITIONED|
+            exchange
             -- HASH_PARTITION_EXCHANGE [$$96]  |PARTITIONED|
-              -- SORT_GROUP_BY[$$85]  |PARTITIONED|
-                      {
+              group by ([$$96 := $$85]) decor ([]) {
+                        aggregate [$$94, $$95] <- [agg-local-sql-sum(switch-case(true, or(eq($$88, 1), eq($$88, 2)), 1, 0)), agg-local-sql-sum(switch-case(true, and(neq($$88, 1), neq($$88, 2)), 1, 0))]
                         -- AGGREGATE  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SORT_GROUP_BY[$$85]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$88, $$85])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    select (and(le($$o.getField("o_entry_d"), $$86), ge($$86, "2016-01-01 00:00:00.000000"), lt($$86, "2017-01-01 00:00:00.000000")))
                     -- STREAM_SELECT  |PARTITIONED|
+                      project ([$$o, $$85, $$88, $$86])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$86] <- [$$ol.getField("ol_delivery_d")]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$o, $$85, $$88, $$ol])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            unnest $$ol <- scan-collection($$91)
                             -- UNNEST  |PARTITIONED|
+                              assign [$$85, $$91, $$88] <- [$$o.getField("o_ol_cnt"), $$o.getField("o_orderline"), $$o.getField("o_carrier_id")]
                               -- ASSIGN  |PARTITIONED|
+                                project ([$$o])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                    data-scan []<-[$$87, $$o] <- test.orders
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q13.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q13.plan
index b33dc89..ee8e8b0 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q13.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q13.plan
@@ -1,53 +1,94 @@
+distribute result [$$119]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$119])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$119] <- [{"c_count": $$c_count, "custdist": $$125}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$125(DESC), $$c_count(DESC) ]  |PARTITIONED|
+          order (DESC, $$125) (DESC, $$c_count)
           -- STABLE_SORT [$$125(DESC), $$c_count(DESC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- SORT_GROUP_BY[$$139]  |PARTITIONED|
-                      {
+              group by ([$$c_count := $$139]) decor ([]) {
+                        aggregate [$$125] <- [agg-sql-sum($$138)]
                         -- AGGREGATE  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SORT_GROUP_BY[$$139]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$139]  |PARTITIONED|
-                  -- SORT_GROUP_BY[$$124]  |PARTITIONED|
-                          {
+                  group by ([$$139 := $$124]) decor ([]) {
+                            aggregate [$$138] <- [agg-sql-count(1)]
                             -- AGGREGATE  |LOCAL|
+                              nested tuple source
                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                         }
+                  -- SORT_GROUP_BY[$$124]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$124])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- SORT_GROUP_BY[$$137]  |PARTITIONED|
-                                  {
+                          group by ([$$c_id := $$137]) decor ([]) {
+                                    aggregate [$$124] <- [agg-sql-sum($$136)]
                                     -- AGGREGATE  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                  }
+                                 }
+                          -- SORT_GROUP_BY[$$137]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$137]  |PARTITIONED|
-                              -- SORT_GROUP_BY[$$126]  |PARTITIONED|
-                                      {
+                              group by ([$$137 := $$126]) decor ([]) {
+                                        aggregate [$$136] <- [agg-sql-count($$108)]
                                         -- AGGREGATE  |LOCAL|
+                                          nested tuple source
                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                      }
+                                     }
+                              -- SORT_GROUP_BY[$$126]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$108, $$126])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      left outer join (and(eq($$126, $$127), eq($$128, $$129), eq($$130, $$131)))
                                       -- HYBRID_HASH_JOIN [$$126, $$128, $$130][$$127, $$129, $$131]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$126, $$128, $$130]  |PARTITIONED|
+                                          project ([$$126, $$128, $$130])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$130, $$126, $$128] <- [$$c.getField("c_d_id"), $$c.getField("c_id"), $$c.getField("c_w_id")]
                                             -- ASSIGN  |PARTITIONED|
+                                              project ([$$c])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- DATASOURCE_SCAN (test.customer)  |PARTITIONED|
+                                                  data-scan []<-[$$122, $$c] <- test.customer
+                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$127, $$129, $$131]  |PARTITIONED|
+                                          project ([$$108, $$127, $$129, $$131])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            select (gt($$o.getField("o_carrier_id"), 8))
                                             -- STREAM_SELECT  |PARTITIONED|
+                                              assign [$$131, $$129, $$127, $$108] <- [$$o.getField("o_d_id"), $$o.getField("o_w_id"), $$o.getField("o_c_id"), $$o.getField("o_id")]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$o])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                                    data-scan []<-[$$123, $$o] <- test.orders
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q14.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q14.plan
index 6dda602..d3e628a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q14.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q14.plan
@@ -1,34 +1,68 @@
+distribute result [$$78]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$78])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$78] <- [{"promo_revenue": numeric-divide(numeric-multiply(100.0, $$85), numeric-add(1, $$86))}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$85, $$86] <- [agg-global-sql-sum($$91), agg-global-sql-sum($$92)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$91, $$92] <- [agg-local-sql-sum($$69), agg-local-sql-sum($$82)]
             -- AGGREGATE  |PARTITIONED|
+              project ([$$69, $$82])
               -- STREAM_PROJECT  |PARTITIONED|
+                assign [$$69] <- [switch-case(true, like($$88, "pr%"), $$82, 0)]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$88, $$82])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (eq($$83, $$84))
                       -- HYBRID_HASH_JOIN [$$84][$$83]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$84]  |PARTITIONED|
+                          project ([$$88, $$84])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$88, $$84] <- [$$i.getField("i_data"), $$i.getField("i_id")]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$i])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.item)  |PARTITIONED|
+                                  data-scan []<-[$$80, $$i] <- test.item
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$83]  |PARTITIONED|
+                          project ([$$82, $$83])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            select (and(ge($$79, "2017-09-01 00:00:00.000000"), lt($$79, "2017-10-01 00:00:00.000000")))
                             -- STREAM_SELECT  |PARTITIONED|
+                              project ([$$82, $$83, $$79])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$82, $$83, $$79] <- [$$ol.getField("ol_amount"), $$ol.getField("ol_i_id"), $$ol.getField("ol_delivery_d")]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$ol])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    unnest $$ol <- scan-collection($$87)
                                     -- UNNEST  |PARTITIONED|
+                                      project ([$$87])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$87] <- [$$o.getField("o_orderline")]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$o])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                              data-scan []<-[$$81, $$o] <- test.orders
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q15.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q15.plan
index 8da830c..175b5f4 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q15.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q15.plan
@@ -1,129 +1,246 @@
+distribute result [$$213]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$213])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$213] <- [{"su_suppkey": $$220, "su_name": $$262, "su_address": $$263, "su_phone": $$264, "total_revenue": $$221}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$220(ASC) ]  |PARTITIONED|
+          order (ASC, $$220)
           -- STABLE_SORT [$$220(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$220, $$262, $$263, $$264, $$221])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  join (eq($$220, $#1))
                   -- HYBRID_HASH_JOIN [$#1][$$220]  |PARTITIONED|
+                    exchange
                     -- HASH_PARTITION_EXCHANGE [$#1]  |PARTITIONED|
+                      project ([$$221, $#1])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          join (eq($$221, $$258))
                           -- HYBRID_HASH_JOIN [$$221][$$258]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$221]  |PARTITIONED|
+                              project ([$$221, $#1])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$221] <- [{"supplier_no": $#1, "total_rev": $$230}.getField("total_revenue")]
                                 -- ASSIGN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- SORT_GROUP_BY[$$270]  |PARTITIONED|
-                                            {
+                                    group by ([$#1 := $$270]) decor ([]) {
+                                              aggregate [$$230] <- [agg-global-sql-sum($$269)]
                                               -- AGGREGATE  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                            }
+                                           }
+                                    -- SORT_GROUP_BY[$$270]  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$270]  |PARTITIONED|
-                                        -- SORT_GROUP_BY[$$215]  |PARTITIONED|
-                                                {
+                                        group by ([$$270 := $$215]) decor ([]) {
+                                                  aggregate [$$269] <- [agg-local-sql-sum($$159)]
                                                   -- AGGREGATE  |LOCAL|
+                                                    nested tuple source
                                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                }
+                                               }
+                                        -- SORT_GROUP_BY[$$215]  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$159, $$215])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$215] <- [numeric-mod(numeric-multiply($$218, $$219), 10000)]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$218, $$219, $$159])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    join (and(eq($$252, $$219), eq($$253, $$218)))
                                                     -- HYBRID_HASH_JOIN [$$219, $$218][$$252, $$253]  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        project ([$$218, $$219])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$218, $$219] <- [$$240, $$241]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              replicate
                                                               -- REPLICATE  |PARTITIONED|
+                                                                exchange
                                                                 -- HASH_PARTITION_EXCHANGE [$$241, $$240]  |PARTITIONED|
+                                                                  project ([$$240, $$241])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    assign [$$241, $$240] <- [$$243.getField("s_i_id"), $$243.getField("s_w_id")]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      project ([$$243])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                          -- DATASOURCE_SCAN (test.stock)  |PARTITIONED|
+                                                                          data-scan []<-[$$248, $$243] <- test.stock
+                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              empty-tuple-source
                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                      exchange
                                                       -- HASH_PARTITION_EXCHANGE [$$252, $$253]  |PARTITIONED|
+                                                        project ([$$159, $$252, $$253])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          select (and(ge($$217, "2018-01-01 00:00:00.000000"), lt($$217, "2018-04-01 00:00:00.000000")))
                                                           -- STREAM_SELECT  |PARTITIONED|
+                                                            project ([$$159, $$253, $$252, $$217])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$159, $$253, $$252, $$217] <- [$$249, $$257, $$256, $$246]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  replicate
                                                                   -- REPLICATE  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      project ([$$249, $$257, $$256, $$246])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        assign [$$249, $$257, $$256, $$246] <- [$$245.getField("ol_amount"), $$245.getField("ol_supply_w_id"), $$245.getField("ol_i_id"), $$245.getField("ol_delivery_d")]
                                                                         -- ASSIGN  |PARTITIONED|
+                                                                          project ([$$245])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            unnest $$245 <- scan-collection($$260)
                                                                             -- UNNEST  |PARTITIONED|
+                                                                              project ([$$260])
                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                assign [$$260] <- [$$244.getField("o_orderline")]
                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                  project ([$$244])
                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                    exchange
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                      -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                                                                      data-scan []<-[$$247, $$244] <- test.orders
+                                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                        exchange
                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                          empty-tuple-source
                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$258]  |PARTITIONED|
+                              project ([$$258])
                               -- STREAM_PROJECT  |UNPARTITIONED|
+                                assign [$$258] <- [get-item($$203, 0)]
                                 -- ASSIGN  |UNPARTITIONED|
+                                  aggregate [$$203] <- [listify($$268)]
                                   -- AGGREGATE  |UNPARTITIONED|
+                                    aggregate [$$268] <- [agg-global-sql-max($$271)]
                                     -- AGGREGATE  |UNPARTITIONED|
+                                      exchange
                                       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                                        aggregate [$$271] <- [agg-local-sql-max($$200)]
                                         -- AGGREGATE  |PARTITIONED|
+                                          project ([$$200])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$200] <- [{"supplier_no": $$237, "total_rev": $$255}.getField("total_revenue")]
                                             -- ASSIGN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- SORT_GROUP_BY[$$273]  |PARTITIONED|
-                                                        {
+                                                group by ([$$237 := $$273]) decor ([]) {
+                                                          aggregate [$$255] <- [agg-global-sql-sum($$272)]
                                                           -- AGGREGATE  |LOCAL|
+                                                            nested tuple source
                                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                        }
+                                                       }
+                                                -- SORT_GROUP_BY[$$273]  |PARTITIONED|
+                                                  exchange
                                                   -- HASH_PARTITION_EXCHANGE [$$273]  |PARTITIONED|
-                                                    -- SORT_GROUP_BY[$$239]  |PARTITIONED|
-                                                            {
+                                                    group by ([$$273 := $$239]) decor ([]) {
+                                                              aggregate [$$272] <- [agg-local-sql-sum($$249)]
                                                               -- AGGREGATE  |LOCAL|
+                                                                nested tuple source
                                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                            }
+                                                           }
+                                                    -- SORT_GROUP_BY[$$239]  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        project ([$$249, $$239])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$239] <- [numeric-mod(numeric-multiply($$240, $$241), 10000)]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            project ([$$240, $$241, $$249])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                join (and(eq($$256, $$241), eq($$257, $$240)))
                                                                 -- HYBRID_HASH_JOIN [$$241, $$240][$$256, $$257]  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    replicate
                                                                     -- REPLICATE  |PARTITIONED|
+                                                                      exchange
                                                                       -- HASH_PARTITION_EXCHANGE [$$241, $$240]  |PARTITIONED|
+                                                                        project ([$$240, $$241])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          assign [$$241, $$240] <- [$$243.getField("s_i_id"), $$243.getField("s_w_id")]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            project ([$$243])
                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                -- DATASOURCE_SCAN (test.stock)  |PARTITIONED|
+                                                                                data-scan []<-[$$248, $$243] <- test.stock
+                                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    empty-tuple-source
                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                  exchange
                                                                   -- HASH_PARTITION_EXCHANGE [$$256, $$257]  |PARTITIONED|
+                                                                    project ([$$249, $$256, $$257])
                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                      select (and(lt($$246, "2018-04-01 00:00:00.000000"), ge($$246, "2018-01-01 00:00:00.000000")))
                                                                       -- STREAM_SELECT  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          replicate
                                                                           -- REPLICATE  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              project ([$$249, $$257, $$256, $$246])
                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                assign [$$249, $$257, $$256, $$246] <- [$$245.getField("ol_amount"), $$245.getField("ol_supply_w_id"), $$245.getField("ol_i_id"), $$245.getField("ol_delivery_d")]
                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                  project ([$$245])
                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                    unnest $$245 <- scan-collection($$260)
                                                                                     -- UNNEST  |PARTITIONED|
+                                                                                      project ([$$260])
                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                        assign [$$260] <- [$$244.getField("o_orderline")]
                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                          project ([$$244])
                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                            exchange
                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                              -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                                                                              data-scan []<-[$$247, $$244] <- test.orders
+                                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                exchange
                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                  empty-tuple-source
                                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                    exchange
                     -- HASH_PARTITION_EXCHANGE [$$220]  |PARTITIONED|
+                      project ([$$220, $$262, $$263, $$264])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$264, $$263, $$262, $$220] <- [$$su.getField("su_phone"), $$su.getField("su_address"), $$su.getField("su_name"), $$su.getField("su_suppkey")]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$su])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (test.supplier)  |PARTITIONED|
+                              data-scan []<-[$$224, $$su] <- test.supplier
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q16.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q16.plan
index 6abcb63..f202182 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q16.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q16.plan
@@ -1,65 +1,124 @@
+distribute result [$$120]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$120])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$120] <- [{"i_name": $$i_name, "brand": $#1, "i_price": $$i_price, "supplier_cnt": $$131}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$131(DESC) ]  |PARTITIONED|
+          order (DESC, $$131)
           -- STABLE_SORT [$$131(DESC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- PRE_CLUSTERED_GROUP_BY[$$121, $$122, $$123]  |PARTITIONED|
-                      {
+              group by ([$$i_name := $$121; $#1 := $$122; $$i_price := $$123]) decor ([]) {
+                        aggregate [$$131] <- [agg-sql-count($$142)]
                         -- AGGREGATE  |LOCAL|
+                          distinct ([$$142])
                           -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                            order (ASC, $$142)
                             -- MICRO_STABLE_SORT [$$142(ASC)]  |LOCAL|
+                              assign [$$142] <- [numeric-mod(numeric-multiply($$135, $$136), 10000)]
                               -- ASSIGN  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- PRE_CLUSTERED_GROUP_BY[$$121, $$122, $$123]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  order (ASC, $$121) (ASC, $$122) (ASC, $$123)
                   -- STABLE_SORT [$$121(ASC), $$122(ASC), $$123(ASC)]  |PARTITIONED|
+                    exchange
                     -- HASH_PARTITION_EXCHANGE [$$121, $$122, $$123]  |PARTITIONED|
+                      project ([$$135, $$136, $$121, $$122, $$123])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$122] <- [substring1($$124, 1, 3)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$121, $$123, $$124, $$136, $$135])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            select ($$103)
                             -- STREAM_SELECT  |PARTITIONED|
+                              project ([$$103, $$121, $$123, $$124, $$136, $$135])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- PRE_CLUSTERED_GROUP_BY[$$125, $$126]  |PARTITIONED|
-                                          {
+                                  group by ([$$138 := $$125; $$139 := $$126]) decor ([$$121; $$123; $$124; $$136 := $$130; $$135 := $$133]) {
+                                            aggregate [$$103] <- [empty-stream()]
                                             -- AGGREGATE  |LOCAL|
+                                              select (not(is-missing($$137)))
                                               -- STREAM_SELECT  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                         }
+                                  -- PRE_CLUSTERED_GROUP_BY[$$125, $$126]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$125) (ASC, $$126)
                                       -- STABLE_SORT [$$125(ASC), $$126(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$125, $$126]  |PARTITIONED|
+                                          project ([$$121, $$123, $$124, $$137, $$125, $$126, $$130, $$133])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              left outer join (not(if-missing-or-null(neq(numeric-mod(numeric-multiply($$133, $$130), 10000), $$97), false)))
                                               -- NESTED_LOOP  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  project ([$$121, $$123, $$124, $$125, $$126, $$130, $$133])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      join (eq($$129, $$130))
                                                       -- HYBRID_HASH_JOIN [$$130][$$129]  |PARTITIONED|
+                                                        exchange
                                                         -- HASH_PARTITION_EXCHANGE [$$130]  |PARTITIONED|
+                                                          project ([$$125, $$130, $$133])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            assign [$$130, $$133] <- [$$s.getField("s_i_id"), $$s.getField("s_w_id")]
                                                             -- ASSIGN  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- DATASOURCE_SCAN (test.stock)  |PARTITIONED|
+                                                                data-scan []<-[$$125, $$s] <- test.stock
+                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    empty-tuple-source
                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                        exchange
                                                         -- HASH_PARTITION_EXCHANGE [$$129]  |PARTITIONED|
+                                                          select (not(like($$124, "zz%")))
                                                           -- STREAM_SELECT  |PARTITIONED|
+                                                            project ([$$126, $$123, $$121, $$124, $$129])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$123, $$121, $$124, $$129] <- [$$i.getField("i_price"), $$i.getField("i_name"), $$i.getField("i_data"), $$i.getField("i_id")]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- DATASOURCE_SCAN (test.item)  |PARTITIONED|
+                                                                  data-scan []<-[$$126, $$i] <- test.item
+                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      empty-tuple-source
                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                exchange
                                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                  assign [$$137] <- [true]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$97])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      select (like($$su.getField("su_comment"), "%Customer%Complaints%"))
                                                       -- STREAM_SELECT  |PARTITIONED|
+                                                        assign [$$97] <- [$$su.getField("su_suppkey")]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          project ([$$su])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- DATASOURCE_SCAN (test.supplier)  |PARTITIONED|
+                                                              data-scan []<-[$$127, $$su] <- test.supplier
+                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  empty-tuple-source
                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q17.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q17.plan
index 8896e10..bbf241e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q17.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q17.plan
@@ -1,69 +1,132 @@
+distribute result [$$135]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$135])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$135] <- [{"AVG_yearly": numeric-divide($$146, 2.0)}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$146] <- [agg-global-sql-sum($$155)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$155] <- [agg-local-sql-sum($$132)]
             -- AGGREGATE  |PARTITIONED|
+              project ([$$132])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (lt($$141, $$145))
                 -- STREAM_SELECT  |PARTITIONED|
+                  project ([$$145, $$132, $$141])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (eq($$143, $$i_id))
                       -- HYBRID_HASH_JOIN [$$i_id][$$143]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- PRE_CLUSTERED_GROUP_BY[$$154]  |PARTITIONED|
-                                  {
+                          group by ([$$i_id := $$154]) decor ([]) {
+                                    aggregate [$$145] <- [agg-global-sql-avg($$153)]
                                     -- AGGREGATE  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                  }
+                                 }
+                          -- PRE_CLUSTERED_GROUP_BY[$$154]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- SORT_GROUP_BY[$$137]  |PARTITIONED|
-                                      {
+                              group by ([$$154 := $$137]) decor ([]) {
+                                        aggregate [$$153] <- [agg-local-sql-avg($$113)]
                                         -- AGGREGATE  |LOCAL|
+                                          nested tuple source
                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                      }
+                                     }
+                              -- SORT_GROUP_BY[$$137]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$113, $$137])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      join (eq($$147, $$137))
                                       -- HYBRID_HASH_JOIN [$$137][$$147]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$137]  |PARTITIONED|
+                                          project ([$$137])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            select (like($$i.getField("i_data"), "%b"))
                                             -- STREAM_SELECT  |PARTITIONED|
+                                              assign [$$137] <- [$$i.getField("i_id")]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$i])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (test.item)  |PARTITIONED|
+                                                    data-scan []<-[$$138, $$i] <- test.item
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$147]  |PARTITIONED|
+                                          project ([$$113, $$147])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$113, $$147] <- [$$ol1.getField("ol_quantity"), $$ol1.getField("ol_i_id")]
                                             -- ASSIGN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                replicate
                                                 -- REPLICATE  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$$ol1])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      unnest $$ol1 <- scan-collection($$149)
                                                       -- UNNEST  |PARTITIONED|
+                                                        project ([$$149])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$149] <- [$$o1.getField("o_orderline")]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            project ([$$o1])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                                                data-scan []<-[$$139, $$o1] <- test.orders
+                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    empty-tuple-source
                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$143]  |PARTITIONED|
+                          project ([$$132, $$141, $$143])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$132, $$143, $$141] <- [$$ol.getField("ol_amount"), $$ol.getField("ol_i_id"), $$ol.getField("ol_quantity")]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$ol])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$ol] <- [$$ol1]
                                 -- ASSIGN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    replicate
                                     -- REPLICATE  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$ol1])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          unnest $$ol1 <- scan-collection($$149)
                                           -- UNNEST  |PARTITIONED|
+                                            project ([$$149])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$149] <- [$$o1.getField("o_orderline")]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$o1])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                                    data-scan []<-[$$139, $$o1] <- test.orders
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q18.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q18.plan
index ad40849..6218a96 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q18.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q18.plan
@@ -1,50 +1,94 @@
+distribute result [$$158]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    limit 100
     -- STREAM_LIMIT  |UNPARTITIONED|
+      project ([$$158])
       -- STREAM_PROJECT  |PARTITIONED|
+        assign [$$158] <- [{"c_last": $$c_last, "o_id": $$c_id, "o_entry_d": $$o_entry_d, "o_ol_cnt": $$o_ol_cnt, "$1": $$181}]
         -- ASSIGN  |PARTITIONED|
+          project ([$$c_last, $$c_id, $$o_entry_d, $$o_ol_cnt, $$181])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- SORT_MERGE_EXCHANGE [$$182(DESC), $$o_entry_d(ASC) ]  |PARTITIONED|
+              limit 100
               -- STREAM_LIMIT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  order (topK: 100) (DESC, $$182) (ASC, $$o_entry_d)
                   -- STABLE_SORT [topK: 100] [$$182(DESC), $$o_entry_d(ASC)]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$c_last, $$c_id, $$o_entry_d, $$o_ol_cnt, $$181, $$182])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (gt($$180, 200))
                         -- STREAM_SELECT  |PARTITIONED|
+                          project ([$$180, $$181, $$182, $$c_id, $$c_last, $$o_entry_d, $$o_ol_cnt])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- SORT_GROUP_BY[$$188, $$189, $$190, $$191, $$192, $$193, $$194]  |PARTITIONED|
-                                      {
+                              group by ([$$o_id := $$188; $$o_w_id := $$189; $$o_d_id := $$190; $$c_id := $$191; $$c_last := $$192; $$o_entry_d := $$193; $$o_ol_cnt := $$194]) decor ([]) {
+                                        aggregate [$$180, $$181, $$182] <- [agg-global-sql-sum($$185), agg-global-sql-sum($$186), agg-global-sql-sum($$187)]
                                         -- AGGREGATE  |LOCAL|
+                                          nested tuple source
                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                      }
+                                     }
+                              -- SORT_GROUP_BY[$$188, $$189, $$190, $$191, $$192, $$193, $$194]  |PARTITIONED|
+                                exchange
                                 -- HASH_PARTITION_EXCHANGE [$$188, $$189, $$190, $$191, $$192, $$193, $$194]  |PARTITIONED|
-                                  -- SORT_GROUP_BY[$$164, $$172, $$173, $$174, $$168, $$169, $$170]  |PARTITIONED|
-                                          {
+                                  group by ([$$188 := $$164; $$189 := $$172; $$190 := $$173; $$191 := $$174; $$192 := $$168; $$193 := $$169; $$194 := $$170]) decor ([]) {
+                                            aggregate [$$185, $$186, $$187] <- [agg-local-sql-sum($$149), agg-local-sql-sum($$149), agg-local-sql-sum($$149)]
                                             -- AGGREGATE  |LOCAL|
+                                              nested tuple source
                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                         }
+                                  -- SORT_GROUP_BY[$$164, $$172, $$173, $$174, $$168, $$169, $$170]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$149, $$164, $$172, $$173, $$174, $$168, $$169, $$170])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          join (and(eq($$174, $$177), eq($$178, $$172), eq($$179, $$173)))
                                           -- HYBRID_HASH_JOIN [$$177, $$172, $$173][$$174, $$178, $$179]  |PARTITIONED|
+                                            exchange
                                             -- HASH_PARTITION_EXCHANGE [$$177, $$172, $$173]  |PARTITIONED|
+                                              project ([$$149, $$164, $$172, $$173, $$169, $$170, $$177])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$149] <- [$$ol.getField("ol_amount")]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  project ([$$170, $$169, $$164, $$177, $$172, $$173, $$ol])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    unnest $$ol <- scan-collection($$183)
                                                     -- UNNEST  |PARTITIONED|
+                                                      project ([$$170, $$169, $$164, $$177, $$172, $$173, $$183])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$170, $$169, $$164, $$177, $$172, $$173, $$183] <- [$$o.getField("o_ol_cnt"), $$o.getField("o_entry_d"), $$o.getField("o_id"), $$o.getField("o_c_id"), $$o.getField("o_w_id"), $$o.getField("o_d_id"), $$o.getField("o_orderline")]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          project ([$$o])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                                              data-scan []<-[$$175, $$o] <- test.orders
+                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  empty-tuple-source
                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                            exchange
                                             -- HASH_PARTITION_EXCHANGE [$$174, $$178, $$179]  |PARTITIONED|
+                                              project ([$$174, $$168, $$178, $$179])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$168, $$179, $$178, $$174] <- [$$c.getField("c_last"), $$c.getField("c_d_id"), $$c.getField("c_w_id"), $$c.getField("c_id")]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  project ([$$c])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.customer)  |PARTITIONED|
+                                                      data-scan []<-[$$176, $$c] <- test.customer
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q19.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q19.plan
index 4030e67..542f5a5 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q19.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q19.plan
@@ -1,34 +1,68 @@
+distribute result [$$116]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$116])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$116] <- [{"revenue": $$124}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$124] <- [agg-global-sql-sum($$129)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$129] <- [agg-local-sql-sum($$114)]
             -- AGGREGATE  |PARTITIONED|
+              project ([$$114])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (or(and(like($$119, "%h"), ge($$118, 7), le($$118, 17), and($$130, le($$117, 5)), or(eq($$65, 37), eq($$65, 29), eq($$65, 70))), and(like($$119, "%t"), ge($$118, 16), le($$118, 26), and($$130, le($$117, 10)), or(eq($$65, 78), eq($$65, 17), eq($$65, 6))), and(like($$119, "%m"), ge($$118, 24), le($$118, 34), and($$130, $$131), or(eq($$65, 91), eq($$65, 95), eq($$65, 15)))))
                 -- STREAM_SELECT  |PARTITIONED|
+                  project ([$$114, $$118, $$65, $$119, $$117, $$131, $$130])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (eq($$122, $$123))
                       -- HYBRID_HASH_JOIN [$$122][$$123]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$122]  |PARTITIONED|
+                          project ([$$114, $$118, $$65, $$122])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$114, $$118, $$122] <- [$$ol.getField("ol_amount"), $$ol.getField("ol_quantity"), $$ol.getField("ol_i_id")]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$65, $$ol])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                unnest $$ol <- scan-collection($$125)
                                 -- UNNEST  |PARTITIONED|
+                                  project ([$$65, $$125])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$65, $$125] <- [$$o.getField("o_w_id"), $$o.getField("o_orderline")]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$o])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                          data-scan []<-[$$120, $$o] <- test.orders
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$123]  |PARTITIONED|
+                          select (and($$130, $$131))
                           -- STREAM_SELECT  |PARTITIONED|
+                            assign [$$131, $$130] <- [le($$117, 15), ge($$117, 1)]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$119, $$117, $$123])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$119, $$117, $$123] <- [$$i.getField("i_data"), $$i.getField("i_price"), $$i.getField("i_id")]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$i])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.item)  |PARTITIONED|
+                                      data-scan []<-[$$121, $$i] <- test.item
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q2.plan
index 84f5c1d..cc860e4 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q2.plan
@@ -1,162 +1,318 @@
+distribute result [$$220]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    limit 100
     -- STREAM_LIMIT  |UNPARTITIONED|
+      project ([$$220])
       -- STREAM_PROJECT  |PARTITIONED|
+        assign [$$220] <- [{"su_suppkey": $$228, "su_name": $$261, "n_name": $$260, "i_id": $$226, "i_name": $$265, "su_address": $$266, "su_phone": $$267, "su_comment": $$268}]
         -- ASSIGN  |PARTITIONED|
+          exchange
           -- SORT_MERGE_EXCHANGE [$$260(ASC), $$261(ASC), $$226(ASC) ]  |PARTITIONED|
+            limit 100
             -- STREAM_LIMIT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (topK: 100) (ASC, $$260) (ASC, $$261) (ASC, $$226)
                 -- STABLE_SORT [topK: 100] [$$260(ASC), $$261(ASC), $$226(ASC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$228, $$261, $$260, $$226, $$265, $$266, $$267, $$268])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        join (eq($$238, $$239))
                         -- HYBRID_HASH_JOIN [$$238][$$239]  |PARTITIONED|
+                          exchange
                           -- HASH_PARTITION_EXCHANGE [$$238]  |PARTITIONED|
+                            project ([$$228, $$261, $$260, $$226, $$265, $$266, $$267, $$268, $$238])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                join (eq($$245, $$246))
                                 -- HYBRID_HASH_JOIN [$$245][$$246]  |PARTITIONED|
+                                  exchange
                                   -- HASH_PARTITION_EXCHANGE [$$245]  |PARTITIONED|
+                                    project ([$$228, $$261, $$226, $$265, $$266, $$267, $$268, $$245])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        join (eq($$251, $$228))
                                         -- HYBRID_HASH_JOIN [$$251][$$228]  |PARTITIONED|
+                                          exchange
                                           -- HASH_PARTITION_EXCHANGE [$$251]  |PARTITIONED|
+                                            project ([$$226, $$265, $$251])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$251] <- [numeric-mod(numeric-multiply($$258, $$227), 10000)]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$226, $$265, $$258, $$227])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    join (and(eq($$226, $$227), eq($$249, $$240)))
                                                     -- HYBRID_HASH_JOIN [$$226, $$240][$$227, $$249]  |PARTITIONED|
+                                                      exchange
                                                       -- HASH_PARTITION_EXCHANGE [$$226, $$240]  |PARTITIONED|
+                                                        project ([$$226, $$265, $$240])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            join (eq($$226, $$s_i_id))
                                                             -- HYBRID_HASH_JOIN [$$s_i_id][$$226]  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- SORT_GROUP_BY[$$271]  |PARTITIONED|
-                                                                        {
+                                                                group by ([$$s_i_id := $$271]) decor ([]) {
+                                                                          aggregate [$$240] <- [agg-global-sql-min($$270)]
                                                                           -- AGGREGATE  |LOCAL|
+                                                                            nested tuple source
                                                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                        }
+                                                                       }
+                                                                -- SORT_GROUP_BY[$$271]  |PARTITIONED|
+                                                                  exchange
                                                                   -- HASH_PARTITION_EXCHANGE [$$271]  |PARTITIONED|
-                                                                    -- SORT_GROUP_BY[$$225]  |PARTITIONED|
-                                                                            {
+                                                                    group by ([$$271 := $$225]) decor ([]) {
+                                                                              aggregate [$$270] <- [agg-local-sql-min($$177)]
                                                                               -- AGGREGATE  |LOCAL|
+                                                                                nested tuple source
                                                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                            }
+                                                                           }
+                                                                    -- SORT_GROUP_BY[$$225]  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        project ([$$177, $$225])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            join (eq($$247, $$256))
                                                                             -- HYBRID_HASH_JOIN [$$247][$$256]  |PARTITIONED|
+                                                                              exchange
                                                                               -- HASH_PARTITION_EXCHANGE [$$247]  |PARTITIONED|
+                                                                                project ([$$177, $$225, $$247])
                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                  assign [$$247] <- [numeric-mod(numeric-multiply($$s1.getField("s_w_id"), $$225), 10000)]
                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                    assign [$$225, $$177] <- [$$s1.getField("s_i_id"), $$s1.getField("s_quantity")]
                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                        replicate
                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                            project ([$$s1])
                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                              exchange
                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                -- DATASOURCE_SCAN (test.stock)  |PARTITIONED|
+                                                                                                data-scan []<-[$$229, $$s1] <- test.stock
+                                                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                  exchange
                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                    empty-tuple-source
                                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                              exchange
                                                                               -- HASH_PARTITION_EXCHANGE [$$256]  |PARTITIONED|
+                                                                                project ([$$256])
                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    join (eq($$243, $$255))
                                                                                     -- HYBRID_HASH_JOIN [$$243][$$255]  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- HASH_PARTITION_EXCHANGE [$$243]  |PARTITIONED|
+                                                                                        project ([$$256, $$243])
                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                          assign [$$256, $$243] <- [$$su1.getField("su_suppkey"), $$su1.getField("su_nationkey")]
                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                            exchange
                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                              replicate
                                                                                               -- REPLICATE  |PARTITIONED|
+                                                                                                exchange
                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                  project ([$$su1])
                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                    exchange
                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                      -- DATASOURCE_SCAN (test.supplier)  |PARTITIONED|
+                                                                                                      data-scan []<-[$$230, $$su1] <- test.supplier
+                                                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                        exchange
                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                          empty-tuple-source
                                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- HASH_PARTITION_EXCHANGE [$$255]  |PARTITIONED|
+                                                                                        project ([$$255])
                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                            join (eq($$241, $$242))
                                                                                             -- HYBRID_HASH_JOIN [$$241][$$242]  |PARTITIONED|
+                                                                                              exchange
                                                                                               -- HASH_PARTITION_EXCHANGE [$$241]  |PARTITIONED|
+                                                                                                project ([$$255, $$241])
                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                  assign [$$255, $$241] <- [$$n1.getField("n_nationkey"), $$n1.getField("n_regionkey")]
                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                    exchange
                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                      replicate
                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                        exchange
                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                          project ([$$n1])
                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                            exchange
                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                              -- DATASOURCE_SCAN (test.nation)  |PARTITIONED|
+                                                                                                              data-scan []<-[$$231, $$n1] <- test.nation
+                                                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                exchange
                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                  empty-tuple-source
                                                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                              exchange
                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                replicate
                                                                                                 -- REPLICATE  |PARTITIONED|
+                                                                                                  exchange
                                                                                                   -- HASH_PARTITION_EXCHANGE [$$242]  |PARTITIONED|
+                                                                                                    project ([$$242])
                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                      select (like($$r1.getField("r_name"), "Europ%"))
                                                                                                       -- STREAM_SELECT  |PARTITIONED|
+                                                                                                        assign [$$242] <- [$$r1.getField("r_regionkey")]
                                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                                          project ([$$r1])
                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                            exchange
                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                              -- DATASOURCE_SCAN (test.region)  |PARTITIONED|
+                                                                                                              data-scan []<-[$$232, $$r1] <- test.region
+                                                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                exchange
                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                  empty-tuple-source
                                                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                              exchange
                                                               -- HASH_PARTITION_EXCHANGE [$$226]  |PARTITIONED|
+                                                                project ([$$226, $$265])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  select (like($$i.getField("i_data"), "%b"))
                                                                   -- STREAM_SELECT  |PARTITIONED|
+                                                                    assign [$$265, $$226] <- [$$i.getField("i_name"), $$i.getField("i_id")]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      project ([$$i])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                          -- DATASOURCE_SCAN (test.item)  |PARTITIONED|
+                                                                          data-scan []<-[$$233, $$i] <- test.item
+                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              empty-tuple-source
                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                      exchange
                                                       -- HASH_PARTITION_EXCHANGE [$$227, $$249]  |PARTITIONED|
+                                                        project ([$$258, $$227, $$249])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$258, $$249, $$227] <- [$$s.getField("s_w_id"), $$s.getField("s_quantity"), $$s.getField("s_i_id")]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            project ([$$s])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$s] <- [$$s1]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  replicate
                                                                   -- REPLICATE  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      project ([$$s1])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                          -- DATASOURCE_SCAN (test.stock)  |PARTITIONED|
+                                                                          data-scan []<-[$$229, $$s1] <- test.stock
+                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              empty-tuple-source
                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                          exchange
                                           -- HASH_PARTITION_EXCHANGE [$$228]  |PARTITIONED|
+                                            project ([$$228, $$261, $$266, $$267, $$268, $$245])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$268, $$267, $$266, $$261, $$245, $$228] <- [$$su.getField("su_comment"), $$su.getField("su_phone"), $$su.getField("su_address"), $$su.getField("su_name"), $$su.getField("su_nationkey"), $$su.getField("su_suppkey")]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$su])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$su] <- [$$su1]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      replicate
                                                       -- REPLICATE  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          project ([$$su1])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- DATASOURCE_SCAN (test.supplier)  |PARTITIONED|
+                                                              data-scan []<-[$$230, $$su1] <- test.supplier
+                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  empty-tuple-source
                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                  exchange
                                   -- HASH_PARTITION_EXCHANGE [$$246]  |PARTITIONED|
+                                    project ([$$260, $$238, $$246])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$260, $$238, $$246] <- [$$n.getField("n_name"), $$n.getField("n_regionkey"), $$n.getField("n_nationkey")]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$n])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$n] <- [$$n1]
                                           -- ASSIGN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              replicate
                                               -- REPLICATE  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  project ([$$n1])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.nation)  |PARTITIONED|
+                                                      data-scan []<-[$$231, $$n1] <- test.nation
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$239])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$239] <- [$$242]
                               -- ASSIGN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  replicate
                                   -- REPLICATE  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$242]  |PARTITIONED|
+                                      project ([$$242])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        select (like($$r1.getField("r_name"), "Europ%"))
                                         -- STREAM_SELECT  |PARTITIONED|
+                                          assign [$$242] <- [$$r1.getField("r_regionkey")]
                                           -- ASSIGN  |PARTITIONED|
+                                            project ([$$r1])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- DATASOURCE_SCAN (test.region)  |PARTITIONED|
+                                                data-scan []<-[$$232, $$r1] <- test.region
+                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q20.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q20.plan
index 3b04b56..38d2539 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q20.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q20.plan
@@ -1,112 +1,212 @@
+distribute result [$$157]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$157])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$157] <- [{"su_name": $$178, "su_address": $$180}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$178(ASC) ]  |PARTITIONED|
+          order (ASC, $$178)
           -- STABLE_SORT [$$178(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$178, $$180])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  join (eq($$172, $$173))
                   -- HYBRID_HASH_JOIN [$$172][$$173]  |PARTITIONED|
+                    exchange
                     -- HASH_PARTITION_EXCHANGE [$$172]  |PARTITIONED|
+                      project ([$$178, $$180, $$172])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select ($$147)
                         -- STREAM_SELECT  |PARTITIONED|
+                          project ([$$147, $$178, $$180, $$172])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- PRE_CLUSTERED_GROUP_BY[$$164]  |PARTITIONED|
-                                      {
+                              group by ([$$185 := $$164]) decor ([$$178; $$180; $$172]) {
+                                        aggregate [$$147] <- [non-empty-stream()]
                                         -- AGGREGATE  |LOCAL|
+                                          select (not(is-missing($$184)))
                                           -- STREAM_SELECT  |LOCAL|
+                                            nested tuple source
                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                      }
+                                     }
+                              -- PRE_CLUSTERED_GROUP_BY[$$164]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  order (ASC, $$164)
                                   -- STABLE_SORT [$$164(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$164]  |PARTITIONED|
+                                      project ([$$178, $$180, $$172, $$184, $$164])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          left outer join (eq($$171, $$143))
                                           -- HYBRID_HASH_JOIN [$$171][$$143]  |PARTITIONED|
+                                            exchange
                                             -- HASH_PARTITION_EXCHANGE [$$171]  |PARTITIONED|
+                                              project ([$$178, $$180, $$172, $$164, $$171])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$180, $$178, $$172, $$171] <- [$$su.getField("su_address"), $$su.getField("su_name"), $$su.getField("su_nationkey"), $$su.getField("su_suppkey")]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (test.supplier)  |PARTITIONED|
+                                                    data-scan []<-[$$164, $$su] <- test.supplier
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                            exchange
                                             -- HASH_PARTITION_EXCHANGE [$$143]  |PARTITIONED|
+                                              project ([$$184, $$143])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$184, $$143] <- [true, numeric-mod(numeric-multiply($$s_i_id, $$s_w_id), 10000)]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  project ([$$s_i_id, $$s_w_id])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    select (gt(numeric-multiply(20, $$s_quantity), $$169))
                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- SORT_GROUP_BY[$$187, $$188, $$189]  |PARTITIONED|
-                                                                {
+                                                        group by ([$$s_i_id := $$187; $$s_w_id := $$188; $$s_quantity := $$189]) decor ([]) {
+                                                                  aggregate [$$169] <- [agg-global-sql-sum($$186)]
                                                                   -- AGGREGATE  |LOCAL|
+                                                                    nested tuple source
                                                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                }
+                                                               }
+                                                        -- SORT_GROUP_BY[$$187, $$188, $$189]  |PARTITIONED|
+                                                          exchange
                                                           -- HASH_PARTITION_EXCHANGE [$$187, $$188, $$189]  |PARTITIONED|
-                                                            -- SORT_GROUP_BY[$$170, $$160, $$161]  |PARTITIONED|
-                                                                    {
+                                                            group by ([$$187 := $$170; $$188 := $$160; $$189 := $$161]) decor ([]) {
+                                                                      aggregate [$$186] <- [agg-local-sql-sum($$139)]
                                                                       -- AGGREGATE  |LOCAL|
+                                                                        nested tuple source
                                                                         -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                    }
+                                                                   }
+                                                            -- SORT_GROUP_BY[$$170, $$160, $$161]  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                project ([$$139, $$170, $$160, $$161])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    join (eq($$174, $$170))
                                                                     -- HYBRID_HASH_JOIN [$$170][$$174]  |PARTITIONED|
+                                                                      exchange
                                                                       -- HASH_PARTITION_EXCHANGE [$$170]  |PARTITIONED|
+                                                                        project ([$$170, $$160, $$161])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          select ($$121)
                                                                           -- STREAM_SELECT  |PARTITIONED|
+                                                                            project ([$$121, $$160, $$161, $$170])
                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                -- PRE_CLUSTERED_GROUP_BY[$$166]  |PARTITIONED|
-                                                                                        {
+                                                                                group by ([$$183 := $$166]) decor ([$$160; $$161; $$170]) {
+                                                                                          aggregate [$$121] <- [non-empty-stream()]
                                                                                           -- AGGREGATE  |LOCAL|
+                                                                                            select (not(is-missing($$182)))
                                                                                             -- STREAM_SELECT  |LOCAL|
+                                                                                              nested tuple source
                                                                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                        }
+                                                                                       }
+                                                                                -- PRE_CLUSTERED_GROUP_BY[$$166]  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    order (ASC, $$166)
                                                                                     -- STABLE_SORT [$$166(ASC)]  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- HASH_PARTITION_EXCHANGE [$$166]  |PARTITIONED|
+                                                                                        project ([$$170, $$160, $$161, $$182, $$166])
                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                            left outer join (eq($$170, $$117))
                                                                                             -- HYBRID_HASH_JOIN [$$170][$$117]  |PARTITIONED|
+                                                                                              exchange
                                                                                               -- HASH_PARTITION_EXCHANGE [$$170]  |PARTITIONED|
+                                                                                                project ([$$170, $$160, $$161, $$166])
                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                  assign [$$161, $$160, $$170] <- [$$s.getField("s_quantity"), $$s.getField("s_w_id"), $$s.getField("s_i_id")]
                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                    exchange
                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                      -- DATASOURCE_SCAN (test.stock)  |PARTITIONED|
+                                                                                                      data-scan []<-[$$166, $$s] <- test.stock
+                                                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                        exchange
                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                          empty-tuple-source
                                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                              exchange
                                                                                               -- HASH_PARTITION_EXCHANGE [$$117]  |PARTITIONED|
+                                                                                                assign [$$182] <- [true]
                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                  project ([$$117])
                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                    select (like($$i.getField("i_data"), "co%"))
                                                                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                                                                      assign [$$117] <- [$$i.getField("i_id")]
                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                        project ([$$i])
                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                          exchange
                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                            -- DATASOURCE_SCAN (test.item)  |PARTITIONED|
+                                                                                                            data-scan []<-[$$168, $$i] <- test.item
+                                                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                              exchange
                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                empty-tuple-source
                                                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                      exchange
                                                                       -- HASH_PARTITION_EXCHANGE [$$174]  |PARTITIONED|
+                                                                        project ([$$139, $$174])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          select (and(ge($$162, "2016-01-01 12:00:00"), lt($$162, "2017-01-01 12:00:00")))
                                                                           -- STREAM_SELECT  |PARTITIONED|
+                                                                            project ([$$139, $$174, $$162])
                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                              assign [$$139, $$174, $$162] <- [$$ol.getField("ol_quantity"), $$ol.getField("ol_i_id"), $$ol.getField("ol_delivery_d")]
                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                project ([$$ol])
                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                  unnest $$ol <- scan-collection($$176)
                                                                                   -- UNNEST  |PARTITIONED|
+                                                                                    project ([$$176])
                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                      assign [$$176] <- [$$o.getField("o_orderline")]
                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                        project ([$$o])
                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                            -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                                                                            data-scan []<-[$$167, $$o] <- test.orders
+                                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                              exchange
                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                empty-tuple-source
                                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                    exchange
                     -- HASH_PARTITION_EXCHANGE [$$173]  |PARTITIONED|
+                      project ([$$173])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (eq($$n.getField("n_name"), "Germany"))
                         -- STREAM_SELECT  |PARTITIONED|
+                          assign [$$173] <- [$$n.getField("n_nationkey")]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$n])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.nation)  |PARTITIONED|
+                                data-scan []<-[$$165, $$n] <- test.nation
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q21.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q21.plan
index 6c845e0..7111036 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q21.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q21.plan
@@ -1,116 +1,220 @@
+distribute result [$$318]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    limit 100
     -- STREAM_LIMIT  |UNPARTITIONED|
+      project ([$$318])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$su_name(ASC) ]  |PARTITIONED|
+          project ([$$su_name, $$318])
           -- STREAM_PROJECT  |PARTITIONED|
+            assign [$$318] <- [{"su_name": $$su_name, "numwait": $$343}]
             -- ASSIGN  |PARTITIONED|
+              limit 100
               -- STREAM_LIMIT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- SORT_GROUP_BY[$$377]  |PARTITIONED|
-                          {
+                  group by ([$$su_name := $$378]) decor ([]) {
+                            aggregate [$$343] <- [agg-sql-sum($$377)]
                             -- AGGREGATE  |LOCAL|
+                              nested tuple source
                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
-                    -- HASH_PARTITION_EXCHANGE [$$377]  |PARTITIONED|
-                      -- SORT_GROUP_BY[$$su_name]  |PARTITIONED|
-                              {
+                         }
+                  -- SORT_GROUP_BY[$$378]  |PARTITIONED|
+                    exchange
+                    -- HASH_PARTITION_EXCHANGE [$$378]  |PARTITIONED|
+                      group by ([$$378 := $$su_name]) decor ([]) {
+                                aggregate [$$377] <- [agg-sql-count(1)]
                                 -- AGGREGATE  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- SORT_GROUP_BY[$$su_name]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$su_name])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            select (eq($$342, 0))
                             -- STREAM_SELECT  |PARTITIONED|
+                              project ([$$342, $$su_name])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- SORT_GROUP_BY[$$368, $$369, $$370, $$371, $$372, $$373, $$374, $$375]  |PARTITIONED|
-                                          {
+                                  group by ([$$o_w_id := $$369; $$o_d_id := $$370; $$o_id := $$371; $$n_nationkey := $$372; $$su_suppkey := $$373; $$s_w_id := $$374; $$s_i_id := $$375; $$su_name := $$376]) decor ([]) {
+                                            aggregate [$$342] <- [agg-sql-sum($$368)]
                                             -- AGGREGATE  |LOCAL|
+                                              nested tuple source
                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
-                                    -- HASH_PARTITION_EXCHANGE [$$368, $$369, $$370, $$371, $$372, $$373, $$374, $$375]  |PARTITIONED|
-                                      -- SORT_GROUP_BY[$$330, $$356, $$355, $$332, $$333, $$329, $$328, $$357]  |PARTITIONED|
-                                              {
+                                         }
+                                  -- SORT_GROUP_BY[$$369, $$370, $$371, $$372, $$373, $$374, $$375, $$376]  |PARTITIONED|
+                                    exchange
+                                    -- HASH_PARTITION_EXCHANGE [$$369, $$370, $$371, $$372, $$373, $$374, $$375, $$376]  |PARTITIONED|
+                                      group by ([$$369 := $$331; $$370 := $$357; $$371 := $$356; $$372 := $$333; $$373 := $$334; $$374 := $$330; $$375 := $$329; $$376 := $$358]) decor ([]) {
+                                                aggregate [$$368] <- [agg-sql-count($$305)]
                                                 -- AGGREGATE  |LOCAL|
+                                                  nested tuple source
                                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                              }
+                                             }
+                                      -- SORT_GROUP_BY[$$331, $$357, $$356, $$333, $$334, $$330, $$329, $$358]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$305, $$331, $$357, $$356, $$333, $$334, $$330, $$329, $$358])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              left outer join (and(eq($$362, $$357), gt($$363, $$332), eq($$360, $$356), eq($$361, $$331)))
                                               -- NESTED_LOOP  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  project ([$$331, $$357, $$356, $$333, $$334, $$330, $$329, $$358, $$332])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- HYBRID_HASH_JOIN [$$329, $$328][$$330, $$340]  |PARTITIONED|
-                                                        -- HASH_PARTITION_EXCHANGE [$$329, $$328]  |PARTITIONED|
+                                                      join (and(eq($$331, $$330), eq($$341, $$329)))
+                                                      -- HYBRID_HASH_JOIN [$$330, $$329][$$331, $$341]  |PARTITIONED|
+                                                        exchange
+                                                        -- HASH_PARTITION_EXCHANGE [$$330, $$329]  |PARTITIONED|
+                                                          project ([$$333, $$334, $$330, $$329, $$358])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- HYBRID_HASH_JOIN [$$333][$$344]  |PARTITIONED|
-                                                                -- HASH_PARTITION_EXCHANGE [$$333]  |PARTITIONED|
+                                                              join (eq($$345, $$334))
+                                                              -- HYBRID_HASH_JOIN [$$334][$$345]  |PARTITIONED|
+                                                                exchange
+                                                                -- HASH_PARTITION_EXCHANGE [$$334]  |PARTITIONED|
+                                                                  project ([$$333, $$334, $$358])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- HYBRID_HASH_JOIN [$$332][$$343]  |PARTITIONED|
-                                                                        -- HASH_PARTITION_EXCHANGE [$$332]  |PARTITIONED|
+                                                                      join (eq($$344, $$333))
+                                                                      -- HYBRID_HASH_JOIN [$$333][$$344]  |PARTITIONED|
+                                                                        exchange
+                                                                        -- HASH_PARTITION_EXCHANGE [$$333]  |PARTITIONED|
+                                                                          project ([$$333])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            select (eq($$n.getField("n_name"), "Peru"))
                                                                             -- STREAM_SELECT  |PARTITIONED|
+                                                                              assign [$$333] <- [$$n.getField("n_nationkey")]
                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                project ([$$n])
                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                    -- DATASOURCE_SCAN (test.nation)  |PARTITIONED|
+                                                                                    data-scan []<-[$$336, $$n] <- test.nation
+                                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                        empty-tuple-source
                                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                                        -- HASH_PARTITION_EXCHANGE [$$343]  |PARTITIONED|
+                                                                        exchange
+                                                                        -- HASH_PARTITION_EXCHANGE [$$344]  |PARTITIONED|
+                                                                          project ([$$334, $$358, $$344])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            assign [$$358, $$334, $$344] <- [$$su.getField("su_name"), $$su.getField("su_suppkey"), $$su.getField("su_nationkey")]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              project ([$$su])
                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                  -- DATASOURCE_SCAN (test.supplier)  |PARTITIONED|
+                                                                                  data-scan []<-[$$337, $$su] <- test.supplier
+                                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                    exchange
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                      empty-tuple-source
                                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                                -- HASH_PARTITION_EXCHANGE [$$344]  |PARTITIONED|
+                                                                exchange
+                                                                -- HASH_PARTITION_EXCHANGE [$$345]  |PARTITIONED|
+                                                                  assign [$$345] <- [numeric-mod(numeric-multiply($$330, $$329), 10000)]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    project ([$$330, $$329])
                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                      assign [$$330, $$329] <- [$$s.getField("s_w_id"), $$s.getField("s_i_id")]
                                                                       -- ASSIGN  |PARTITIONED|
+                                                                        project ([$$s])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                            -- DATASOURCE_SCAN (test.stock)  |PARTITIONED|
+                                                                            data-scan []<-[$$338, $$s] <- test.stock
+                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                empty-tuple-source
                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                        -- HASH_PARTITION_EXCHANGE [$$330, $$340]  |PARTITIONED|
+                                                        exchange
+                                                        -- HASH_PARTITION_EXCHANGE [$$331, $$341]  |PARTITIONED|
+                                                          project ([$$331, $$357, $$356, $$332, $$341])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            select (gt($$332, string(numeric-add(date($$328), duration: {P150D }))))
                                                             -- STREAM_SELECT  |PARTITIONED|
+                                                              project ([$$357, $$356, $$331, $$328, $$341, $$332])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$341, $$332] <- [$$ol1.getField("ol_i_id"), $$ol1.getField("ol_delivery_d")]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  project ([$$357, $$356, $$331, $$328, $$ol1])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    unnest $$ol1 <- scan-collection($$355)
                                                                     -- UNNEST  |PARTITIONED|
+                                                                      select (and(le($$328, "2017-12-31 00:00:00"), ge($$328, "2017-12-01 00:00:00")))
                                                                       -- STREAM_SELECT  |PARTITIONED|
+                                                                        project ([$$357, $$356, $$331, $$328, $$355])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          assign [$$357, $$356, $$331, $$328, $$355] <- [$$o1.getField("o_d_id"), $$o1.getField("o_id"), $$o1.getField("o_w_id"), $$o1.getField("o_entry_d"), $$o1.getField("o_orderline")]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              replicate
                                                                               -- REPLICATE  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  project ([$$o1])
                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                    exchange
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                      -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                                                                      data-scan []<-[$$339, $$o1] <- test.orders
+                                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                        exchange
                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                          empty-tuple-source
                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                exchange
                                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                  assign [$$305] <- [{"o_id": $$360, "o_w_id": $$361, "o_d_id": $$362, "ol_delivery_d": $$363}.getField("o_id")]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$362, $$361, $$360, $$363])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      assign [$$363] <- [$$ol2.getField("ol_delivery_d")]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        project ([$$362, $$361, $$360, $$ol2])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          unnest $$ol2 <- scan-collection($$359)
                                                           -- UNNEST  |PARTITIONED|
+                                                            project ([$$362, $$361, $$360, $$359])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              select (and(le($$335, "2017-12-31 00:00:00"), ge($$335, "2017-12-01 00:00:00")))
                                                               -- STREAM_SELECT  |PARTITIONED|
+                                                                project ([$$362, $$361, $$360, $$335, $$359])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  assign [$$362, $$361, $$360, $$335, $$359] <- [$$o2.getField("o_d_id"), $$o2.getField("o_w_id"), $$o2.getField("o_id"), $$o2.getField("o_entry_d"), $$o2.getField("o_orderline")]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    project ([$$o2])
                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                      assign [$$o2] <- [$$o1]
                                                                       -- ASSIGN  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          replicate
                                                                           -- REPLICATE  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              project ([$$o1])
                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                  -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                                                                  data-scan []<-[$$339, $$o1] <- test.orders
+                                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                    exchange
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                      empty-tuple-source
                                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q22.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q22.plan
index 19a82f7..140aeb3 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q22.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q22.plan
@@ -1,110 +1,208 @@
+distribute result [$$135]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$135])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$135] <- [{"country": $#1, "numcust": $$144, "totacctbal": $$145}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$#1(ASC) ]  |PARTITIONED|
-          -- SORT_GROUP_BY[$$168]  |PARTITIONED|
-                  {
+          group by ([$#1 := $$168]) decor ([]) {
+                    aggregate [$$144, $$145] <- [agg-sql-sum($$166), agg-global-sql-sum($$167)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- SORT_GROUP_BY[$$168]  |PARTITIONED|
+            exchange
             -- HASH_PARTITION_EXCHANGE [$$168]  |PARTITIONED|
-              -- SORT_GROUP_BY[$$136]  |PARTITIONED|
-                      {
+              group by ([$$168 := $$136]) decor ([]) {
+                        aggregate [$$166, $$167] <- [agg-sql-count(1), agg-local-sql-sum($$146)]
                         -- AGGREGATE  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SORT_GROUP_BY[$$136]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$146, $$136])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$136] <- [substring1($$157, 1, 1)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$146, $$157])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (not(neq($$143, 0)))
                         -- STREAM_SELECT  |PARTITIONED|
+                          project ([$$143, $$146, $$157])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- SORT_GROUP_BY[$$165]  |PARTITIONED|
-                                      {
+                              group by ([$$162 := $$165]) decor ([$$146; $$157]) {
+                                        aggregate [$$143] <- [agg-sum($$164)]
                                         -- AGGREGATE  |LOCAL|
+                                          nested tuple source
                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                      }
+                                     }
+                              -- SORT_GROUP_BY[$$165]  |PARTITIONED|
+                                exchange
                                 -- HASH_PARTITION_EXCHANGE [$$165]  |PARTITIONED|
-                                  -- PRE_CLUSTERED_GROUP_BY[$$160]  |PARTITIONED|
-                                          {
+                                  group by ([$$165 := $$160]) decor ([$$146; $$157]) {
+                                            aggregate [$$164] <- [agg-count(1)]
                                             -- AGGREGATE  |LOCAL|
+                                              select (not(is-missing($$161)))
                                               -- STREAM_SELECT  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                         }
+                                  -- PRE_CLUSTERED_GROUP_BY[$$160]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$160)
                                       -- STABLE_SORT [$$160(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$146, $$157, $$161, $$160])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              left outer join (and(eq($$148, $$149), eq($$150, $$151), eq($$152, $$153)))
                                               -- HYBRID_HASH_JOIN [$$149, $$151, $$153][$$148, $$150, $$152]  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$149, $$151, $$153]  |PARTITIONED|
+                                                  running-aggregate [$$160] <- [create-query-uid()]
                                                   -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                    project ([$$146, $$157, $$149, $$151, $$153])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        join (gt($$146, $$147))
                                                         -- NESTED_LOOP  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            project ([$$146, $$157, $$149, $$151, $$153])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                join (eq($$141, $$79))
                                                                 -- HYBRID_HASH_JOIN [$$79][$$141]  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    project ([$$146, $$157, $$149, $$151, $$153, $$79])
                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                      assign [$$79, $$157, $$153, $$151, $$149, $$146] <- [substring1($$c.getField("c_phone"), 1, 1), $$c.getField("c_state"), $$c.getField("c_w_id"), $$c.getField("c_id"), $$c.getField("c_d_id"), $$c.getField("c_balance")]
                                                                       -- ASSIGN  |PARTITIONED|
+                                                                        project ([$$c])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          assign [$$c] <- [$$c1]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              replicate
                                                                               -- REPLICATE  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  project ([$$c1])
                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                    exchange
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                      -- DATASOURCE_SCAN (test.customer)  |PARTITIONED|
+                                                                                      data-scan []<-[$$139, $$c1] <- test.customer
+                                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                        exchange
                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                          empty-tuple-source
                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    project ([$$141])
                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                      assign [$$141] <- [$$142]
                                                                       -- ASSIGN  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          replicate
                                                                           -- REPLICATE  |PARTITIONED|
+                                                                            exchange
                                                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                              unnest $$142 <- scan-collection(array: [ "1", "2", "3", "4", "5", "6", "7" ])
                                                                               -- UNNEST  |UNPARTITIONED|
+                                                                                empty-tuple-source
                                                                                 -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                                          exchange
                                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                            project ([$$147])
                                                             -- STREAM_PROJECT  |UNPARTITIONED|
+                                                              assign [$$147] <- [get-item($$98, 0)]
                                                               -- ASSIGN  |UNPARTITIONED|
+                                                                aggregate [$$98] <- [listify($$163)]
                                                                 -- AGGREGATE  |UNPARTITIONED|
+                                                                  aggregate [$$163] <- [agg-global-sql-avg($$169)]
                                                                   -- AGGREGATE  |UNPARTITIONED|
+                                                                    exchange
                                                                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                                                                      aggregate [$$169] <- [agg-local-sql-avg($$155)]
                                                                       -- AGGREGATE  |PARTITIONED|
+                                                                        project ([$$155])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            join (eq($$142, $$87))
                                                                             -- HYBRID_HASH_JOIN [$$87][$$142]  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                project ([$$155, $$87])
                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                  assign [$$87] <- [substring1($$c1.getField("c_phone"), 1, 1)]
                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                    select (gt($$155, 0.0))
                                                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                                                      assign [$$155] <- [$$c1.getField("c_balance")]
                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                        exchange
                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                          replicate
                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                            exchange
                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                              project ([$$c1])
                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                exchange
                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                  -- DATASOURCE_SCAN (test.customer)  |PARTITIONED|
+                                                                                                  data-scan []<-[$$139, $$c1] <- test.customer
+                                                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                    exchange
                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                      empty-tuple-source
                                                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                replicate
                                                                                 -- REPLICATE  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                    unnest $$142 <- scan-collection(array: [ "1", "2", "3", "4", "5", "6", "7" ])
                                                                                     -- UNNEST  |UNPARTITIONED|
+                                                                                      empty-tuple-source
                                                                                       -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$148, $$150, $$152]  |PARTITIONED|
+                                                  assign [$$161] <- [true]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$152, $$150, $$148])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      select (and(ge($$137, "2013-12-01 00:00:00"), le($$137, "2013-12-31 00:00:00")))
                                                       -- STREAM_SELECT  |PARTITIONED|
+                                                        project ([$$152, $$150, $$148, $$137])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$152, $$150, $$148, $$137] <- [$$o.getField("o_w_id"), $$o.getField("o_c_id"), $$o.getField("o_d_id"), $$o.getField("o_entry_d")]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            project ([$$o])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                                                data-scan []<-[$$140, $$o] <- test.orders
+                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    empty-tuple-source
                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q3.plan
index a2ffaea..8d0aa84 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q3.plan
@@ -1,56 +1,106 @@
+distribute result [$$183]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$183])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$183] <- [{"o_id": $$o_id, "o_w_id": $$o_w_id, "o_d_id": $$o_d_id, "revenue": $$204, "o_entry_d": $$o_entry_d}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$204(DESC), $$o_entry_d(ASC) ]  |PARTITIONED|
+          order (DESC, $$204) (ASC, $$o_entry_d)
           -- STABLE_SORT [$$204(DESC), $$o_entry_d(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- SORT_GROUP_BY[$$211, $$212, $$213, $$214]  |PARTITIONED|
-                      {
+              group by ([$$o_id := $$211; $$o_w_id := $$212; $$o_d_id := $$213; $$o_entry_d := $$214]) decor ([]) {
+                        aggregate [$$204] <- [agg-global-sql-sum($$210)]
                         -- AGGREGATE  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SORT_GROUP_BY[$$211, $$212, $$213, $$214]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$211, $$212, $$213, $$214]  |PARTITIONED|
-                  -- SORT_GROUP_BY[$$206, $$188, $$189, $$190]  |PARTITIONED|
-                          {
+                  group by ([$$211 := $$206; $$212 := $$188; $$213 := $$189; $$214 := $$190]) decor ([]) {
+                            aggregate [$$210] <- [agg-local-sql-sum($$180)]
                             -- AGGREGATE  |LOCAL|
+                              nested tuple source
                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                         }
+                  -- SORT_GROUP_BY[$$206, $$188, $$189, $$190]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$180, $$206, $$188, $$189, $$190])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          join (and(eq($$201, $$188), eq($$202, $$189), eq($$203, $$206)))
                           -- HYBRID_HASH_JOIN [$$188, $$189, $$206][$$201, $$202, $$203]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$188, $$189, $$206]  |PARTITIONED|
+                              project ([$$180, $$206, $$188, $$189, $$190])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$180] <- [$$ol.getField("ol_amount")]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$206, $$190, $$189, $$188, $$ol])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    unnest $$ol <- scan-collection($$207)
                                     -- UNNEST  |PARTITIONED|
+                                      project ([$$207, $$206, $$190, $$189, $$188])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          join (and(eq($$197, $$198), eq($$199, $$188), eq($$200, $$189)))
                                           -- HYBRID_HASH_JOIN [$$198, $$188, $$189][$$197, $$199, $$200]  |PARTITIONED|
+                                            exchange
                                             -- HASH_PARTITION_EXCHANGE [$$198, $$188, $$189]  |PARTITIONED|
+                                              select (lt($$190, "2017-03-15 00:00:00.000000"))
                                               -- STREAM_SELECT  |PARTITIONED|
+                                                project ([$$207, $$206, $$198, $$190, $$189, $$188])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$207, $$206, $$198, $$190, $$189, $$188] <- [$$o.getField("o_orderline"), $$o.getField("o_id"), $$o.getField("o_c_id"), $$o.getField("o_entry_d"), $$o.getField("o_d_id"), $$o.getField("o_w_id")]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$o])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                                        data-scan []<-[$$194, $$o] <- test.orders
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                            exchange
                                             -- HASH_PARTITION_EXCHANGE [$$197, $$199, $$200]  |PARTITIONED|
+                                              project ([$$197, $$199, $$200])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                select (like($$c.getField("c_state"), "A%"))
                                                 -- STREAM_SELECT  |PARTITIONED|
+                                                  assign [$$200, $$199, $$197] <- [$$c.getField("c_d_id"), $$c.getField("c_w_id"), $$c.getField("c_id")]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$c])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.customer)  |PARTITIONED|
+                                                        data-scan []<-[$$195, $$c] <- test.customer
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$201, $$202, $$203]  |PARTITIONED|
+                              project ([$$201, $$202, $$203])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$203, $$202, $$201] <- [$$no.getField("no_o_id"), $$no.getField("no_d_id"), $$no.getField("no_w_id")]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$no])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.neworder)  |PARTITIONED|
+                                      data-scan []<-[$$196, $$no] <- test.neworder
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q4.plan
index 5818a43..5ff242d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q4.plan
@@ -1,36 +1,63 @@
+distribute result [$$68]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$68])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$68] <- [{"o_ol_cnt": $$o_ol_cnt, "order_COUNT": $$73}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$o_ol_cnt(ASC) ]  |PARTITIONED|
-          -- SORT_GROUP_BY[$$77]  |PARTITIONED|
-                  {
+          group by ([$$o_ol_cnt := $$78]) decor ([]) {
+                    aggregate [$$73] <- [agg-sql-sum($$77)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
-            -- HASH_PARTITION_EXCHANGE [$$77]  |PARTITIONED|
-              -- SORT_GROUP_BY[$$68]  |PARTITIONED|
-                      {
+                 }
+          -- SORT_GROUP_BY[$$78]  |PARTITIONED|
+            exchange
+            -- HASH_PARTITION_EXCHANGE [$$78]  |PARTITIONED|
+              group by ([$$78 := $$69]) decor ([]) {
+                        aggregate [$$77] <- [agg-sql-count(1)]
                         -- AGGREGATE  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SORT_GROUP_BY[$$69]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$69])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    select (neq($$72, 0))
                     -- STREAM_SELECT  |PARTITIONED|
+                      project ([$$69, $$72])
                       -- STREAM_PROJECT  |PARTITIONED|
-                        -- SUBPLAN  |PARTITIONED|
-                                {
+                        subplan {
+                                  aggregate [$$72] <- [agg-count(1)]
                                   -- AGGREGATE  |LOCAL|
+                                    select (ge($$75, string(numeric-add(date($$76), duration: {P7D }))))
                                     -- STREAM_SELECT  |LOCAL|
+                                      assign [$$75] <- [$$ol.getField("ol_delivery_d")]
                                       -- ASSIGN  |LOCAL|
+                                        unnest $$ol <- scan-collection($$74)
                                         -- UNNEST  |LOCAL|
+                                          nested tuple source
                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                }
+                               }
+                        -- SUBPLAN  |PARTITIONED|
+                          select (and(lt($$76, "2015-10-01 00:00:00.000000"), ge($$76, "2015-07-01 00:00:00.000000")))
                           -- STREAM_SELECT  |PARTITIONED|
+                            project ([$$69, $$76, $$74])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$69, $$76, $$74] <- [$$o.getField("o_ol_cnt"), $$o.getField("o_entry_d"), $$o.getField("o_orderline")]
                               -- ASSIGN  |PARTITIONED|
+                                project ([$$o])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                    data-scan []<-[$$71, $$o] <- test.orders
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q5.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q5.plan
index 30ae23f..6d990fe 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q5.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q5.plan
@@ -1,98 +1,190 @@
+distribute result [$$229]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$229])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$229] <- [{"n_name": $$n_name, "revenue": $#2}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$#2(DESC) ]  |PARTITIONED|
+          order (DESC, $#2)
           -- STABLE_SORT [$#2(DESC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$n_name, $#2])
               -- STREAM_PROJECT  |PARTITIONED|
+                assign [$#2] <- [round($$256, 2)]
                 -- ASSIGN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- SORT_GROUP_BY[$$277]  |PARTITIONED|
-                            {
+                    group by ([$$n_name := $$277]) decor ([]) {
+                              aggregate [$$256] <- [agg-global-sql-sum($$276)]
                               -- AGGREGATE  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                            }
+                           }
+                    -- SORT_GROUP_BY[$$277]  |PARTITIONED|
+                      exchange
                       -- HASH_PARTITION_EXCHANGE [$$277]  |PARTITIONED|
-                        -- SORT_GROUP_BY[$$261]  |PARTITIONED|
-                                {
+                        group by ([$$277 := $$261]) decor ([]) {
+                                  aggregate [$$276] <- [agg-local-sql-sum($$266)]
                                   -- AGGREGATE  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                }
+                               }
+                        -- SORT_GROUP_BY[$$261]  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$266, $$261])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                join (and(eq($$252, $$260), eq($$254, $$255)))
                                 -- HYBRID_HASH_JOIN [$$260, $$254][$$252, $$255]  |PARTITIONED|
+                                  exchange
                                   -- HASH_PARTITION_EXCHANGE [$$260, $$254]  |PARTITIONED|
+                                    project ([$$266, $$261, $$260, $$254])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$254] <- [numeric-mod(numeric-multiply($$231, $$232), 10000)]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$231, $$232, $$266, $$261, $$260])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            join (and(eq($$240, $$231), eq($$267, $$232)))
                                             -- HYBRID_HASH_JOIN [$$231, $$232][$$240, $$267]  |PARTITIONED|
+                                              exchange
                                               -- HASH_PARTITION_EXCHANGE [$$231, $$232]  |PARTITIONED|
+                                                project ([$$231, $$232])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$232, $$231] <- [$$s.getField("s_i_id"), $$s.getField("s_w_id")]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$s])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.stock)  |PARTITIONED|
+                                                        data-scan []<-[$$233, $$s] <- test.stock
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                              exchange
                                               -- HASH_PARTITION_EXCHANGE [$$240, $$267]  |PARTITIONED|
+                                                project ([$$266, $$261, $$260, $$240, $$267])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    join (and(eq($$262, $$246), eq($$263, $$240), eq($$264, $$249)))
                                                     -- HYBRID_HASH_JOIN [$$246, $$240, $$249][$$262, $$263, $$264]  |PARTITIONED|
+                                                      exchange
                                                       -- HASH_PARTITION_EXCHANGE [$$246, $$240, $$249]  |PARTITIONED|
+                                                        project ([$$266, $$240, $$267, $$246, $$249])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$267, $$266] <- [$$ol.getField("ol_i_id"), $$ol.getField("ol_amount")]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            project ([$$249, $$246, $$240, $$ol])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              unnest $$ol <- scan-collection($$257)
                                                               -- UNNEST  |PARTITIONED|
+                                                                project ([$$249, $$246, $$240, $$257])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  select (and(ge($$239, "2016-01-01 00:00:00.000000"), lt($$239, "2017-01-01 00:00:00.000000")))
                                                                   -- STREAM_SELECT  |PARTITIONED|
+                                                                    project ([$$249, $$246, $$240, $$239, $$257])
                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                      assign [$$249, $$246, $$240, $$239, $$257] <- [$$o.getField("o_d_id"), $$o.getField("o_c_id"), $$o.getField("o_w_id"), $$o.getField("o_entry_d"), $$o.getField("o_orderline")]
                                                                       -- ASSIGN  |PARTITIONED|
+                                                                        project ([$$o])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                            -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                                                            data-scan []<-[$$234, $$o] <- test.orders
+                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                empty-tuple-source
                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                      exchange
                                                       -- HASH_PARTITION_EXCHANGE [$$262, $$263, $$264]  |PARTITIONED|
+                                                        project ([$$261, $$260, $$262, $$263, $$264])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            join (eq($$244, $$260))
                                                             -- HYBRID_HASH_JOIN [$$244][$$260]  |PARTITIONED|
+                                                              exchange
                                                               -- HASH_PARTITION_EXCHANGE [$$244]  |PARTITIONED|
+                                                                project ([$$262, $$263, $$264, $$244])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  assign [$$244, $$264, $$263, $$262] <- [get-item(string-to-codepoint($$c.getField("c_state")), 0), $$c.getField("c_d_id"), $$c.getField("c_w_id"), $$c.getField("c_id")]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    project ([$$c])
                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                        -- DATASOURCE_SCAN (test.customer)  |PARTITIONED|
+                                                                        data-scan []<-[$$235, $$c] <- test.customer
+                                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            empty-tuple-source
                                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                              exchange
                                                               -- HASH_PARTITION_EXCHANGE [$$260]  |PARTITIONED|
+                                                                project ([$$261, $$260])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    join (eq($$242, $$243))
                                                                     -- HYBRID_HASH_JOIN [$$242][$$243]  |PARTITIONED|
+                                                                      exchange
                                                                       -- HASH_PARTITION_EXCHANGE [$$242]  |PARTITIONED|
+                                                                        project ([$$261, $$260, $$242])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          assign [$$261, $$260, $$242] <- [$$n.getField("n_name"), $$n.getField("n_nationkey"), $$n.getField("n_regionkey")]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            project ([$$n])
                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                -- DATASOURCE_SCAN (test.nation)  |PARTITIONED|
+                                                                                data-scan []<-[$$236, $$n] <- test.nation
+                                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    empty-tuple-source
                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                      exchange
                                                                       -- HASH_PARTITION_EXCHANGE [$$243]  |PARTITIONED|
+                                                                        project ([$$243])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          select (eq($$r.getField("r_name"), "Asia"))
                                                                           -- STREAM_SELECT  |PARTITIONED|
+                                                                            assign [$$243] <- [$$r.getField("r_regionkey")]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              project ([$$r])
                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                  -- DATASOURCE_SCAN (test.region)  |PARTITIONED|
+                                                                                  data-scan []<-[$$237, $$r] <- test.region
+                                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                    exchange
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                      empty-tuple-source
                                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                  exchange
                                   -- HASH_PARTITION_EXCHANGE [$$252, $$255]  |PARTITIONED|
+                                    project ([$$252, $$255])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$255, $$252] <- [$$su.getField("su_suppkey"), $$su.getField("su_nationkey")]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$su])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (test.supplier)  |PARTITIONED|
+                                            data-scan []<-[$$238, $$su] <- test.supplier
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q6.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q6.plan
index 3b05b97..2fde336 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q6.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q6.plan
@@ -1,20 +1,40 @@
+distribute result [$$51]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$51])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$51] <- [{"revenue": $$54}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$54] <- [agg-global-sql-sum($$58)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$58] <- [agg-local-sql-sum($$56)]
             -- AGGREGATE  |PARTITIONED|
+              project ([$$56])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (and(gt($$56, 600), lt($$52, "2017-01-01 00:00:00.000000"), ge($$52, "2016-01-01 00:00:00.000000")))
                 -- STREAM_SELECT  |PARTITIONED|
+                  project ([$$52, $$56])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$52, $$56] <- [$$ol.getField("ol_delivery_d"), $$ol.getField("ol_amount")]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$ol])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        unnest $$ol <- scan-collection($$55)
                         -- UNNEST  |PARTITIONED|
+                          project ([$$55])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$55] <- [$$o.getField("o_orderline")]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$o])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                  data-scan []<-[$$53, $$o] <- test.orders
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q7.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q7.plan
index 4572727..0605405 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q7.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q7.plan
@@ -1,102 +1,198 @@
+distribute result [$$256]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$256])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$256] <- [{"supp_nation": $$su_nationkey, "cust_nation": $#1, "l_year": $#2, "revenue": round($$286, 2)}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$su_nationkey(ASC), $#1(ASC), $#2(ASC) ]  |PARTITIONED|
-          -- SORT_GROUP_BY[$$310, $$311, $$312]  |PARTITIONED|
-                  {
+          group by ([$$su_nationkey := $$310; $#1 := $$311; $#2 := $$312]) decor ([]) {
+                    aggregate [$$286] <- [agg-global-sql-sum($$309)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- SORT_GROUP_BY[$$310, $$311, $$312]  |PARTITIONED|
+            exchange
             -- HASH_PARTITION_EXCHANGE [$$310, $$311, $$312]  |PARTITIONED|
-              -- SORT_GROUP_BY[$$262, $$258, $$259]  |PARTITIONED|
-                      {
+              group by ([$$310 := $$262; $$311 := $$258; $$312 := $$259]) decor ([]) {
+                        aggregate [$$309] <- [agg-local-sql-sum($$298)]
                         -- AGGREGATE  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SORT_GROUP_BY[$$262, $$258, $$259]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$298, $$262, $$258, $$259])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$259, $$258] <- [get-year(date($$294)), substring1($$270, 1, 1)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$298, $$294, $$270, $$262])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          join (and(eq($$262, $$288), eq($$284, $$285)))
                           -- HYBRID_HASH_JOIN [$$288, $$284][$$262, $$285]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$288, $$284]  |PARTITIONED|
+                              project ([$$298, $$294, $$270, $$288, $$284])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$284] <- [numeric-mod(numeric-multiply($$260, $$261), 10000)]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$260, $$261, $$298, $$294, $$270, $$288])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      join (and(eq($$295, $$260), eq($$296, $$261)))
                                       -- HYBRID_HASH_JOIN [$$260, $$261][$$295, $$296]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$260, $$261]  |PARTITIONED|
+                                          project ([$$260, $$261])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$261, $$260] <- [$$s.getField("s_i_id"), $$s.getField("s_w_id")]
                                             -- ASSIGN  |PARTITIONED|
+                                              project ([$$s])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- DATASOURCE_SCAN (test.stock)  |PARTITIONED|
+                                                  data-scan []<-[$$263, $$s] <- test.stock
+                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$295, $$296]  |PARTITIONED|
+                                          project ([$$298, $$294, $$270, $$288, $$295, $$296])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              join (and(eq($$290, $$276), eq($$291, $$278), eq($$292, $$280)))
                                               -- HYBRID_HASH_JOIN [$$276, $$278, $$280][$$290, $$291, $$292]  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$276, $$278, $$280]  |PARTITIONED|
+                                                  project ([$$298, $$294, $$295, $$296, $$276, $$278, $$280])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    select (and(ge($$269, "2017-01-01 00:00:00.000000"), le($$269, "2018-12-31 00:00:00.000000")))
                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                      project ([$$294, $$280, $$278, $$276, $$298, $$296, $$295, $$269])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$298, $$296, $$295, $$269] <- [$$ol.getField("ol_amount"), $$ol.getField("ol_i_id"), $$ol.getField("ol_supply_w_id"), $$ol.getField("ol_delivery_d")]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          project ([$$294, $$280, $$278, $$276, $$ol])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            unnest $$ol <- scan-collection($$287)
                                                             -- UNNEST  |PARTITIONED|
+                                                              project ([$$294, $$280, $$278, $$276, $$287])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$294, $$280, $$278, $$276, $$287] <- [$$o.getField("o_entry_d"), $$o.getField("o_d_id"), $$o.getField("o_w_id"), $$o.getField("o_c_id"), $$o.getField("o_orderline")]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  project ([$$o])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                                                      data-scan []<-[$$264, $$o] <- test.orders
+                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          empty-tuple-source
                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$290, $$291, $$292]  |PARTITIONED|
+                                                  project ([$$270, $$288, $$290, $$291, $$292])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      join (eq($$273, $$289))
                                                       -- HYBRID_HASH_JOIN [$$273][$$289]  |PARTITIONED|
+                                                        exchange
                                                         -- HASH_PARTITION_EXCHANGE [$$273]  |PARTITIONED|
+                                                          assign [$$273] <- [get-item(string-to-codepoint($$270), 0)]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            project ([$$292, $$291, $$290, $$270])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$292, $$291, $$290, $$270] <- [$$c.getField("c_d_id"), $$c.getField("c_w_id"), $$c.getField("c_id"), $$c.getField("c_state")]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                project ([$$c])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (test.customer)  |PARTITIONED|
+                                                                    data-scan []<-[$$265, $$c] <- test.customer
+                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        empty-tuple-source
                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                        exchange
                                                         -- HASH_PARTITION_EXCHANGE [$$289]  |PARTITIONED|
+                                                          project ([$$288, $$289])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              join (or(and(eq($$271, "Germany"), eq($$272, "Cambodia")), and(eq($$271, "Cambodia"), eq($$272, "Germany"))))
                                                               -- NESTED_LOOP  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  project ([$$288, $$271])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    assign [$$288, $$271] <- [$$289, $$272]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        replicate
                                                                         -- REPLICATE  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            project ([$$289, $$272])
                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                              assign [$$289, $$272] <- [$$n2.getField("n_nationkey"), $$n2.getField("n_name")]
                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                project ([$$n2])
                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                    -- DATASOURCE_SCAN (test.nation)  |PARTITIONED|
+                                                                                    data-scan []<-[$$267, $$n2] <- test.nation
+                                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                        empty-tuple-source
                                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                exchange
                                                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                  replicate
                                                                   -- REPLICATE  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      project ([$$289, $$272])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        assign [$$289, $$272] <- [$$n2.getField("n_nationkey"), $$n2.getField("n_name")]
                                                                         -- ASSIGN  |PARTITIONED|
+                                                                          project ([$$n2])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                              -- DATASOURCE_SCAN (test.nation)  |PARTITIONED|
+                                                                              data-scan []<-[$$267, $$n2] <- test.nation
+                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  empty-tuple-source
                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$262, $$285]  |PARTITIONED|
+                              project ([$$262, $$285])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$285, $$262] <- [$$su.getField("su_suppkey"), $$su.getField("su_nationkey")]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$su])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.supplier)  |PARTITIONED|
+                                      data-scan []<-[$$268, $$su] <- test.supplier
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q8.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q8.plan
index 3c62aa7..4f8c21a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q8.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q8.plan
@@ -1,128 +1,250 @@
+distribute result [$$277]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$277])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$277] <- [{"l_year": $#1, "mkt_share": round(numeric-divide($$306, $$307), 2)}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$#1(ASC) ]  |PARTITIONED|
-          -- SORT_GROUP_BY[$$333]  |PARTITIONED|
-                  {
+          group by ([$#1 := $$333]) decor ([]) {
+                    aggregate [$$306, $$307] <- [agg-global-sql-sum($$331), agg-global-sql-sum($$332)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- SORT_GROUP_BY[$$333]  |PARTITIONED|
+            exchange
             -- HASH_PARTITION_EXCHANGE [$$333]  |PARTITIONED|
-              -- SORT_GROUP_BY[$$278]  |PARTITIONED|
-                      {
+              group by ([$$333 := $$278]) decor ([]) {
+                        aggregate [$$331, $$332] <- [agg-local-sql-sum(switch-case(true, eq($$326, "Germany"), $$319, 0)), agg-local-sql-sum($$319)]
                         -- AGGREGATE  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SORT_GROUP_BY[$$278]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$326, $$319, $$278])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$278] <- [get-year(date($$289))]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$319, $$289, $$326])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          join (eq($$304, $$325))
                           -- HYBRID_HASH_JOIN [$$304][$$325]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$304]  |PARTITIONED|
+                              project ([$$319, $$289, $$304])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$304] <- [numeric-mod(numeric-multiply($$279, $$280), 10000)]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$279, $$280, $$319, $$289])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      join (and(eq($$290, $$280), eq($$320, $$279)))
                                       -- HYBRID_HASH_JOIN [$$280, $$279][$$290, $$320]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$280, $$279]  |PARTITIONED|
+                                          project ([$$279, $$280])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$280, $$279] <- [$$s.getField("s_i_id"), $$s.getField("s_w_id")]
                                             -- ASSIGN  |PARTITIONED|
+                                              project ([$$s])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- DATASOURCE_SCAN (test.stock)  |PARTITIONED|
+                                                  data-scan []<-[$$281, $$s] <- test.stock
+                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$290, $$320]  |PARTITIONED|
+                                          project ([$$319, $$289, $$290, $$320])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              join (and(eq($$317, $$297), eq($$318, $$299), eq($$316, $$301)))
                                               -- HYBRID_HASH_JOIN [$$297, $$299, $$301][$$317, $$318, $$316]  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$297, $$299, $$301]  |PARTITIONED|
+                                                  project ([$$319, $$289, $$290, $$320, $$297, $$299, $$301])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      join (eq($$308, $$290))
                                                       -- HYBRID_HASH_JOIN [$$290][$$308]  |PARTITIONED|
+                                                        exchange
                                                         -- HASH_PARTITION_EXCHANGE [$$290]  |PARTITIONED|
+                                                          select (lt($$290, 1000))
                                                           -- STREAM_SELECT  |PARTITIONED|
+                                                            project ([$$301, $$299, $$297, $$289, $$320, $$319, $$290])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$320, $$319, $$290] <- [$$ol.getField("ol_supply_w_id"), $$ol.getField("ol_amount"), $$ol.getField("ol_i_id")]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                project ([$$301, $$299, $$297, $$289, $$ol])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  unnest $$ol <- scan-collection($$311)
                                                                   -- UNNEST  |PARTITIONED|
+                                                                    select (and(le($$289, "2018-12-31 00:00:00.000000"), ge($$289, "2017-01-01 00:00:00.000000")))
                                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                                      project ([$$301, $$299, $$297, $$289, $$311])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        assign [$$301, $$299, $$297, $$289, $$311] <- [$$o.getField("o_c_id"), $$o.getField("o_d_id"), $$o.getField("o_w_id"), $$o.getField("o_entry_d"), $$o.getField("o_orderline")]
                                                                         -- ASSIGN  |PARTITIONED|
+                                                                          project ([$$o])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                              -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                                                              data-scan []<-[$$282, $$o] <- test.orders
+                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  empty-tuple-source
                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                        exchange
                                                         -- HASH_PARTITION_EXCHANGE [$$308]  |PARTITIONED|
+                                                          project ([$$308])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            select (like($$i.getField("i_data"), "%b"))
                                                             -- STREAM_SELECT  |PARTITIONED|
+                                                              assign [$$308] <- [$$i.getField("i_id")]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                project ([$$i])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (test.item)  |PARTITIONED|
+                                                                    data-scan []<-[$$283, $$i] <- test.item
+                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        empty-tuple-source
                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$317, $$318, $$316]  |PARTITIONED|
+                                                  project ([$$317, $$318, $$316])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      join (eq($$315, $$295))
                                                       -- HYBRID_HASH_JOIN [$$295][$$315]  |PARTITIONED|
+                                                        exchange
                                                         -- HASH_PARTITION_EXCHANGE [$$295]  |PARTITIONED|
+                                                          project ([$$317, $$318, $$316, $$295])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            assign [$$295, $$318, $$317, $$316] <- [get-item(string-to-codepoint($$c.getField("c_state")), 0), $$c.getField("c_d_id"), $$c.getField("c_w_id"), $$c.getField("c_id")]
                                                             -- ASSIGN  |PARTITIONED|
+                                                              project ([$$c])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- DATASOURCE_SCAN (test.customer)  |PARTITIONED|
+                                                                  data-scan []<-[$$284, $$c] <- test.customer
+                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      empty-tuple-source
                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                        exchange
                                                         -- HASH_PARTITION_EXCHANGE [$$315]  |PARTITIONED|
+                                                          project ([$$315])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              join (eq($$292, $$293))
                                                               -- HYBRID_HASH_JOIN [$$292][$$293]  |PARTITIONED|
+                                                                exchange
                                                                 -- HASH_PARTITION_EXCHANGE [$$292]  |PARTITIONED|
+                                                                  project ([$$315, $$292])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    assign [$$315, $$292] <- [$$n1.getField("n_nationkey"), $$n1.getField("n_regionkey")]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        replicate
                                                                         -- REPLICATE  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            project ([$$n1])
                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                -- DATASOURCE_SCAN (test.nation)  |PARTITIONED|
+                                                                                data-scan []<-[$$285, $$n1] <- test.nation
+                                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    empty-tuple-source
                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                exchange
                                                                 -- HASH_PARTITION_EXCHANGE [$$293]  |PARTITIONED|
+                                                                  project ([$$293])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    select (eq($$r.getField("r_name"), "Europe"))
                                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                                      assign [$$293] <- [$$r.getField("r_regionkey")]
                                                                       -- ASSIGN  |PARTITIONED|
+                                                                        project ([$$r])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                            -- DATASOURCE_SCAN (test.region)  |PARTITIONED|
+                                                                            data-scan []<-[$$286, $$r] <- test.region
+                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                empty-tuple-source
                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$325]  |PARTITIONED|
+                              project ([$$326, $$325])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  join (eq($$309, $$310))
                                   -- HYBRID_HASH_JOIN [$$309][$$310]  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$309]  |PARTITIONED|
+                                      project ([$$325, $$309])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$325, $$309] <- [$$su.getField("su_suppkey"), $$su.getField("su_nationkey")]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$su])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.supplier)  |PARTITIONED|
+                                              data-scan []<-[$$287, $$su] <- test.supplier
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$310]  |PARTITIONED|
+                                      project ([$$326, $$310])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$326, $$310] <- [$$n2.getField("n_name"), $$n2.getField("n_nationkey")]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$n2])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$n2] <- [$$n1]
                                             -- ASSIGN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                replicate
                                                 -- REPLICATE  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$$n1])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.nation)  |PARTITIONED|
+                                                        data-scan []<-[$$285, $$n1] <- test.nation
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q9.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q9.plan
index 97037d6..5ce5c73 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q9.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/ch2/ch2_q9.plan
@@ -1,81 +1,156 @@
+distribute result [$$184]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$184])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$184] <- [{"n_name": $$n_name, "l_year": $#1, "SUM_profit": round($$200, 2)}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$n_name(ASC), $#1(DESC) ]  |PARTITIONED|
-          -- SORT_GROUP_BY[$$217, $$218]  |PARTITIONED|
-                  {
+          group by ([$$n_name := $$217; $#1 := $$218]) decor ([]) {
+                    aggregate [$$200] <- [agg-global-sql-sum($$216)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- SORT_GROUP_BY[$$217, $$218]  |PARTITIONED|
+            exchange
             -- HASH_PARTITION_EXCHANGE [$$217, $$218]  |PARTITIONED|
-              -- SORT_GROUP_BY[$$213, $$186]  |PARTITIONED|
-                      {
+              group by ([$$217 := $$213; $$218 := $$186]) decor ([]) {
+                        aggregate [$$216] <- [agg-local-sql-sum($$206)]
                         -- AGGREGATE  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SORT_GROUP_BY[$$213, $$186]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$206, $$213, $$186])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$186] <- [get-year(date($$207))]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$206, $$207, $$213])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          join (eq($$198, $$212))
                           -- HYBRID_HASH_JOIN [$$198][$$212]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$198]  |PARTITIONED|
+                              project ([$$206, $$207, $$198])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$198] <- [numeric-mod(numeric-multiply($$187, $$188), 10000)]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$187, $$188, $$206, $$207])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      join (and(eq($$194, $$188), eq($$205, $$187)))
                                       -- HYBRID_HASH_JOIN [$$188, $$187][$$194, $$205]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$188]  |PARTITIONED|
+                                          project ([$$187, $$188])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$188, $$187] <- [$$s.getField("s_i_id"), $$s.getField("s_w_id")]
                                             -- ASSIGN  |PARTITIONED|
+                                              project ([$$s])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- DATASOURCE_SCAN (test.stock)  |PARTITIONED|
+                                                  data-scan []<-[$$189, $$s] <- test.stock
+                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$206, $$207, $$194, $$205])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              join (eq($$194, $$195))
                                               -- HYBRID_HASH_JOIN [$$194][$$195]  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$194]  |PARTITIONED|
+                                                  project ([$$206, $$207, $$194, $$205])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    assign [$$206, $$205, $$194] <- [$$ol.getField("ol_amount"), $$ol.getField("ol_supply_w_id"), $$ol.getField("ol_i_id")]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      project ([$$207, $$ol])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        unnest $$ol <- scan-collection($$203)
                                                         -- UNNEST  |PARTITIONED|
+                                                          project ([$$207, $$203])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            assign [$$207, $$203] <- [$$o.getField("o_entry_d"), $$o.getField("o_orderline")]
                                                             -- ASSIGN  |PARTITIONED|
+                                                              project ([$$o])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                                                  data-scan []<-[$$190, $$o] <- test.orders
+                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      empty-tuple-source
                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$195]  |PARTITIONED|
+                                                  project ([$$195])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    select (like($$i.getField("i_data"), "%bb"))
                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                      assign [$$195] <- [$$i.getField("i_id")]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        project ([$$i])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- DATASOURCE_SCAN (test.item)  |PARTITIONED|
+                                                            data-scan []<-[$$191, $$i] <- test.item
+                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                empty-tuple-source
                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$212]  |PARTITIONED|
+                              project ([$$213, $$212])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  join (eq($$201, $$202))
                                   -- HYBRID_HASH_JOIN [$$201][$$202]  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$201]  |PARTITIONED|
+                                      project ([$$212, $$201])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$212, $$201] <- [$$su.getField("su_suppkey"), $$su.getField("su_nationkey")]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$su])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.supplier)  |PARTITIONED|
+                                              data-scan []<-[$$192, $$su] <- test.supplier
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$202]  |PARTITIONED|
+                                      project ([$$213, $$202])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$213, $$202] <- [$$n.getField("n_name"), $$n.getField("n_nationkey")]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$n])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.nation)  |PARTITIONED|
+                                              data-scan []<-[$$193, $$n] <- test.nation
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/collocated.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/collocated.plan
index 02a8214..66a4651 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/collocated.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/collocated.plan
@@ -1,21 +1,42 @@
+distribute result [$$29]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$29])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$29] <- [{"user_name": $$34, "visitor_name": $$35}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$34, $$35])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$30, $$31))
             -- HYBRID_HASH_JOIN [$$30][$$31]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$34, $$30])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$34] <- [$$user.getField(1)]
                   -- ASSIGN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (colocated.Users)  |PARTITIONED|
+                      data-scan []<-[$$30, $$user] <- colocated.Users
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$35, $$31])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$35] <- [$$visitor.getField(1)]
                   -- ASSIGN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (colocated.Visitors)  |PARTITIONED|
+                      data-scan []<-[$$31, $$visitor] <- colocated.Visitors
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/common-expr-01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/common-expr-01.plan
index 616e808..672afc7 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/common-expr-01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/common-expr-01.plan
@@ -1,68 +1,127 @@
+distribute result [$$167]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$167])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$167] <- [{"c11": $$c11, "c3": $$c3, "$1": $$175}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- SORT_GROUP_BY[$$185, $$186]  |PARTITIONED|
-                  {
+          group by ([$$c3 := $$185; $$c11 := $$186]) decor ([]) {
+                    aggregate [$$175] <- [agg-global-sql-sum($$184)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- SORT_GROUP_BY[$$185, $$186]  |PARTITIONED|
+            exchange
             -- HASH_PARTITION_EXCHANGE [$$185, $$186]  |PARTITIONED|
-              -- SORT_GROUP_BY[$$168, $$169]  |PARTITIONED|
-                      {
+              group by ([$$185 := $$168; $$186 := $$169]) decor ([]) {
+                        aggregate [$$184] <- [agg-local-sql-sum($$165)]
                         -- AGGREGATE  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SORT_GROUP_BY[$$168, $$169]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$165, $$168, $$169])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$169] <- [get-hour(duration-from-interval(interval(parse-datetime(print-datetime(current-datetime(), "YYYY-MM-DDThh:mm:ss"), "YYYY-MM-DDThh:mm:ss"), parse-datetime($$174, "YYYY-MM-DDThh:mm:ss"))))]
                     -- ASSIGN  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        join (true)
                         -- NESTED_LOOP  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$165, $$168])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$168, $$165] <- [get-month(print-datetime(parse-datetime($$170, "YYYY-MM-DDThh:mm:ss"), "YYYY-MM-DDThh:mm:ss")), switch-case(true, contains($$171, "x"), 1, 0)]
                               -- ASSIGN  |PARTITIONED|
+                                project ([$$170, $$171])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  select ($$155)
                                   -- STREAM_SELECT  |PARTITIONED|
+                                    project ([$$155, $$170, $$171])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- PRE_CLUSTERED_GROUP_BY[$$172]  |PARTITIONED|
-                                                {
+                                        group by ([$$182 := $$172]) decor ([$$170; $$171]) {
+                                                  aggregate [$$155] <- [empty-stream()]
                                                   -- AGGREGATE  |LOCAL|
+                                                    select (not(is-missing($$181)))
                                                     -- STREAM_SELECT  |LOCAL|
+                                                      nested tuple source
                                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                }
+                                               }
+                                        -- PRE_CLUSTERED_GROUP_BY[$$172]  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            order (ASC, $$172)
                                             -- STABLE_SORT [$$172(ASC)]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$170, $$171, $$181, $$172])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    left outer join (not(if-missing-or-null(neq($$171, $#6), false)))
                                                     -- NESTED_LOOP  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        select (le(get-day(duration-from-interval(interval(parse-datetime(print-datetime(current-datetime(), "YYYY-MM-DDThh:mm:ss"), "YYYY-MM-DDThh:mm:ss"), parse-datetime($$170, "YYYY-MM-DDThh:mm:ss")))), 30))
                                                         -- STREAM_SELECT  |PARTITIONED|
+                                                          project ([$$172, $$171, $$170])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            assign [$$171, $$170] <- [$$t1.getField("c2"), $$t1.getField("c1")]
                                                             -- ASSIGN  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                replicate
                                                                 -- REPLICATE  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (test.t1)  |PARTITIONED|
+                                                                    data-scan []<-[$$172, $$t1] <- test.t1
+                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        empty-tuple-source
                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                      exchange
                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                        assign [$$181] <- [true]
                                                         -- ASSIGN  |UNPARTITIONED|
+                                                          unnest $#6 <- scan-collection(array: [ "a", "b", "c", "d" ])
                                                           -- UNNEST  |UNPARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                          exchange
                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                            aggregate [$$174] <- [agg-global-sql-max($$187)]
                             -- AGGREGATE  |UNPARTITIONED|
+                              exchange
                               -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                                aggregate [$$187] <- [agg-local-sql-max($$139)]
                                 -- AGGREGATE  |PARTITIONED|
+                                  project ([$$139])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$139] <- [print-datetime(parse-datetime($$t1.getField("c5"), "YYYY-MM-DDThh:mm:ss"), "YYYY-MM-DDThh:mm:ss")]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$t1])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$173, $$t1] <- [$$172, $$t1]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- DATASOURCE_SCAN (test.t1)  |PARTITIONED|
+                                                data-scan []<-[$$172, $$t1] <- test.t1
+                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/composite-key/composite-prefix-low-high.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/composite-key/composite-prefix-low-high.plan
index 5639621..49af3a4 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/composite-key/composite-prefix-low-high.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/composite-key/composite-prefix-low-high.plan
@@ -1,9 +1,18 @@
+distribute result [$$21]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$21])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$21] <- [{"x": $$25, "y": $$26, "z": $$Points.getField(2)}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$25(ASC), $$26(ASC) ]  |PARTITIONED|
-          -- BTREE_SEARCH (test.Points.Points)  |PARTITIONED|
+          unnest-map [$$25, $$26, $$Points] <- index-search("Points", 0, "test", "Points", false, false, 1, $$31, 1, $$32, true, true, false)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              assign [$$31, $$32] <- [2, 3]
               -- ASSIGN  |PARTITIONED|
+                empty-tuple-source
                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/cust_group_no_agg.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/cust_group_no_agg.plan
index 7afa33f..8092fc7 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/cust_group_no_agg.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/cust_group_no_agg.plan
@@ -1,15 +1,27 @@
+distribute result [$$name]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- SORT_GROUP_BY[$$34]  |PARTITIONED|
-            {
+    group by ([$$name := $$34]) decor ([]) {
+              aggregate [] <- []
               -- AGGREGATE  |LOCAL|
+                nested tuple source
                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-            }
+           }
+    -- SORT_GROUP_BY[$$34]  |PARTITIONED|
+      exchange
       -- HASH_PARTITION_EXCHANGE [$$34]  |PARTITIONED|
+        project ([$$34])
         -- STREAM_PROJECT  |PARTITIONED|
+          assign [$$34] <- [$$c.getField(1)]
           -- ASSIGN  |PARTITIONED|
+            project ([$$c])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (group_no_agg.Customers)  |PARTITIONED|
+                data-scan []<-[$$35, $$c] <- group_no_agg.Customers
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/denorm-cust-order.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/denorm-cust-order.plan
index 5516a6f..c38457b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/denorm-cust-order.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/denorm-cust-order.plan
@@ -1,27 +1,51 @@
+distribute result [$$90]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$90])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$90] <- [{"cid": $$cid, "cust": $$81, "cnt-orders": $$96, "orders": $$89}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- PRE_CLUSTERED_GROUP_BY[$$93]  |PARTITIONED|
-                  {
+          group by ([$$cid := $$93]) decor ([]) {
+                    aggregate [$$81, $$89, $$96] <- [listify({"c": $$c}), listify({"o": $$o}), agg-sql-count($$o)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- PRE_CLUSTERED_GROUP_BY[$$93]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$93)
               -- STABLE_SORT [$$93(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$c, $$o, $$93])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (eq($$93, $$95))
                       -- HYBRID_HASH_JOIN [$$93][$$95]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (custorder.Customers)  |PARTITIONED|
+                          data-scan []<-[$$93, $$c] <- custorder.Customers
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$95]  |PARTITIONED|
+                          assign [$$95] <- [$$o.getField(1)]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$o])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (custorder.Orders)  |PARTITIONED|
+                                data-scan []<-[$$94, $$o] <- custorder.Orders
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/disjunction-to-join-delete-3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/disjunction-to-join-delete-3.plan
index b6f3cb4..7948e7d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/disjunction-to-join-delete-3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/disjunction-to-join-delete-3.plan
@@ -1,25 +1,50 @@
+commit
 -- COMMIT  |PARTITIONED|
+  project ([$$18])
   -- STREAM_PROJECT  |PARTITIONED|
+    exchange
     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+      delete from TestSetIndex on test.TestSet from [$$22]
       -- INDEX_INSERT_DELETE  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          project ([$$22, $$18])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              delete from test.TestSet from record: $$TestSet partitioned by [$$18]
               -- INSERT_DELETE  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  materialize
                   -- MATERIALIZE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      assign [$$22, $$18] <- [$$TestSet.getField(1), $$TestSet.getField(0)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$TestSet])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            join (eq($$21, $$19))
                             -- HYBRID_HASH_JOIN [$$19][$$21]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                assign [$$19] <- [$$TestSet.getField(2)]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$TestSet])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.TestSet)  |PARTITIONED|
+                                      data-scan []<-[$$20, $$TestSet] <- test.TestSet
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                unnest $$21 <- scan-collection(array: [ "one", "two" ])
                                 -- UNNEST  |UNPARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/external-cross-product.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/external-cross-product.plan
index fd95cc1..8995fb5 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/external-cross-product.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/external-cross-product.plan
@@ -1,45 +1,90 @@
+distribute result [$$54]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$54])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$54] <- [{"$1": $$55}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$55] <- [agg-sql-sum($$56)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$56] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                join (true)
                 -- NESTED_LOOP  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    join (true)
                     -- NESTED_LOOP  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [] <- []
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              replicate
                               -- REPLICATE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.Orders)  |PARTITIONED|
+                                      data-scan []<-[$$o2] <- test.Orders
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        replicate
                         -- REPLICATE  |PARTITIONED|
+                          exchange
                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (test.Orders)  |PARTITIONED|
+                                    data-scan []<-[$$o2] <- test.Orders
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [] <- []
                       -- ASSIGN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                              replicate
                               -- REPLICATE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.Orders)  |PARTITIONED|
+                                      data-scan []<-[$$o2] <- test.Orders
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/extract-common-operators/extract-common-operators.01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/extract-common-operators/extract-common-operators.01.plan
index 677a45f..b551390 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/extract-common-operators/extract-common-operators.01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/extract-common-operators/extract-common-operators.01.plan
@@ -1,98 +1,196 @@
+distribute result [$$373]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$373])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$373] <- [{"DataverseName": $$381, "SynonymName": $$382}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$381(ASC), $$382(ASC) ]  |PARTITIONED|
+          order (ASC, $$381) (ASC, $$382)
           -- STABLE_SORT [$$381(ASC), $$382(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$381, $$382])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  left outer join (eq($$390, $$386))
                   -- HYBRID_HASH_JOIN [$$390][$$386]  |PARTITIONED|
+                    exchange
                     -- HASH_PARTITION_MERGE_EXCHANGE MERGE:[$$381(ASC), $$382(ASC)] HASH:[$$390]  |PARTITIONED|
+                      order (ASC, $$381) (ASC, $$382)
                       -- STABLE_SORT [$$381(ASC), $$382(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$381, $$382, $$390])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              left outer join (eq($$384, $$390))
                               -- HYBRID_HASH_JOIN [$$390][$$384]  |PARTITIONED|
+                                exchange
                                 -- HASH_PARTITION_EXCHANGE [$$390]  |PARTITIONED|
+                                  project ([$$381, $$382, $$390])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$390] <- [$$s.getField(3)]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$381, $$382, $$s])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$381, $$382, $$s] <- [$$385, $$386, $$s]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- DATASOURCE_SCAN (Metadata.Synonym)  |PARTITIONED|
+                                                data-scan []<-[$$385, $$386, $$s] <- Metadata.Synonym
+                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                exchange
                                 -- HASH_PARTITION_EXCHANGE [$$384]  |PARTITIONED|
+                                  project ([$$384])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      join (and(eq($$384, $$ds_name), eq($$383, $$dv_name)))
                                       -- HYBRID_HASH_JOIN [$$384, $$383][$$ds_name, $$dv_name]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          replicate
                                           -- REPLICATE  |PARTITIONED|
+                                            exchange
                                             -- HASH_PARTITION_EXCHANGE [$$384, $$383]  |PARTITIONED|
+                                              project ([$$384, $$383])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- DATASOURCE_SCAN (Metadata.Dataset)  |PARTITIONED|
+                                                  data-scan []<-[$$383, $$384, $$d] <- Metadata.Dataset
+                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$ds_name, $$dv_name]  |PARTITIONED|
+                                          join (true)
                                           -- NESTED_LOOP  |UNPARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                              unnest $$dv_name <- scan-collection(array: [ "test2", "test1" ])
                                               -- UNNEST  |UNPARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                              replicate
                                               -- REPLICATE  |UNPARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                  unnest $$ds_name <- scan-collection(array: [ "ds2", "ds1" ])
                                                   -- UNNEST  |UNPARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                    exchange
                     -- HASH_PARTITION_EXCHANGE [$$386]  |PARTITIONED|
+                      project ([$$386])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          left outer join (eq($$388, $$404))
                           -- HYBRID_HASH_JOIN [$$404][$$388]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$404]  |PARTITIONED|
+                              project ([$$386, $$404])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  join (eq($$386, $$syn_name))
                                   -- HYBRID_HASH_JOIN [$$386][$$syn_name]  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$386]  |PARTITIONED|
+                                      project ([$$386, $$404])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$404] <- [$$s.getField(3)]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$386, $$s])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              replicate
                                               -- REPLICATE  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- DATASOURCE_SCAN (Metadata.Synonym)  |PARTITIONED|
+                                                  data-scan []<-[$$385, $$386, $$s] <- Metadata.Synonym
+                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$syn_name]  |PARTITIONED|
+                                      unnest $$syn_name <- scan-collection(array: [ "syn2", "syn1" ])
                                       -- UNNEST  |UNPARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$388]  |PARTITIONED|
+                              project ([$$388])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  join (and(eq($$388, $$ds_name), eq($$387, $$dv_name)))
                                   -- HYBRID_HASH_JOIN [$$388, $$387][$$ds_name, $$dv_name]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$388, $$387])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$388, $$387] <- [$$384, $$383]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- HASH_PARTITION_EXCHANGE [$$384, $$383]  |PARTITIONED|
+                                                project ([$$384, $$383])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (Metadata.Dataset)  |PARTITIONED|
+                                                    data-scan []<-[$$383, $$384, $$d] <- Metadata.Dataset
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$ds_name, $$dv_name]  |PARTITIONED|
+                                      join (true)
                                       -- NESTED_LOOP  |UNPARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                          project ([$$ds_name])
                                           -- STREAM_PROJECT  |UNPARTITIONED|
+                                            assign [$$ds_name] <- [$$ds_name]
                                             -- ASSIGN  |UNPARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                replicate
                                                 -- REPLICATE  |UNPARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                    unnest $$ds_name <- scan-collection(array: [ "ds2", "ds1" ])
                                                     -- UNNEST  |UNPARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                          unnest $$dv_name <- scan-collection(array: [ "test2", "test1" ])
                                           -- UNNEST  |UNPARTITIONED|
-                                            -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
\ No newline at end of file
+                                            empty-tuple-source
+                                            -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter/inverted-btree-search-return-optional-field.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter/inverted-btree-search-return-optional-field.plan
index 21e4b56..4b827e7 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter/inverted-btree-search-return-optional-field.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter/inverted-btree-search-return-optional-field.plan
@@ -1,29 +1,58 @@
+distribute result [$$37]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    limit 2147483647 offset 0
     -- STREAM_LIMIT  |UNPARTITIONED|
+      project ([$$37])
       -- STREAM_PROJECT  |PARTITIONED|
+        assign [$$37] <- [{"place.bounding_box": $$44, "user.id": $$45, "id": $$40, "coordinate": $$47, "create_at": $$39}]
         -- ASSIGN  |PARTITIONED|
+          exchange
           -- SORT_MERGE_EXCHANGE [$$39(DESC) ]  |PARTITIONED|
+            limit 2147483647
             -- STREAM_LIMIT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (topK: 2147483647) (DESC, $$39)
                 -- STABLE_SORT [topK: 2147483647] [$$39(DESC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$44, $$45, $$40, $$47, $$39])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        join (eq($$41, $$26))
                         -- HYBRID_HASH_JOIN [$$26][$$41]  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$44, $$45, $$40, $$47, $$39, $$26])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              select (and(ftcontains($$t.getField(2), array: [ "francisco" ], "mode", "all"), ge($$39, datetime: { 2018-02-22T10:53:07.888 }), lt($$39, datetime: { 2018-02-22T18:50:39.301 })))
                               -- STREAM_SELECT  |PARTITIONED|
+                                assign [$$26, $$44, $$45, $$47, $$39] <- [$$t.getField(14).getField(0), $$t.getField(13).getField(6), $$t.getField(12).getField(0), $$t.getField(6), $$t.getField(0)]
                                 -- ASSIGN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- BTREE_SEARCH (twitter.ds_tweet.ds_tweet)  |PARTITIONED|
+                                    unnest-map [$$40, $$t] <- index-search("ds_tweet", 0, "twitter", "ds_tweet", false, false, 1, $$52, 1, $$52, true, true, true) with filter on min:[$$53] max:[$$54]
+                                    -- BTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        order (ASC, $$52)
                                         -- STABLE_SORT [$$52(ASC)]  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- SINGLE_PARTITION_INVERTED_INDEX_SEARCH (twitter.ds_tweet.text_idx)  |PARTITIONED|
+                                            unnest-map [$$52, $$53, $$54] <- index-search("text_idx", 2, "twitter", "ds_tweet", false, false, 0, null, 21, true, 1, $$51)
+                                            -- SINGLE_PARTITION_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$51] <- [array: [ "francisco" ]]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                            unnest $$41 <- scan-collection(array: [ 51, 37, 24, 11 ])
                             -- UNNEST  |UNPARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_0.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_0.plan
index cb2b171..7ee3c68 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_0.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_0.plan
@@ -1,11 +1,22 @@
+distribute result [$$15]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$15])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$15] <- [{"KVStore": $$KVStore}]
       -- ASSIGN  |PARTITIONED|
+        select (gt($$KVStore.getField(0), 10))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$KVStore])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- DATASOURCE_SCAN (KeyVerse.KVStore)  |PARTITIONED|
+              data-scan []<-[$$16, $$KVStore, $$17] <- KeyVerse.KVStore with filter on min:[$$19] max:[]
+              -- DATASOURCE_SCAN  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  assign [$$19] <- [10]
                   -- ASSIGN  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_1.plan
index 38c95ba..baadad7 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_1.plan
@@ -1,12 +1,24 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"KVStore": $$KVStore}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$KVStore])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (gt($$18.getField(6), 11))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$KVStore, $$18])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (KeyVerse.KVStore)  |PARTITIONED|
+                data-scan []<-[$$17, $$KVStore, $$18] <- KeyVerse.KVStore with filter on min:[$$20] max:[]
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    assign [$$20] <- [11]
                     -- ASSIGN  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_2.plan
index 38c95ba..44e6fd9 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_2.plan
@@ -1,12 +1,24 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$17] <- [{"k": $$k, "meta": $$20}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$k, $$20])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (gt($$19, 12))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$19, $$k, $$20])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (KeyVerse.KVStore)  |PARTITIONED|
+                data-scan []<-[$$19, $$k, $$20] <- KeyVerse.KVStore with filter on min:[$$22] max:[]
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    assign [$$22] <- [12]
                     -- ASSIGN  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_3.plan
index cb2b171..7ee3c68 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_3.plan
@@ -1,11 +1,22 @@
+distribute result [$$15]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$15])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$15] <- [{"KVStore": $$KVStore}]
       -- ASSIGN  |PARTITIONED|
+        select (gt($$KVStore.getField(0), 10))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$KVStore])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- DATASOURCE_SCAN (KeyVerse.KVStore)  |PARTITIONED|
+              data-scan []<-[$$16, $$KVStore, $$17] <- KeyVerse.KVStore with filter on min:[$$19] max:[]
+              -- DATASOURCE_SCAN  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  assign [$$19] <- [10]
                   -- ASSIGN  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_4.plan
index 38c95ba..8d8b72d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_4.plan
@@ -1,12 +1,24 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"KVStore": $$KVStore}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$KVStore])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (gt($$18.getField(8), 10))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$KVStore, $$18])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (KeyVerse.KVStore)  |PARTITIONED|
+                data-scan []<-[$$17, $$KVStore, $$18] <- KeyVerse.KVStore with filter on min:[$$20] max:[]
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    assign [$$20] <- [10]
                     -- ASSIGN  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_5.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_5.plan
index 38c95ba..faa30a1 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_5.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_5.plan
@@ -1,12 +1,24 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"KVStore": $$KVStore}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$KVStore])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (gt($$19.getField(8), 10))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$KVStore, $$19])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (KeyVerse.KVStore)  |PARTITIONED|
+                data-scan []<-[$$17, $$18, $$KVStore, $$19] <- KeyVerse.KVStore with filter on min:[$$21] max:[]
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    assign [$$21] <- [10]
                     -- ASSIGN  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_with_idx_0.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_with_idx_0.plan
index ece21bd..a369802 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_with_idx_0.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_with_idx_0.plan
@@ -1,53 +1,106 @@
+distribute result [$$32]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    union ($$71, $$96, $$32)
     -- UNION_ALL  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$71])
         -- STREAM_PROJECT  |PARTITIONED|
+          assign [$$71] <- [{"t": $$t}]
           -- ASSIGN  |PARTITIONED|
+            project ([$$t])
             -- STREAM_PROJECT  |PARTITIONED|
+              select (spatial-intersect($$36, $$68.getField(1)))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$t, $$36, $$68])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- BTREE_SEARCH (test.OfficerLocations.OfficerLocations)  |PARTITIONED|
+                    unnest-map [$$67, $$68] <- index-search("OfficerLocations", 0, "test", "OfficerLocations", true, false, 1, $$48, 1, $$48, true, true, true)
+                    -- BTREE_SEARCH  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$t, $$36, $$48])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            split ($$49)
                             -- SPLIT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$t, $$36, $$44, $$45, $$48, $$49])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- RTREE_SEARCH (test.OfficerLocations.o_location)  |PARTITIONED|
+                                    unnest-map [$$44, $$45, $$46, $$47, $$48, $$49] <- index-search("o_location", 1, "test", "OfficerLocations", true, true, 4, $$40, $$41, $$42, $$43)
+                                    -- RTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                        assign [$$40, $$41, $$42, $$43] <- [create-mbr($$36, 2, 0), create-mbr($$36, 2, 1), create-mbr($$36, 2, 2), create-mbr($$36, 2, 3)]
                                         -- ASSIGN  |PARTITIONED|
+                                          assign [$$36] <- [create-circle($$t.getField(0), 100.0)]
                                           -- ASSIGN  |PARTITIONED|
+                                            project ([$$t])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              select (gt($$34.getField(2), 100))
                                               -- STREAM_SELECT  |PARTITIONED|
+                                                project ([$$t, $$34])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (test.KVStore)  |PARTITIONED|
+                                                    data-scan []<-[$$33, $$t, $$34] <- test.KVStore with filter on min:[$$70] max:[]
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                        assign [$$70] <- [100]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$96])
         -- STREAM_PROJECT  |PARTITIONED|
+          assign [$$96] <- [{"t": $$t}]
           -- ASSIGN  |PARTITIONED|
+            project ([$$t])
             -- STREAM_PROJECT  |PARTITIONED|
+              select (spatial-intersect($$36, create-point($$44, $$45)))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$t, $$36, $$44, $$45])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    split ($$49)
                     -- SPLIT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$t, $$36, $$44, $$45, $$48, $$49])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- RTREE_SEARCH (test.OfficerLocations.o_location)  |PARTITIONED|
+                            unnest-map [$$44, $$45, $$46, $$47, $$48, $$49] <- index-search("o_location", 1, "test", "OfficerLocations", true, true, 4, $$40, $$41, $$42, $$43)
+                            -- RTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                assign [$$40, $$41, $$42, $$43] <- [create-mbr($$36, 2, 0), create-mbr($$36, 2, 1), create-mbr($$36, 2, 2), create-mbr($$36, 2, 3)]
                                 -- ASSIGN  |PARTITIONED|
+                                  assign [$$36] <- [create-circle($$t.getField(0), 100.0)]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$t])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      select (gt($$34.getField(2), 100))
                                       -- STREAM_SELECT  |PARTITIONED|
+                                        project ([$$t, $$34])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (test.KVStore)  |PARTITIONED|
+                                            data-scan []<-[$$33, $$t, $$34] <- test.KVStore with filter on min:[$$70] max:[]
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                assign [$$70] <- [100]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_with_idx_1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_with_idx_1.plan
index aa7008a..a884c75 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_with_idx_1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_with_idx_1.plan
@@ -1,25 +1,50 @@
+distribute result [$$32]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$32])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$32] <- [{"t": $$t}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$t])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (spatial-intersect($$36, $$37))
             -- NESTED_LOOP  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                assign [$$36] <- [create-circle($$t.getField(0), 100.0)]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$t])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    select (gt($$34.getField(2), 100))
                     -- STREAM_SELECT  |PARTITIONED|
+                      project ([$$t, $$34])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (test.KVStore)  |PARTITIONED|
+                          data-scan []<-[$$33, $$t, $$34] <- test.KVStore with filter on min:[$$40] max:[]
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                              assign [$$40] <- [100]
                               -- ASSIGN  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                project ([$$37])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$37] <- [$$o.getField(1)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$o])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.OfficerLocations)  |PARTITIONED|
+                        data-scan []<-[$$35, $$o] <- test.OfficerLocations
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_with_idx_2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_with_idx_2.plan
index a0caf5f..3d0bf7c 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_with_idx_2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_with_idx_2.plan
@@ -1,25 +1,50 @@
+distribute result [$$31]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$31])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$31] <- [{"t": $$t}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$t])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$35, $$36))
             -- HYBRID_HASH_JOIN [$$35][$$36]  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$35]  |PARTITIONED|
+                project ([$$t, $$35])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (gt($$33.getField(2), 100))
                   -- STREAM_SELECT  |PARTITIONED|
+                    assign [$$35] <- [$$t.getField(2)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$t, $$33])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (test.KVStore)  |PARTITIONED|
+                          data-scan []<-[$$32, $$t, $$33] <- test.KVStore with filter on min:[$$38] max:[]
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                              assign [$$38] <- [100]
                               -- ASSIGN  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$36]  |PARTITIONED|
+                project ([$$36])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$36] <- [$$o.getField(2)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$o])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.OfficerLocations)  |PARTITIONED|
+                        data-scan []<-[$$34, $$o] <- test.OfficerLocations
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_with_idx_3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_with_idx_3.plan
index a0caf5f..3d0bf7c 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_with_idx_3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/filter_on_meta_with_idx_3.plan
@@ -1,25 +1,50 @@
+distribute result [$$31]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$31])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$31] <- [{"t": $$t}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$t])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$35, $$36))
             -- HYBRID_HASH_JOIN [$$35][$$36]  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$35]  |PARTITIONED|
+                project ([$$t, $$35])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (gt($$33.getField(2), 100))
                   -- STREAM_SELECT  |PARTITIONED|
+                    assign [$$35] <- [$$t.getField(2)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$t, $$33])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (test.KVStore)  |PARTITIONED|
+                          data-scan []<-[$$32, $$t, $$33] <- test.KVStore with filter on min:[$$38] max:[]
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                              assign [$$38] <- [100]
                               -- ASSIGN  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$36]  |PARTITIONED|
+                project ([$$36])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$36] <- [$$o.getField(2)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$o])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.OfficerLocations)  |PARTITIONED|
+                        data-scan []<-[$$34, $$o] <- test.OfficerLocations
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/flwr/at07.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/flwr/at07.plan
index a263d35..0c7a664 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/flwr/at07.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/flwr/at07.plan
@@ -1,40 +1,80 @@
+distribute result [$$95]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$95])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$95] <- [object-concat-strict(if-missing-or-null(to-object($$76), cast({  })), {"percentile": $#2, "i": $$i, "cnt": $$98})]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$#2(ASC) ]  |PARTITIONED|
+          order (ASC, $#2)
           -- STABLE_SORT [$#2(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              assign [$#2] <- [numeric-multiply(numeric-divide($$i, $$98), 100)]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  join (true)
                   -- NESTED_LOOP  |PARTITIONED|
+                    exchange
                     -- RANDOM_PARTITION_EXCHANGE  |PARTITIONED|
+                      project ([$$76, $$i])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (eq($$103, "NicholasStroh"))
                         -- STREAM_SELECT  |PARTITIONED|
+                          running-aggregate [$$i] <- [tid()]
                           -- RUNNING_AGGREGATE  |PARTITIONED|
+                            project ([$$76, $$103])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$76] <- [{"name": $$103, "alias": $$105}]
                               -- ASSIGN  |PARTITIONED|
-                                -- SORT_MERGE_EXCHANGE [$$99(ASC) ]  |PARTITIONED|
-                                  -- STABLE_SORT [$$99(ASC)]  |PARTITIONED|
+                                exchange
+                                -- SORT_MERGE_EXCHANGE [$$103(ASC) ]  |PARTITIONED|
+                                  order (ASC, $$103)
+                                  -- STABLE_SORT [$$103(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$103, $$105])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$105, $$103] <- [$$FacebookUsers.getField(1), $$FacebookUsers.getField(2)]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$FacebookUsers])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              replicate
                                               -- REPLICATE  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- DATASOURCE_SCAN (test.FacebookUsers)  |PARTITIONED|
+                                                  data-scan []<-[$$96, $$FacebookUsers] <- test.FacebookUsers
+                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                    exchange
                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                      aggregate [$$98] <- [agg-sql-sum($$107)]
                       -- AGGREGATE  |UNPARTITIONED|
+                        exchange
                         -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                          aggregate [$$107] <- [agg-sql-count(1)]
                           -- AGGREGATE  |PARTITIONED|
+                            project ([$$102, $$101])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$102, $$101] <- [$$96, $$FacebookUsers]
                               -- ASSIGN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  replicate
                                   -- REPLICATE  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.FacebookUsers)  |PARTITIONED|
+                                      data-scan []<-[$$96, $$FacebookUsers] <- test.FacebookUsers
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/flwr/select-let-1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/flwr/select-let-1.plan
index de331ad..7c5d5fc 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/flwr/select-let-1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/flwr/select-let-1.plan
@@ -1,4 +1,8 @@
+distribute result [$$x]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    assign [$$x] <- [2]
     -- ASSIGN  |UNPARTITIONED|
-      -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
\ No newline at end of file
+      empty-tuple-source
+      -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/gby_partitioning_property_01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/gby_partitioning_property_01.plan
index 16d2e46..bcd7153 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/gby_partitioning_property_01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/gby_partitioning_property_01.plan
@@ -1,36 +1,66 @@
+distribute result [$$58]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$58])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$58] <- [{"id": $$id, "count": $$64}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- PRE_CLUSTERED_GROUP_BY[$$70]  |PARTITIONED|
-                  {
+          group by ([$$id := $$70]) decor ([]) {
+                    aggregate [$$64] <- [agg-sql-sum($$69)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- PRE_CLUSTERED_GROUP_BY[$$70]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- SORT_GROUP_BY[$$60]  |PARTITIONED|
-                      {
+              group by ([$$70 := $$60]) decor ([]) {
+                        aggregate [$$69] <- [agg-sql-count(1)]
                         -- AGGREGATE  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SORT_GROUP_BY[$$60]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$60])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (eq($$60, $$63))
                       -- HYBRID_HASH_JOIN [$$60][$$63]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$60]  |PARTITIONED|
+                          project ([$$60])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$60] <- [meta($$user).getField("id")]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$user])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.GleambookUsers)  |PARTITIONED|
+                                  data-scan []<-[$$61, $$user] <- test.GleambookUsers
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$63]  |PARTITIONED|
+                          project ([$$63])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$63] <- [$$message.getField("author_id")]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$message])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.GleambookMessages)  |PARTITIONED|
+                                  data-scan []<-[$$62, $$message] <- test.GleambookMessages
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/group-by/gby-case-01.3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/group-by/gby-case-01.3.plan
index 3e8d666..baec7d2 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/group-by/gby-case-01.3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/group-by/gby-case-01.3.plan
@@ -1,24 +1,42 @@
+distribute result [$$83]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$83])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$83] <- [{"x": $$x, "res": switch-case(true, eq($$87, 0), 0, numeric-divide($$88, $$89))}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$x(ASC) ]  |PARTITIONED|
-          -- SORT_GROUP_BY[$$96]  |PARTITIONED|
-                  {
+          group by ([$$x := $$96]) decor ([]) {
+                    aggregate [$$87, $$88, $$89] <- [agg-global-sql-sum($$93), agg-global-sql-sum($$94), agg-global-sql-sum($$95)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- SORT_GROUP_BY[$$96]  |PARTITIONED|
+            exchange
             -- HASH_PARTITION_EXCHANGE [$$96]  |PARTITIONED|
-              -- SORT_GROUP_BY[$$84]  |PARTITIONED|
-                      {
+              group by ([$$96 := $$84]) decor ([]) {
+                        aggregate [$$93, $$94, $$95] <- [agg-local-sql-sum($$64), agg-local-sql-sum(numeric-multiply($$90, $$64)), agg-local-sql-sum($$64)]
                         -- AGGREGATE  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SORT_GROUP_BY[$$84]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$64, $$90, $$84])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$64, $$90, $$84] <- [$$t1.getField("z"), $$t1.getField("y"), $$t1.getField("x")]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$t1])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (test.t1)  |PARTITIONED|
+                          data-scan []<-[$$86, $$t1] <- test.t1
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/group-by/gby-case-01.4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/group-by/gby-case-01.4.plan
index 9b25048..b56614f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/group-by/gby-case-01.4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/group-by/gby-case-01.4.plan
@@ -1,24 +1,42 @@
+distribute result [$$107]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$107])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$107] <- [{"x": $$x, "res": switch-case(true, eq($$112, 0), 0, numeric-divide($$113, $$114))}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$x(ASC) ]  |PARTITIONED|
-          -- SORT_GROUP_BY[$$124]  |PARTITIONED|
-                  {
+          group by ([$$x := $$124]) decor ([]) {
+                    aggregate [$$112, $$113, $$114] <- [agg-global-sql-sum($$121), agg-global-sql-sum($$122), agg-global-sql-sum($$123)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- SORT_GROUP_BY[$$124]  |PARTITIONED|
+            exchange
             -- HASH_PARTITION_EXCHANGE [$$124]  |PARTITIONED|
-              -- SORT_GROUP_BY[$$109]  |PARTITIONED|
-                      {
+              group by ([$$124 := $$109]) decor ([]) {
+                        aggregate [$$121, $$122, $$123] <- [agg-local-sql-sum($$83), agg-local-sql-sum(numeric-multiply($$115, $$83)), agg-local-sql-sum($$83)]
                         -- AGGREGATE  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SORT_GROUP_BY[$$109]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$83, $$115, $$109])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$83, $$115, $$109] <- [$$t1.getField("z"), $$t1.getField("y"), $$t1.getField("x")]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$t1])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (test.t1)  |PARTITIONED|
+                          data-scan []<-[$$111, $$t1] <- test.t1
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/group-by/grouping-sets-1.1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/group-by/grouping-sets-1.1.plan
index 0d40ec3..ab45a0f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/group-by/grouping-sets-1.1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/group-by/grouping-sets-1.1.plan
@@ -1,123 +1,222 @@
+distribute result [$#3]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$#3])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- SORT_MERGE_EXCHANGE [$$385(ASC), $$386(ASC), $$387(ASC) ]  |PARTITIONED|
+        order (ASC, $$385) (ASC, $$386) (ASC, $$387)
         -- STABLE_SORT [$$385(ASC), $$386(ASC), $$387(ASC)]  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            union ($$1087, $$1189, $#3) ($$392, $$ten, $$387) ($$486, $$four, $$386) ($$586, $$two, $$385)
             -- UNION_ALL  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$1087, $$392, $$486, $$586])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    union ($$692, $$ten, $$392) ($$762, $$four, $$486) ($$838, $$two, $$586) ($$1088, $$1138, $$1087)
                     -- UNION_ALL  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        union ($$ten, $$ten, $$692) ($$four, $$four, $$762) ($$two, $$two, $$838) ($$1190, $$1222, $$1088)
                         -- UNION_ALL  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$ten, $$four, $$two, $$1190])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$1190] <- [cast(cast({"two": $$two, "four": $$four, "ten": $$ten, "grp": 3, "agg_sum": $$381}))]
                               -- ASSIGN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  group by ([$$two := $$1077]) decor ([$$four := $$231; $$ten := $$232]) {
+                                            aggregate [$$381] <- [agg-global-sql-sum($$1076)]
+                                            -- AGGREGATE  |LOCAL|
+                                              nested tuple source
+                                              -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                         }
                                   -- SORT_GROUP_BY[$$1077]  |PARTITIONED|
-                                          {
-                                            -- AGGREGATE  |LOCAL|
-                                              -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$1077]  |PARTITIONED|
+                                      group by ([$$1077 := $$238]) decor ([$$231; $$232]) {
+                                                aggregate [$$1076] <- [agg-local-sql-sum($$179)]
+                                                -- AGGREGATE  |LOCAL|
+                                                  nested tuple source
+                                                  -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                             }
                                       -- SORT_GROUP_BY[$$238]  |PARTITIONED|
-                                              {
-                                                -- AGGREGATE  |LOCAL|
-                                                  -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                              }
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$231, $$232, $$179, $$238])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$231, $$232, $$179, $$238] <- [null, null, $$tenk.getField(5), $$tenk.getField(2)]
                                             -- ASSIGN  |PARTITIONED|
+                                              project ([$$tenk])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$tenk] <- [$$tenk]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    replicate
                                                     -- REPLICATE  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        project ([$$tenk])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                                                            data-scan []<-[$$244, $$tenk] <- test.tenk
+                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                empty-tuple-source
                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$ten, $$four, $$two, $$1222])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$1222] <- [cast(cast({"two": $$two, "four": $$four, "ten": $$ten, "grp": 5, "agg_sum": $$382}))]
                               -- ASSIGN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  group by ([$$four := $$1079]) decor ([$$two := $$233; $$ten := $$234]) {
+                                            aggregate [$$382] <- [agg-global-sql-sum($$1078)]
+                                            -- AGGREGATE  |LOCAL|
+                                              nested tuple source
+                                              -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                         }
                                   -- SORT_GROUP_BY[$$1079]  |PARTITIONED|
-                                          {
-                                            -- AGGREGATE  |LOCAL|
-                                              -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$1079]  |PARTITIONED|
-                                      -- SORT_GROUP_BY[$$239]  |PARTITIONED|
-                                              {
+                                      group by ([$$1079 := $$239]) decor ([$$233; $$234]) {
+                                                aggregate [$$1078] <- [agg-local-sql-sum($$192)]
                                                 -- AGGREGATE  |LOCAL|
+                                                  nested tuple source
                                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                              }
+                                             }
+                                      -- SORT_GROUP_BY[$$239]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$233, $$234, $$192, $$239])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$233, $$234, $$192, $$239] <- [null, null, $$tenk.getField(5), $$tenk.getField(3)]
                                             -- ASSIGN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                replicate
                                                 -- REPLICATE  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$$tenk])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                                                        data-scan []<-[$$244, $$tenk] <- test.tenk
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$ten, $$four, $$two, $$1138])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$1138] <- [cast(cast({"two": $$two, "four": $$four, "ten": $$ten, "grp": 1, "agg_sum": $$383}))]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- SORT_GROUP_BY[$$1081, $$1082]  |PARTITIONED|
-                                      {
+                              group by ([$$two := $$1081; $$four := $$1082]) decor ([$$ten := $$235]) {
+                                        aggregate [$$383] <- [agg-global-sql-sum($$1080)]
                                         -- AGGREGATE  |LOCAL|
+                                          nested tuple source
                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                      }
+                                     }
+                              -- SORT_GROUP_BY[$$1081, $$1082]  |PARTITIONED|
+                                exchange
                                 -- HASH_PARTITION_EXCHANGE [$$1081, $$1082]  |PARTITIONED|
-                                  -- SORT_GROUP_BY[$$240, $$241]  |PARTITIONED|
-                                          {
+                                  group by ([$$1081 := $$240; $$1082 := $$241]) decor ([$$235]) {
+                                            aggregate [$$1080] <- [agg-local-sql-sum($$206)]
                                             -- AGGREGATE  |LOCAL|
+                                              nested tuple source
                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                         }
+                                  -- SORT_GROUP_BY[$$240, $$241]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$235, $$241, $$240, $$206])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$235, $$241, $$240, $$206] <- [null, $$tenk.getField(3), $$tenk.getField(2), $$tenk.getField(5)]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$tenk])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$tenk] <- [$$tenk]
                                             -- ASSIGN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                replicate
                                                 -- REPLICATE  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$$tenk])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                                                        data-scan []<-[$$244, $$tenk] <- test.tenk
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$1189, $$ten, $$four, $$two])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$1189] <- [cast({"two": $$two, "four": $$four, "ten": $$ten, "grp": 6, "agg_sum": $$384})]
                   -- ASSIGN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- SORT_GROUP_BY[$$1084]  |PARTITIONED|
-                              {
+                      group by ([$$ten := $$1084]) decor ([$$two := $$236; $$four := $$237]) {
+                                aggregate [$$384] <- [agg-global-sql-sum($$1083)]
                                 -- AGGREGATE  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- SORT_GROUP_BY[$$1084]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$1084]  |PARTITIONED|
-                          -- SORT_GROUP_BY[$$242]  |PARTITIONED|
-                                  {
+                          group by ([$$1084 := $$242]) decor ([$$236; $$237]) {
+                                    aggregate [$$1083] <- [agg-local-sql-sum($$219)]
                                     -- AGGREGATE  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                  }
+                                 }
+                          -- SORT_GROUP_BY[$$242]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$236, $$237, $$219, $$242])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$236, $$237, $$219, $$242] <- [null, null, $$tenk.getField(5), $$tenk.getField(4)]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$tenk])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$tenk] <- [$$tenk]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        replicate
                                         -- REPLICATE  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$tenk])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                                                data-scan []<-[$$244, $$tenk] <- test.tenk
+                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/group-by/grouping-sets-1.2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/group-by/grouping-sets-1.2.plan
index d3e260c..3f61851 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/group-by/grouping-sets-1.2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/group-by/grouping-sets-1.2.plan
@@ -1,364 +1,656 @@
+distribute result [$#3]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$#3])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- SORT_MERGE_EXCHANGE [$$1224(ASC), $$1225(ASC), $$1226(ASC), $$1227(ASC) ]  |PARTITIONED|
+        order (ASC, $$1224) (ASC, $$1225) (ASC, $$1226) (ASC, $$1227)
         -- STABLE_SORT [$$1224(ASC), $$1225(ASC), $$1226(ASC), $$1227(ASC)]  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            union ($$686, $$10235, $#3) ($$1240, $$twenty, $$1227) ($$1578, $$ten, $$1226) ($$1922, $$four, $$1225) ($$2272, $$two, $$1224)
             -- UNION_ALL  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                union ($$685, $$10234, $$686) ($$2628, $$twenty, $$1240) ($$2934, $$ten, $$1578) ($$3246, $$four, $$1922) ($$3564, $$two, $$2272)
                 -- UNION_ALL  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    union ($$684, $$10233, $$685) ($$3888, $$twenty, $$2628) ($$4166, $$ten, $$2934) ($$4450, $$four, $$3246) ($$4740, $$two, $$3564)
                     -- UNION_ALL  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        union ($$10232, $$10852, $$684) ($$5036, $$twenty, $$3888) ($$5286, $$ten, $$4166) ($$5542, $$four, $$4450) ($$5804, $$two, $$4740)
                         -- UNION_ALL  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$10232, $$5036, $$5286, $$5542, $$5804])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                union ($$6072, $$twenty, $$5036) ($$6294, $$ten, $$5286) ($$6522, $$four, $$5542) ($$6756, $$two, $$5804) ($$10494, $$10672, $$10232)
                                 -- UNION_ALL  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    union ($$6996, $$twenty, $$6072) ($$7190, $$ten, $$6294) ($$7390, $$four, $$6522) ($$7596, $$two, $$6756) ($$10985, $$11144, $$10494)
                                     -- UNION_ALL  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        union ($$7808, $$twenty, $$6996) ($$7974, $$ten, $$7190) ($$8146, $$four, $$7390) ($$8324, $$two, $$7596) ($$11389, $$11527, $$10985)
                                         -- UNION_ALL  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            union ($$8508, $$twenty, $$7808) ($$8646, $$ten, $$7974) ($$8790, $$four, $$8146) ($$8940, $$two, $$8324) ($$11665, $$11780, $$11389)
                                             -- UNION_ALL  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                union ($$9096, $$twenty, $$8508) ($$9206, $$ten, $$8646) ($$9322, $$four, $$8790) ($$9444, $$two, $$8940) ($$11895, $$11987, $$11665)
                                                 -- UNION_ALL  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    union ($$9572, $$twenty, $$9096) ($$9654, $$ten, $$9206) ($$9742, $$four, $$9322) ($$9836, $$two, $$9444) ($$12079, $$12148, $$11895)
                                                     -- UNION_ALL  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        union ($$twenty, $$twenty, $$9572) ($$ten, $$ten, $$9654) ($$four, $$four, $$9742) ($$two, $$two, $$9836) ($$12217, $$12262, $$12079)
                                                         -- UNION_ALL  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            project ([$$twenty, $$ten, $$four, $$two, $$12217])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$12217] <- [cast(cast(cast(cast({"two": $$two, "four": $$four, "ten": $$ten, "twenty": $$twenty, "grp": 0, "agg_sum": $$1212}))))]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  group by ([$$two := $$10189; $$four := $$10190; $$ten := $$10191; $$twenty := $$10192]) decor ([]) {
+                                                                            aggregate [$$1212] <- [agg-global-sql-sum($$10188)]
+                                                                            -- AGGREGATE  |LOCAL|
+                                                                              nested tuple source
+                                                                              -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                                                         }
                                                                   -- SORT_GROUP_BY[$$10189, $$10190, $$10191, $$10192]  |PARTITIONED|
-                                                                          {
-                                                                            -- AGGREGATE  |LOCAL|
-                                                                              -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                          }
+                                                                    exchange
                                                                     -- HASH_PARTITION_EXCHANGE [$$10189, $$10190, $$10191, $$10192]  |PARTITIONED|
+                                                                      group by ([$$10189 := $$717; $$10190 := $$718; $$10191 := $$719; $$10192 := $$720]) decor ([]) {
+                                                                                aggregate [$$10188] <- [agg-local-sql-sum($$519)]
+                                                                                -- AGGREGATE  |LOCAL|
+                                                                                  nested tuple source
+                                                                                  -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                                                             }
                                                                       -- SORT_GROUP_BY[$$717, $$718, $$719, $$720]  |PARTITIONED|
-                                                                              {
-                                                                                -- AGGREGATE  |LOCAL|
-                                                                                  -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                              }
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          project ([$$720, $$719, $$718, $$717, $$519])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            assign [$$720, $$719, $$718, $$717, $$519] <- [$$tenk.getField(5), $$tenk.getField(4), $$tenk.getField(3), $$tenk.getField(2), $$tenk.getField(6)]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              project ([$$tenk])
                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                assign [$$tenk] <- [$$tenk]
                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    replicate
                                                                                     -- REPLICATE  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                        project ([$$tenk])
                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                            -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                                                                                            data-scan []<-[$$743, $$tenk] <- test.tenk
+                                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                              exchange
                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                empty-tuple-source
                                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            project ([$$twenty, $$ten, $$four, $$two, $$12262])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$12262] <- [cast(cast(cast({"two": $$two, "four": $$four, "ten": $$ten, "twenty": $$twenty, "grp": 1, "agg_sum": $$1213})))]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  group by ([$$two := $$10194; $$four := $$10195; $$ten := $$10196]) decor ([$$twenty := $$693]) {
+                                                                            aggregate [$$1213] <- [agg-global-sql-sum($$10193)]
+                                                                            -- AGGREGATE  |LOCAL|
+                                                                              nested tuple source
+                                                                              -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                                                         }
                                                                   -- SORT_GROUP_BY[$$10194, $$10195, $$10196]  |PARTITIONED|
-                                                                          {
-                                                                            -- AGGREGATE  |LOCAL|
-                                                                              -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                          }
+                                                                    exchange
                                                                     -- HASH_PARTITION_EXCHANGE [$$10194, $$10195, $$10196]  |PARTITIONED|
-                                                                      -- SORT_GROUP_BY[$$721, $$722, $$723]  |PARTITIONED|
-                                                                              {
+                                                                      group by ([$$10194 := $$721; $$10195 := $$722; $$10196 := $$723]) decor ([$$693]) {
+                                                                                aggregate [$$10193] <- [agg-local-sql-sum($$534)]
                                                                                 -- AGGREGATE  |LOCAL|
+                                                                                  nested tuple source
                                                                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                              }
+                                                                             }
+                                                                      -- SORT_GROUP_BY[$$721, $$722, $$723]  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          project ([$$693, $$723, $$722, $$721, $$534])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            assign [$$693, $$723, $$722, $$721, $$534] <- [null, $$tenk.getField(4), $$tenk.getField(3), $$tenk.getField(2), $$tenk.getField(6)]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                replicate
                                                                                 -- REPLICATE  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    project ([$$tenk])
                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                        -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                                                                                        data-scan []<-[$$743, $$tenk] <- test.tenk
+                                                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                            empty-tuple-source
                                                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        project ([$$twenty, $$ten, $$four, $$two, $$12148])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$12148] <- [cast(cast(cast({"two": $$two, "four": $$four, "ten": $$ten, "twenty": $$twenty, "grp": 2, "agg_sum": $$1214})))]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              group by ([$$two := $$10198; $$four := $$10199; $$twenty := $$10200]) decor ([$$ten := $$694]) {
+                                                                        aggregate [$$1214] <- [agg-global-sql-sum($$10197)]
+                                                                        -- AGGREGATE  |LOCAL|
+                                                                          nested tuple source
+                                                                          -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                                                     }
                                                               -- SORT_GROUP_BY[$$10198, $$10199, $$10200]  |PARTITIONED|
-                                                                      {
-                                                                        -- AGGREGATE  |LOCAL|
-                                                                          -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                      }
+                                                                exchange
                                                                 -- HASH_PARTITION_EXCHANGE [$$10198, $$10199, $$10200]  |PARTITIONED|
-                                                                  -- SORT_GROUP_BY[$$724, $$725, $$726]  |PARTITIONED|
-                                                                          {
+                                                                  group by ([$$10198 := $$724; $$10199 := $$725; $$10200 := $$726]) decor ([$$694]) {
+                                                                            aggregate [$$10197] <- [agg-local-sql-sum($$549)]
                                                                             -- AGGREGATE  |LOCAL|
+                                                                              nested tuple source
                                                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                          }
+                                                                         }
+                                                                  -- SORT_GROUP_BY[$$724, $$725, $$726]  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      project ([$$694, $$726, $$725, $$724, $$549])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        assign [$$694, $$726, $$725, $$724, $$549] <- [null, $$tenk.getField(5), $$tenk.getField(3), $$tenk.getField(2), $$tenk.getField(6)]
                                                                         -- ASSIGN  |PARTITIONED|
+                                                                          project ([$$tenk])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            assign [$$tenk] <- [$$tenk]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                replicate
                                                                                 -- REPLICATE  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    project ([$$tenk])
                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                        -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                                                                                        data-scan []<-[$$743, $$tenk] <- test.tenk
+                                                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                            empty-tuple-source
                                                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$$twenty, $$ten, $$four, $$two, $$11987])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      assign [$$11987] <- [cast(cast(cast({"two": $$two, "four": $$four, "ten": $$ten, "twenty": $$twenty, "grp": 3, "agg_sum": $$1215})))]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          group by ([$$two := $$10202; $$four := $$10203]) decor ([$$ten := $$695; $$twenty := $$696]) {
+                                                                    aggregate [$$1215] <- [agg-global-sql-sum($$10201)]
+                                                                    -- AGGREGATE  |LOCAL|
+                                                                      nested tuple source
+                                                                      -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                                                 }
                                                           -- SORT_GROUP_BY[$$10202, $$10203]  |PARTITIONED|
-                                                                  {
-                                                                    -- AGGREGATE  |LOCAL|
-                                                                      -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                  }
+                                                            exchange
                                                             -- HASH_PARTITION_EXCHANGE [$$10202, $$10203]  |PARTITIONED|
-                                                              -- SORT_GROUP_BY[$$727, $$728]  |PARTITIONED|
-                                                                      {
+                                                              group by ([$$10202 := $$727; $$10203 := $$728]) decor ([$$695; $$696]) {
+                                                                        aggregate [$$10201] <- [agg-local-sql-sum($$563)]
                                                                         -- AGGREGATE  |LOCAL|
+                                                                          nested tuple source
                                                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                      }
+                                                                     }
+                                                              -- SORT_GROUP_BY[$$727, $$728]  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  project ([$$695, $$696, $$728, $$727, $$563])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    assign [$$695, $$696, $$728, $$727, $$563] <- [null, null, $$tenk.getField(3), $$tenk.getField(2), $$tenk.getField(6)]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      project ([$$tenk])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        assign [$$tenk] <- [$$tenk]
                                                                         -- ASSIGN  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            replicate
                                                                             -- REPLICATE  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                project ([$$tenk])
                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                    -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                                                                                    data-scan []<-[$$743, $$tenk] <- test.tenk
+                                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                        empty-tuple-source
                                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$twenty, $$ten, $$four, $$two, $$11780])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$11780] <- [cast(cast({"two": $$two, "four": $$four, "ten": $$ten, "twenty": $$twenty, "grp": 4, "agg_sum": $$1216}))]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      group by ([$$two := $$10205; $$ten := $$10206; $$twenty := $$10207]) decor ([$$four := $$697]) {
+                                                                aggregate [$$1216] <- [agg-global-sql-sum($$10204)]
+                                                                -- AGGREGATE  |LOCAL|
+                                                                  nested tuple source
+                                                                  -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                                             }
                                                       -- SORT_GROUP_BY[$$10205, $$10206, $$10207]  |PARTITIONED|
-                                                              {
-                                                                -- AGGREGATE  |LOCAL|
-                                                                  -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                              }
+                                                        exchange
                                                         -- HASH_PARTITION_EXCHANGE [$$10205, $$10206, $$10207]  |PARTITIONED|
-                                                          -- SORT_GROUP_BY[$$729, $$730, $$731]  |PARTITIONED|
-                                                                  {
+                                                          group by ([$$10205 := $$729; $$10206 := $$730; $$10207 := $$731]) decor ([$$697]) {
+                                                                    aggregate [$$10204] <- [agg-local-sql-sum($$578)]
                                                                     -- AGGREGATE  |LOCAL|
+                                                                      nested tuple source
                                                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                  }
+                                                                 }
+                                                          -- SORT_GROUP_BY[$$729, $$730, $$731]  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              project ([$$697, $$731, $$730, $$729, $$578])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$697, $$731, $$730, $$729, $$578] <- [null, $$tenk.getField(5), $$tenk.getField(4), $$tenk.getField(2), $$tenk.getField(6)]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  project ([$$tenk])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    assign [$$tenk] <- [$$tenk]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        replicate
                                                                         -- REPLICATE  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            project ([$$tenk])
                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                                                                                data-scan []<-[$$743, $$tenk] <- test.tenk
+                                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    empty-tuple-source
                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$twenty, $$ten, $$four, $$two, $$11527])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$11527] <- [cast(cast({"two": $$two, "four": $$four, "ten": $$ten, "twenty": $$twenty, "grp": 5, "agg_sum": $$1217}))]
                                               -- ASSIGN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  group by ([$$two := $$10209; $$ten := $$10210]) decor ([$$four := $$698; $$twenty := $$699]) {
+                                                            aggregate [$$1217] <- [agg-global-sql-sum($$10208)]
+                                                            -- AGGREGATE  |LOCAL|
+                                                              nested tuple source
+                                                              -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                                         }
                                                   -- SORT_GROUP_BY[$$10209, $$10210]  |PARTITIONED|
-                                                          {
-                                                            -- AGGREGATE  |LOCAL|
-                                                              -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                          }
+                                                    exchange
                                                     -- HASH_PARTITION_EXCHANGE [$$10209, $$10210]  |PARTITIONED|
-                                                      -- SORT_GROUP_BY[$$732, $$733]  |PARTITIONED|
-                                                              {
+                                                      group by ([$$10209 := $$732; $$10210 := $$733]) decor ([$$698; $$699]) {
+                                                                aggregate [$$10208] <- [agg-local-sql-sum($$592)]
                                                                 -- AGGREGATE  |LOCAL|
+                                                                  nested tuple source
                                                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                              }
+                                                             }
+                                                      -- SORT_GROUP_BY[$$732, $$733]  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          project ([$$698, $$699, $$733, $$732, $$592])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            assign [$$698, $$699, $$733, $$732, $$592] <- [null, null, $$tenk.getField(4), $$tenk.getField(2), $$tenk.getField(6)]
                                                             -- ASSIGN  |PARTITIONED|
+                                                              project ([$$tenk])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$tenk] <- [$$tenk]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    replicate
                                                                     -- REPLICATE  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        project ([$$tenk])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                            -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                                                                            data-scan []<-[$$743, $$tenk] <- test.tenk
+                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                empty-tuple-source
                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$twenty, $$ten, $$four, $$two, $$11144])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$11144] <- [cast(cast({"two": $$two, "four": $$four, "ten": $$ten, "twenty": $$twenty, "grp": 6, "agg_sum": $$1218}))]
                                           -- ASSIGN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              group by ([$$two := $$10212; $$twenty := $$10213]) decor ([$$four := $$700; $$ten := $$701]) {
+                                                        aggregate [$$1218] <- [agg-global-sql-sum($$10211)]
+                                                        -- AGGREGATE  |LOCAL|
+                                                          nested tuple source
+                                                          -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                                     }
                                               -- SORT_GROUP_BY[$$10212, $$10213]  |PARTITIONED|
-                                                      {
-                                                        -- AGGREGATE  |LOCAL|
-                                                          -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                      }
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$10212, $$10213]  |PARTITIONED|
-                                                  -- SORT_GROUP_BY[$$734, $$735]  |PARTITIONED|
-                                                          {
+                                                  group by ([$$10212 := $$734; $$10213 := $$735]) decor ([$$700; $$701]) {
+                                                            aggregate [$$10211] <- [agg-local-sql-sum($$606)]
                                                             -- AGGREGATE  |LOCAL|
+                                                              nested tuple source
                                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                          }
+                                                         }
+                                                  -- SORT_GROUP_BY[$$734, $$735]  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      project ([$$700, $$701, $$735, $$734, $$606])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$700, $$701, $$735, $$734, $$606] <- [null, null, $$tenk.getField(5), $$tenk.getField(2), $$tenk.getField(6)]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          project ([$$tenk])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            assign [$$tenk] <- [$$tenk]
                                                             -- ASSIGN  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                replicate
                                                                 -- REPLICATE  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    project ([$$tenk])
                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                        -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                                                                        data-scan []<-[$$743, $$tenk] <- test.tenk
+                                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            empty-tuple-source
                                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$twenty, $$ten, $$four, $$two, $$10672])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$10672] <- [cast(cast({"two": $$two, "four": $$four, "ten": $$ten, "twenty": $$twenty, "grp": 7, "agg_sum": $$1219}))]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- SORT_GROUP_BY[$$10215]  |PARTITIONED|
-                                                  {
+                                          group by ([$$two := $$10215]) decor ([$$four := $$702; $$ten := $$703; $$twenty := $$704]) {
+                                                    aggregate [$$1219] <- [agg-global-sql-sum($$10214)]
                                                     -- AGGREGATE  |LOCAL|
+                                                      nested tuple source
                                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                  }
+                                                 }
+                                          -- SORT_GROUP_BY[$$10215]  |PARTITIONED|
+                                            exchange
                                             -- HASH_PARTITION_EXCHANGE [$$10215]  |PARTITIONED|
-                                              -- SORT_GROUP_BY[$$736]  |PARTITIONED|
-                                                      {
+                                              group by ([$$10215 := $$736]) decor ([$$702; $$703; $$704]) {
+                                                        aggregate [$$10214] <- [agg-local-sql-sum($$619)]
                                                         -- AGGREGATE  |LOCAL|
+                                                          nested tuple source
                                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                      }
+                                                     }
+                                              -- SORT_GROUP_BY[$$736]  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  project ([$$702, $$703, $$704, $$619, $$736])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    assign [$$702, $$703, $$704, $$619, $$736] <- [null, null, null, $$tenk.getField(6), $$tenk.getField(2)]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      project ([$$tenk])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$tenk] <- [$$tenk]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            replicate
                                                             -- REPLICATE  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                project ([$$tenk])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                                                                    data-scan []<-[$$743, $$tenk] <- test.tenk
+                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        empty-tuple-source
                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$10852, $$twenty, $$ten, $$four, $$two])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$10852] <- [cast({"two": $$two, "four": $$four, "ten": $$ten, "twenty": $$twenty, "grp": 12, "agg_sum": $$1220})]
                               -- ASSIGN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  group by ([$$ten := $$10217; $$twenty := $$10218]) decor ([$$two := $$705; $$four := $$706]) {
+                                            aggregate [$$1220] <- [agg-global-sql-sum($$10216)]
+                                            -- AGGREGATE  |LOCAL|
+                                              nested tuple source
+                                              -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                         }
                                   -- SORT_GROUP_BY[$$10217, $$10218]  |PARTITIONED|
-                                          {
-                                            -- AGGREGATE  |LOCAL|
-                                              -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$10217, $$10218]  |PARTITIONED|
-                                      -- SORT_GROUP_BY[$$737, $$738]  |PARTITIONED|
-                                              {
+                                      group by ([$$10217 := $$737; $$10218 := $$738]) decor ([$$705; $$706]) {
+                                                aggregate [$$10216] <- [agg-local-sql-sum($$633)]
                                                 -- AGGREGATE  |LOCAL|
+                                                  nested tuple source
                                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                              }
+                                             }
+                                      -- SORT_GROUP_BY[$$737, $$738]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$705, $$706, $$738, $$737, $$633])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$705, $$706, $$738, $$737, $$633] <- [null, null, $$tenk.getField(5), $$tenk.getField(4), $$tenk.getField(6)]
                                             -- ASSIGN  |PARTITIONED|
+                                              project ([$$tenk])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$tenk] <- [$$tenk]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    replicate
                                                     -- REPLICATE  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        project ([$$tenk])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                                                            data-scan []<-[$$743, $$tenk] <- test.tenk
+                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                empty-tuple-source
                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$10233, $$twenty, $$ten, $$four, $$two])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$10233] <- [cast({"two": $$two, "four": $$four, "ten": $$ten, "twenty": $$twenty, "grp": 13, "agg_sum": $$1221})]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              group by ([$$ten := $$10220]) decor ([$$two := $$707; $$four := $$708; $$twenty := $$709]) {
+                                        aggregate [$$1221] <- [agg-global-sql-sum($$10219)]
+                                        -- AGGREGATE  |LOCAL|
+                                          nested tuple source
+                                          -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                     }
                               -- SORT_GROUP_BY[$$10220]  |PARTITIONED|
-                                      {
-                                        -- AGGREGATE  |LOCAL|
-                                          -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                      }
+                                exchange
                                 -- HASH_PARTITION_EXCHANGE [$$10220]  |PARTITIONED|
-                                  -- SORT_GROUP_BY[$$739]  |PARTITIONED|
-                                          {
+                                  group by ([$$10220 := $$739]) decor ([$$707; $$708; $$709]) {
+                                            aggregate [$$10219] <- [agg-local-sql-sum($$646)]
                                             -- AGGREGATE  |LOCAL|
+                                              nested tuple source
                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                         }
+                                  -- SORT_GROUP_BY[$$739]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$707, $$708, $$709, $$646, $$739])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$707, $$708, $$709, $$646, $$739] <- [null, null, null, $$tenk.getField(6), $$tenk.getField(4)]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$tenk])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$tenk] <- [$$tenk]
                                             -- ASSIGN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                replicate
                                                 -- REPLICATE  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$$tenk])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                                                        data-scan []<-[$$743, $$tenk] <- test.tenk
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$10234, $$twenty, $$ten, $$four, $$two])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$10234] <- [cast({"two": $$two, "four": $$four, "ten": $$ten, "twenty": $$twenty, "grp": 14, "agg_sum": $$1222})]
                       -- ASSIGN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- SORT_GROUP_BY[$$10222]  |PARTITIONED|
-                                  {
+                          group by ([$$twenty := $$10222]) decor ([$$two := $$710; $$four := $$711; $$ten := $$712]) {
+                                    aggregate [$$1222] <- [agg-global-sql-sum($$10221)]
                                     -- AGGREGATE  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                  }
+                                 }
+                          -- SORT_GROUP_BY[$$10222]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$10222]  |PARTITIONED|
-                              -- SORT_GROUP_BY[$$740]  |PARTITIONED|
-                                      {
+                              group by ([$$10222 := $$740]) decor ([$$710; $$711; $$712]) {
+                                        aggregate [$$10221] <- [agg-local-sql-sum($$659)]
                                         -- AGGREGATE  |LOCAL|
+                                          nested tuple source
                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                      }
+                                     }
+                              -- SORT_GROUP_BY[$$740]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$710, $$711, $$712, $$659, $$740])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$710, $$711, $$712, $$659, $$740] <- [null, null, null, $$tenk.getField(6), $$tenk.getField(5)]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$tenk])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$tenk] <- [$$tenk]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$tenk])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                                                    data-scan []<-[$$743, $$tenk] <- test.tenk
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$10235, $$twenty, $$ten, $$four, $$two])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$10235] <- [cast({"two": $$two, "four": $$four, "ten": $$ten, "twenty": $$twenty, "grp": 15, "agg_sum": $$1223})]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$1223, $$two, $$four, $$ten, $$twenty])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- SORT_GROUP_BY[$$10224]  |PARTITIONED|
-                                {
+                        group by ([$$666 := $$10224]) decor ([$$two := $$713; $$four := $$714; $$ten := $$715; $$twenty := $$716]) {
+                                  aggregate [$$1223] <- [agg-global-sql-sum($$10223)]
                                   -- AGGREGATE  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                }
+                               }
+                        -- SORT_GROUP_BY[$$10224]  |PARTITIONED|
+                          exchange
                           -- HASH_PARTITION_EXCHANGE [$$10224]  |PARTITIONED|
-                            -- SORT_GROUP_BY[$$741]  |PARTITIONED|
-                                    {
+                            group by ([$$10224 := $$741]) decor ([$$713; $$714; $$715; $$716]) {
+                                      aggregate [$$10223] <- [agg-local-sql-sum($$672)]
                                       -- AGGREGATE  |LOCAL|
+                                        nested tuple source
                                         -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                    }
+                                   }
+                            -- SORT_GROUP_BY[$$741]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$741, $$713, $$714, $$715, $$716, $$672])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  assign [$$741, $$713, $$714, $$715, $$716, $$672] <- [true, null, null, null, null, $$tenk.getField(6)]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$tenk])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$tenk] <- [$$tenk]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          replicate
                                           -- REPLICATE  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$tenk])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                                                  data-scan []<-[$$743, $$tenk] <- test.tenk
+                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/group-by/listify-3.1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/group-by/listify-3.1.plan
index 85fa62d..d3b9747 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/group-by/listify-3.1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/group-by/listify-3.1.plan
@@ -1,43 +1,86 @@
+distribute result [$$136]
 -- DISTRIBUTE_RESULT  |LOCAL|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+    project ([$$136])
     -- STREAM_PROJECT  |LOCAL|
+      assign [$$136] <- [{"std": round-half-to-even(sqrt($$137), 2)}]
       -- ASSIGN  |LOCAL|
+        aggregate [$$137] <- [agg-global-sql-avg($$154)]
         -- AGGREGATE  |LOCAL|
+          aggregate [$$154] <- [agg-local-sql-avg($$134)]
           -- AGGREGATE  |LOCAL|
+            project ([$$134])
             -- STREAM_PROJECT  |LOCAL|
+              assign [$$134] <- [power(numeric-subtract(numeric-add(numeric-subtract($$144, $$t), $$145), 1), 2)]
               -- ASSIGN  |LOCAL|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                  join (true)
                   -- NESTED_LOOP  |LOCAL|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                      join (true)
                       -- NESTED_LOOP  |LOCAL|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                          unnest $$t <- range(1, 10)
                           -- UNNEST  |UNPARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                          project ([$$144])
                           -- STREAM_PROJECT  |LOCAL|
+                            assign [$$144] <- [get-item($$105, 0).getField(0)]
                             -- ASSIGN  |LOCAL|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                                replicate
                                 -- REPLICATE  |LOCAL|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                                    aggregate [$$105] <- [listify($$104)]
                                     -- AGGREGATE  |LOCAL|
+                                      project ([$$104])
                                       -- STREAM_PROJECT  |LOCAL|
+                                        assign [$$104] <- [{"mean": $$148, "min": $$149}]
                                         -- ASSIGN  |LOCAL|
+                                          aggregate [$$148, $$149] <- [agg-global-sql-avg($$152), agg-global-sql-min($$153)]
                                           -- AGGREGATE  |LOCAL|
+                                            aggregate [$$152, $$153] <- [agg-local-sql-avg($$143), agg-local-sql-min($$143)]
                                             -- AGGREGATE  |LOCAL|
+                                              unnest $$143 <- range(1, 10)
                                               -- UNNEST  |UNPARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                      project ([$$145])
                       -- STREAM_PROJECT  |LOCAL|
+                        assign [$$145] <- [get-item($$121, 0).getField(1)]
                         -- ASSIGN  |LOCAL|
+                          project ([$$121])
                           -- STREAM_PROJECT  |LOCAL|
+                            assign [$$121] <- [$$105]
                             -- ASSIGN  |LOCAL|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                                replicate
                                 -- REPLICATE  |LOCAL|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                                    aggregate [$$105] <- [listify($$104)]
                                     -- AGGREGATE  |LOCAL|
+                                      project ([$$104])
                                       -- STREAM_PROJECT  |LOCAL|
+                                        assign [$$104] <- [{"mean": $$148, "min": $$149}]
                                         -- ASSIGN  |LOCAL|
+                                          aggregate [$$148, $$149] <- [agg-global-sql-avg($$152), agg-global-sql-min($$153)]
                                           -- AGGREGATE  |LOCAL|
+                                            aggregate [$$152, $$153] <- [agg-local-sql-avg($$143), agg-local-sql-min($$143)]
                                             -- AGGREGATE  |LOCAL|
+                                              unnest $$143 <- range(1, 10)
                                               -- UNNEST  |UNPARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/group-by/sugar-06-distinct.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/group-by/sugar-06-distinct.plan
index ea1e178..bd56870 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/group-by/sugar-06-distinct.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/group-by/sugar-06-distinct.plan
@@ -1,27 +1,51 @@
+distribute result [$$52]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    limit 3
     -- STREAM_LIMIT  |UNPARTITIONED|
+      project ([$$52])
       -- STREAM_PROJECT  |PARTITIONED|
+        assign [$$52] <- [{"deptno": $$deptno, "salary_agg": $$55}]
         -- ASSIGN  |PARTITIONED|
+          exchange
           -- SORT_MERGE_EXCHANGE [$$55(DESC) ]  |PARTITIONED|
+            limit 3
             -- STREAM_LIMIT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (topK: 3) (DESC, $$55)
                 -- STABLE_SORT [topK: 3] [$$55(DESC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- PRE_CLUSTERED_GROUP_BY[$$53]  |PARTITIONED|
-                            {
+                    group by ([$$deptno := $$53]) decor ([]) {
+                              aggregate [$$55] <- [agg-sql-max($$49)]
                               -- AGGREGATE  |LOCAL|
+                                distinct ([$$49])
                                 -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                                  order (ASC, $$49)
                                   -- MICRO_STABLE_SORT [$$49(ASC)]  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                            }
+                           }
+                    -- PRE_CLUSTERED_GROUP_BY[$$53]  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        order (ASC, $$53)
                         -- STABLE_SORT [$$53(ASC)]  |PARTITIONED|
+                          exchange
                           -- HASH_PARTITION_EXCHANGE [$$53]  |PARTITIONED|
+                            project ([$$49, $$53])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$49, $$53] <- [$$e.getField("salary"), $$e.getField("deptno")]
                               -- ASSIGN  |PARTITIONED|
+                                project ([$$e])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (gby.Employee)  |PARTITIONED|
+                                    data-scan []<-[$$54, $$e] <- gby.Employee
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hash-join-with-redundant-variable/hash-join-with-redundant-variable.1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hash-join-with-redundant-variable/hash-join-with-redundant-variable.1.plan
index 8b2d960..2e847c1 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hash-join-with-redundant-variable/hash-join-with-redundant-variable.1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hash-join-with-redundant-variable/hash-join-with-redundant-variable.1.plan
@@ -1,74 +1,148 @@
+distribute result [$$124]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    aggregate [$$124] <- [agg-sql-sum($$134)]
     -- AGGREGATE  |UNPARTITIONED|
+      exchange
       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+        aggregate [$$134] <- [agg-sql-count(1)]
         -- AGGREGATE  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (and(eq($$127, $$128), eq($$116, $$117)))
             -- HYBRID_HASH_JOIN [$$127, $$117][$$128, $$116]  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$127, $$117]  |PARTITIONED|
+                project ([$$117, $$127])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    join (eq($$131, $$132))
                     -- HYBRID_HASH_JOIN [$$132][$$131]  |PARTITIONED|
+                      exchange
                       -- HASH_PARTITION_EXCHANGE [$$132]  |PARTITIONED|
+                        project ([$$117, $$132])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            join (eq($$115, $$117))
                             -- HYBRID_HASH_JOIN [$$117][$$115]  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$117]  |PARTITIONED|
+                                project ([$$117])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    join (eq($$129, $$130))
                                     -- HYBRID_HASH_JOIN [$$130][$$129]  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$130]  |PARTITIONED|
+                                        project ([$$130])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          select (eq($$r.getField("r_name"), "EUROPE"))
                                           -- STREAM_SELECT  |PARTITIONED|
+                                            assign [$$130] <- [$$r.getField("r_regionkey")]
                                             -- ASSIGN  |PARTITIONED|
+                                              project ([$$r])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- DATASOURCE_SCAN (test.region)  |PARTITIONED|
+                                                  data-scan []<-[$$118, $$r] <- test.region
+                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$129]  |PARTITIONED|
+                                        project ([$$117, $$129])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$117, $$129] <- [$$n.getField("n_nationkey"), $$n.getField("n_regionkey")]
                                           -- ASSIGN  |PARTITIONED|
+                                            project ([$$n])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- DATASOURCE_SCAN (test.nation)  |PARTITIONED|
+                                                data-scan []<-[$$119, $$n] <- test.nation
+                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$115]  |PARTITIONED|
+                                project ([$$115, $$132])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    join (eq($$125, $$126))
                                     -- HYBRID_HASH_JOIN [$$125][$$126]  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$125]  |PARTITIONED|
+                                        project ([$$115, $$125])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$115, $$125] <- [$$c.getField("c_nationkey"), $$c.getField("c_custkey")]
                                           -- ASSIGN  |PARTITIONED|
+                                            project ([$$c])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- DATASOURCE_SCAN (test.customer)  |PARTITIONED|
+                                                data-scan []<-[$$120, $$c] <- test.customer
+                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$126]  |PARTITIONED|
+                                        project ([$$132, $$126])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          select (and(ge($$114, "1993-01-01"), lt($$114, "1993-04-01")))
                                           -- STREAM_SELECT  |PARTITIONED|
+                                            project ([$$132, $$126, $$114])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$132, $$126, $$114] <- [$$o.getField("o_orderkey"), $$o.getField("o_custkey"), $$o.getField("o_orderdate")]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$o])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                                    data-scan []<-[$$121, $$o] <- test.orders
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      exchange
                       -- HASH_PARTITION_EXCHANGE [$$131]  |PARTITIONED|
+                        project ([$$127, $$131])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$127, $$131] <- [$$l.getField("l_suppkey"), $$l.getField("l_orderkey")]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$l])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.lineitem)  |PARTITIONED|
+                                data-scan []<-[$$122, $$l] <- test.lineitem
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$128, $$116]  |PARTITIONED|
+                project ([$$128, $$116])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$128, $$116] <- [$$s.getField("s_suppkey"), $$s.getField("s_nationkey")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$s])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.supplier)  |PARTITIONED|
+                        data-scan []<-[$$123, $$s] <- test.supplier
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hash-join-with-redundant-variable/hash-join-with-redundant-variable.2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hash-join-with-redundant-variable/hash-join-with-redundant-variable.2.plan
index d56477e..df165c4 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hash-join-with-redundant-variable/hash-join-with-redundant-variable.2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hash-join-with-redundant-variable/hash-join-with-redundant-variable.2.plan
@@ -1,35 +1,70 @@
+distribute result [$$69]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    aggregate [$$69] <- [agg-sql-sum($$70)]
     -- AGGREGATE  |UNPARTITIONED|
+      exchange
       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+        aggregate [$$70] <- [agg-sql-count(1)]
         -- AGGREGATE  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$65, $$63))
             -- HYBRID_HASH_JOIN [$$65][$$63]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$65])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    join (eq($$64, $$65))
                     -- HYBRID_HASH_JOIN [$$65][$$64]  |PARTITIONED|
+                      exchange
                       -- HASH_PARTITION_EXCHANGE [$$65]  |PARTITIONED|
+                        project ([$$65])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$65] <- [$$r.getField("x")]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$r])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.region)  |PARTITIONED|
+                                data-scan []<-[$$66, $$r] <- test.region
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      exchange
                       -- HASH_PARTITION_EXCHANGE [$$64]  |PARTITIONED|
+                        project ([$$64])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$64] <- [$$o.getField("x")]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$o])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                data-scan []<-[$$67, $$o] <- test.orders
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$63]  |PARTITIONED|
+                project ([$$63])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$63] <- [$$n.getField("x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$n])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.nation)  |PARTITIONED|
+                        data-scan []<-[$$68, $$n] <- test.nation
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hash-join-with-redundant-variable/hash-join-with-redundant-variable.3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hash-join-with-redundant-variable/hash-join-with-redundant-variable.3.plan
index 5264d56..1452c57 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hash-join-with-redundant-variable/hash-join-with-redundant-variable.3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hash-join-with-redundant-variable/hash-join-with-redundant-variable.3.plan
@@ -1,35 +1,70 @@
+distribute result [$$72]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    aggregate [$$72] <- [agg-sql-sum($$73)]
     -- AGGREGATE  |UNPARTITIONED|
+      exchange
       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+        aggregate [$$73] <- [agg-sql-count(1)]
         -- AGGREGATE  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$66, $$68))
             -- HYBRID_HASH_JOIN [$$68][$$66]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$68])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    join (eq($$67, $$68))
                     -- HYBRID_HASH_JOIN [$$67][$$68]  |PARTITIONED|
+                      exchange
                       -- HASH_PARTITION_EXCHANGE [$$67]  |PARTITIONED|
+                        project ([$$67])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$67] <- [$$r.getField("x")]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$r])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.region)  |PARTITIONED|
+                                data-scan []<-[$$69, $$r] <- test.region
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      exchange
                       -- HASH_PARTITION_EXCHANGE [$$68]  |PARTITIONED|
+                        project ([$$68])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$68] <- [$$n.getField("x")]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$n])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.nation)  |PARTITIONED|
+                                data-scan []<-[$$70, $$n] <- test.nation
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$66]  |PARTITIONED|
+                project ([$$66])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$66] <- [$$o.getField("x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$o])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                        data-scan []<-[$$71, $$o] <- test.orders
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hash-join-with-redundant-variable/hash-join-with-redundant-variable.4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hash-join-with-redundant-variable/hash-join-with-redundant-variable.4.plan
index c898cde..6390bbd 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hash-join-with-redundant-variable/hash-join-with-redundant-variable.4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hash-join-with-redundant-variable/hash-join-with-redundant-variable.4.plan
@@ -1,24 +1,48 @@
+distribute result [$$54]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    aggregate [$$54] <- [agg-sql-sum($$55)]
     -- AGGREGATE  |UNPARTITIONED|
+      exchange
       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+        aggregate [$$55] <- [agg-sql-count(1)]
         -- AGGREGATE  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (and(eq($$49, $$52), eq($$56, $$53)))
             -- HYBRID_HASH_JOIN [$$49, $$56][$$52, $$53]  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$49, $$56]  |PARTITIONED|
+                assign [$$56] <- [$$49]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$49])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$49] <- [$$r.getField("x")]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$r])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (test.region)  |PARTITIONED|
+                          data-scan []<-[$$50, $$r] <- test.region
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$52, $$53]  |PARTITIONED|
+                project ([$$53, $$52])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$53, $$52] <- [$$o.getField("x"), $$o.getField("y")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$o])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                        data-scan []<-[$$51, $$o] <- test.orders
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_join_hint/broadcast_join_hint_1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_join_hint/broadcast_join_hint_1.plan
index be7b38a..90c8bb2 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_join_hint/broadcast_join_hint_1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_join_hint/broadcast_join_hint_1.plan
@@ -1,23 +1,46 @@
+distribute result [$$36]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$36])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$36] <- [{"c0": $$45, "c1": $$46}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$45, $$46])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (and(eq($$39, $$40), eq($$41, $$42), eq($$43, $$44)))
             -- HYBRID_HASH_JOIN [$$39, $$41, $$43][$$40, $$42, $$44]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$45, $$39, $$41, $$43])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$45, $$43, $$41, $$39] <- [$$t1.getField(4), $$t1.getField(1), $$t1.getField(3), $$t1.getField(2)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$t1])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.t1)  |PARTITIONED|
+                        data-scan []<-[$$37, $$t1] <- test.t1
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                project ([$$46, $$40, $$42, $$44])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$46, $$44, $$42, $$40] <- [$$t2.getField(4), $$t2.getField(1), $$t2.getField(3), $$t2.getField(2)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$t2])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.t2)  |PARTITIONED|
+                        data-scan []<-[$$38, $$t2] <- test.t2
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_join_hint/broadcast_join_hint_2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_join_hint/broadcast_join_hint_2.plan
index be7b38a..90c8bb2 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_join_hint/broadcast_join_hint_2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_join_hint/broadcast_join_hint_2.plan
@@ -1,23 +1,46 @@
+distribute result [$$36]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$36])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$36] <- [{"c0": $$45, "c1": $$46}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$45, $$46])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (and(eq($$39, $$40), eq($$41, $$42), eq($$43, $$44)))
             -- HYBRID_HASH_JOIN [$$39, $$41, $$43][$$40, $$42, $$44]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$45, $$39, $$41, $$43])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$45, $$43, $$41, $$39] <- [$$t1.getField(4), $$t1.getField(1), $$t1.getField(3), $$t1.getField(2)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$t1])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.t1)  |PARTITIONED|
+                        data-scan []<-[$$37, $$t1] <- test.t1
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                project ([$$46, $$40, $$42, $$44])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$46, $$44, $$42, $$40] <- [$$t2.getField(4), $$t2.getField(1), $$t2.getField(3), $$t2.getField(2)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$t2])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.t2)  |PARTITIONED|
+                        data-scan []<-[$$38, $$t2] <- test.t2
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_join_hint/broadcast_join_hint_3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_join_hint/broadcast_join_hint_3.plan
index 552f7ef..1c8ab2b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_join_hint/broadcast_join_hint_3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_join_hint/broadcast_join_hint_3.plan
@@ -1,23 +1,46 @@
+distribute result [$$36]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$36])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$36] <- [{"c0": $$45, "c1": $$46}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$45, $$46])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (and(eq($$39, $$40), eq($$41, $$42), eq($$43, $$44)))
             -- HYBRID_HASH_JOIN [$$39, $$42, $$43][$$40, $$41, $$44]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$45, $$39, $$42, $$43])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$45, $$43, $$42, $$39] <- [$$t1.getField(4), $$t1.getField(1), $$t1.getField(3), $$t1.getField(2)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$t1])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.t1)  |PARTITIONED|
+                        data-scan []<-[$$37, $$t1] <- test.t1
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                project ([$$46, $$40, $$41, $$44])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$46, $$44, $$41, $$40] <- [$$t2.getField(4), $$t2.getField(1), $$t2.getField(3), $$t2.getField(2)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$t2])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.t2)  |PARTITIONED|
+                        data-scan []<-[$$38, $$t2] <- test.t2
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_join_hint/broadcast_join_hint_4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_join_hint/broadcast_join_hint_4.plan
index 00c7dfd..3c9589b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_join_hint/broadcast_join_hint_4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_join_hint/broadcast_join_hint_4.plan
@@ -1,34 +1,68 @@
+distribute result [$$73]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$73])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$73] <- [{"$1": $$77}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$77] <- [agg-sql-sum($$82)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$82] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- HYBRID_HASH_JOIN [$$86][$$85]  |PARTITIONED|
+                join (eq($$80, $$81))
+                -- HYBRID_HASH_JOIN [$$81][$$80]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$81])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$81] <- [$$o.getField("o_custkey")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$o])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (tpch.orders)  |PARTITIONED|
+                            data-scan []<-[$$74, $$o] <- tpch.orders
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    project ([$$80])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$80] <- [{"c": $$c, "n": $$n}.getField("c_custkey")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$c, $$n])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- HYBRID_HASH_JOIN [$$83][$$81]  |PARTITIONED|
-                              -- HASH_PARTITION_EXCHANGE [$$83]  |PARTITIONED|
+                            join (eq($$78, $$76))
+                            -- HYBRID_HASH_JOIN [$$78][$$76]  |PARTITIONED|
+                              exchange
+                              -- HASH_PARTITION_EXCHANGE [$$78]  |PARTITIONED|
+                                assign [$$78] <- [$$c.getField("c_nationkey")]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$c])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (tpch.customer)  |PARTITIONED|
+                                      data-scan []<-[$$75, $$c] <- tpch.customer
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (tpch.nation)  |PARTITIONED|
+                                data-scan []<-[$$76, $$n] <- tpch.nation
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_join_hint/broadcast_join_hint_5.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_join_hint/broadcast_join_hint_5.plan
index b5ed081..3dd2d78 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_join_hint/broadcast_join_hint_5.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_join_hint/broadcast_join_hint_5.plan
@@ -1,34 +1,68 @@
+distribute result [$$73]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$73])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$73] <- [{"$1": $$77}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$77] <- [agg-sql-sum($$82)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$82] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- HYBRID_HASH_JOIN [$$85][$$86]  |PARTITIONED|
+                join (eq($$80, $$81))
+                -- HYBRID_HASH_JOIN [$$80][$$81]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$80])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$80] <- [{"c": $$c, "n": $$n}.getField("c_custkey")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$c, $$n])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- HYBRID_HASH_JOIN [$$83][$$81]  |PARTITIONED|
-                              -- HASH_PARTITION_EXCHANGE [$$83]  |PARTITIONED|
+                            join (eq($$78, $$76))
+                            -- HYBRID_HASH_JOIN [$$78][$$76]  |PARTITIONED|
+                              exchange
+                              -- HASH_PARTITION_EXCHANGE [$$78]  |PARTITIONED|
+                                assign [$$78] <- [$$c.getField("c_nationkey")]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$c])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (tpch.customer)  |PARTITIONED|
+                                      data-scan []<-[$$75, $$c] <- tpch.customer
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (tpch.nation)  |PARTITIONED|
+                                data-scan []<-[$$76, $$n] <- tpch.nation
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    project ([$$81])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$81] <- [$$o.getField("o_custkey")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$o])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (tpch.orders)  |PARTITIONED|
+                            data-scan []<-[$$74, $$o] <- tpch.orders
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_join_hint/broadcast_join_hint_6.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_join_hint/broadcast_join_hint_6.plan
index 00c7dfd..3c9589b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_join_hint/broadcast_join_hint_6.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_join_hint/broadcast_join_hint_6.plan
@@ -1,34 +1,68 @@
+distribute result [$$73]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$73])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$73] <- [{"$1": $$77}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$77] <- [agg-sql-sum($$82)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$82] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- HYBRID_HASH_JOIN [$$86][$$85]  |PARTITIONED|
+                join (eq($$80, $$81))
+                -- HYBRID_HASH_JOIN [$$81][$$80]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$81])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$81] <- [$$o.getField("o_custkey")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$o])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (tpch.orders)  |PARTITIONED|
+                            data-scan []<-[$$74, $$o] <- tpch.orders
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    project ([$$80])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$80] <- [{"c": $$c, "n": $$n}.getField("c_custkey")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$c, $$n])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- HYBRID_HASH_JOIN [$$83][$$81]  |PARTITIONED|
-                              -- HASH_PARTITION_EXCHANGE [$$83]  |PARTITIONED|
+                            join (eq($$78, $$76))
+                            -- HYBRID_HASH_JOIN [$$78][$$76]  |PARTITIONED|
+                              exchange
+                              -- HASH_PARTITION_EXCHANGE [$$78]  |PARTITIONED|
+                                assign [$$78] <- [$$c.getField("c_nationkey")]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$c])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (tpch.customer)  |PARTITIONED|
+                                      data-scan []<-[$$75, $$c] <- tpch.customer
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (tpch.nation)  |PARTITIONED|
+                                data-scan []<-[$$76, $$n] <- tpch.nation
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_join_hint/broadcast_join_hint_7.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_join_hint/broadcast_join_hint_7.plan
index 00c7dfd..3c9589b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_join_hint/broadcast_join_hint_7.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/broadcast_join_hint/broadcast_join_hint_7.plan
@@ -1,34 +1,68 @@
+distribute result [$$73]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$73])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$73] <- [{"$1": $$77}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$77] <- [agg-sql-sum($$82)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$82] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- HYBRID_HASH_JOIN [$$86][$$85]  |PARTITIONED|
+                join (eq($$80, $$81))
+                -- HYBRID_HASH_JOIN [$$81][$$80]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$81])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$81] <- [$$o.getField("o_custkey")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$o])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (tpch.orders)  |PARTITIONED|
+                            data-scan []<-[$$74, $$o] <- tpch.orders
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    project ([$$80])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$80] <- [{"c": $$c, "n": $$n}.getField("c_custkey")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$c, $$n])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- HYBRID_HASH_JOIN [$$83][$$81]  |PARTITIONED|
-                              -- HASH_PARTITION_EXCHANGE [$$83]  |PARTITIONED|
+                            join (eq($$78, $$76))
+                            -- HYBRID_HASH_JOIN [$$78][$$76]  |PARTITIONED|
+                              exchange
+                              -- HASH_PARTITION_EXCHANGE [$$78]  |PARTITIONED|
+                                assign [$$78] <- [$$c.getField("c_nationkey")]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$c])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (tpch.customer)  |PARTITIONED|
+                                      data-scan []<-[$$75, $$c] <- tpch.customer
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (tpch.nation)  |PARTITIONED|
+                                data-scan []<-[$$76, $$n] <- tpch.nation
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/hashjoin_hint/hashjoin_hint_1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/hashjoin_hint/hashjoin_hint_1.plan
index c5b8dc2..691c514 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/hashjoin_hint/hashjoin_hint_1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/hashjoin_hint/hashjoin_hint_1.plan
@@ -1,34 +1,68 @@
+distribute result [$$73]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$73])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$73] <- [{"$1": $$77}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$77] <- [agg-sql-sum($$82)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$82] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- HYBRID_HASH_JOIN [$$85][$$86]  |PARTITIONED|
-                  -- HASH_PARTITION_EXCHANGE [$$85]  |PARTITIONED|
+                join (eq($$80, $$81))
+                -- HYBRID_HASH_JOIN [$$80][$$81]  |PARTITIONED|
+                  exchange
+                  -- HASH_PARTITION_EXCHANGE [$$80]  |PARTITIONED|
+                    project ([$$80])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$80] <- [{"c": $$c, "n": $$n}.getField("c_custkey")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$c, $$n])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- HYBRID_HASH_JOIN [$$83][$$81]  |PARTITIONED|
-                              -- HASH_PARTITION_EXCHANGE [$$83]  |PARTITIONED|
+                            join (eq($$78, $$76))
+                            -- HYBRID_HASH_JOIN [$$78][$$76]  |PARTITIONED|
+                              exchange
+                              -- HASH_PARTITION_EXCHANGE [$$78]  |PARTITIONED|
+                                assign [$$78] <- [$$c.getField("c_nationkey")]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$c])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (tpch.customer)  |PARTITIONED|
+                                      data-scan []<-[$$75, $$c] <- tpch.customer
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (tpch.nation)  |PARTITIONED|
+                                data-scan []<-[$$76, $$n] <- tpch.nation
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                  -- HASH_PARTITION_EXCHANGE [$$86]  |PARTITIONED|
+                  exchange
+                  -- HASH_PARTITION_EXCHANGE [$$81]  |PARTITIONED|
+                    project ([$$81])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$81] <- [$$o.getField("o_custkey")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$o])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (tpch.orders)  |PARTITIONED|
+                            data-scan []<-[$$74, $$o] <- tpch.orders
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/hashjoin_hint/hashjoin_hint_2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/hashjoin_hint/hashjoin_hint_2.plan
index 5610321..c6bdd5e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/hashjoin_hint/hashjoin_hint_2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/hashjoin_hint/hashjoin_hint_2.plan
@@ -1,34 +1,68 @@
+distribute result [$$73]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$73])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$73] <- [{"$1": $$77}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$77] <- [agg-sql-sum($$82)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$82] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- HYBRID_HASH_JOIN [$$86][$$85]  |PARTITIONED|
-                  -- HASH_PARTITION_EXCHANGE [$$86]  |PARTITIONED|
+                join (eq($$80, $$81))
+                -- HYBRID_HASH_JOIN [$$81][$$80]  |PARTITIONED|
+                  exchange
+                  -- HASH_PARTITION_EXCHANGE [$$81]  |PARTITIONED|
+                    project ([$$81])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$81] <- [$$o.getField("o_custkey")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$o])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (tpch.orders)  |PARTITIONED|
+                            data-scan []<-[$$74, $$o] <- tpch.orders
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                  -- HASH_PARTITION_EXCHANGE [$$85]  |PARTITIONED|
+                  exchange
+                  -- HASH_PARTITION_EXCHANGE [$$80]  |PARTITIONED|
+                    project ([$$80])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$80] <- [{"c": $$c, "n": $$n}.getField("c_custkey")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$c, $$n])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- HYBRID_HASH_JOIN [$$83][$$81]  |PARTITIONED|
-                              -- HASH_PARTITION_EXCHANGE [$$83]  |PARTITIONED|
+                            join (eq($$78, $$76))
+                            -- HYBRID_HASH_JOIN [$$78][$$76]  |PARTITIONED|
+                              exchange
+                              -- HASH_PARTITION_EXCHANGE [$$78]  |PARTITIONED|
+                                assign [$$78] <- [$$c.getField("c_nationkey")]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$c])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (tpch.customer)  |PARTITIONED|
+                                      data-scan []<-[$$75, $$c] <- tpch.customer
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (tpch.nation)  |PARTITIONED|
+                                data-scan []<-[$$76, $$n] <- tpch.nation
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/hashjoin_hint/hashjoin_hint_3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/hashjoin_hint/hashjoin_hint_3.plan
index 5610321..c6bdd5e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/hashjoin_hint/hashjoin_hint_3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/hashjoin_hint/hashjoin_hint_3.plan
@@ -1,34 +1,68 @@
+distribute result [$$73]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$73])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$73] <- [{"$1": $$77}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$77] <- [agg-sql-sum($$82)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$82] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- HYBRID_HASH_JOIN [$$86][$$85]  |PARTITIONED|
-                  -- HASH_PARTITION_EXCHANGE [$$86]  |PARTITIONED|
+                join (eq($$80, $$81))
+                -- HYBRID_HASH_JOIN [$$81][$$80]  |PARTITIONED|
+                  exchange
+                  -- HASH_PARTITION_EXCHANGE [$$81]  |PARTITIONED|
+                    project ([$$81])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$81] <- [$$o.getField("o_custkey")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$o])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (tpch.orders)  |PARTITIONED|
+                            data-scan []<-[$$74, $$o] <- tpch.orders
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                  -- HASH_PARTITION_EXCHANGE [$$85]  |PARTITIONED|
+                  exchange
+                  -- HASH_PARTITION_EXCHANGE [$$80]  |PARTITIONED|
+                    project ([$$80])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$80] <- [{"c": $$c, "n": $$n}.getField("c_custkey")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$c, $$n])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- HYBRID_HASH_JOIN [$$83][$$81]  |PARTITIONED|
-                              -- HASH_PARTITION_EXCHANGE [$$83]  |PARTITIONED|
+                            join (eq($$78, $$76))
+                            -- HYBRID_HASH_JOIN [$$78][$$76]  |PARTITIONED|
+                              exchange
+                              -- HASH_PARTITION_EXCHANGE [$$78]  |PARTITIONED|
+                                assign [$$78] <- [$$c.getField("c_nationkey")]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$c])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (tpch.customer)  |PARTITIONED|
+                                      data-scan []<-[$$75, $$c] <- tpch.customer
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (tpch.nation)  |PARTITIONED|
+                                data-scan []<-[$$76, $$n] <- tpch.nation
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/hashjoin_hint/hashjoin_hint_4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/hashjoin_hint/hashjoin_hint_4.plan
index 5610321..c6bdd5e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/hashjoin_hint/hashjoin_hint_4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/hashjoin_hint/hashjoin_hint_4.plan
@@ -1,34 +1,68 @@
+distribute result [$$73]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$73])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$73] <- [{"$1": $$77}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$77] <- [agg-sql-sum($$82)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$82] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- HYBRID_HASH_JOIN [$$86][$$85]  |PARTITIONED|
-                  -- HASH_PARTITION_EXCHANGE [$$86]  |PARTITIONED|
+                join (eq($$80, $$81))
+                -- HYBRID_HASH_JOIN [$$81][$$80]  |PARTITIONED|
+                  exchange
+                  -- HASH_PARTITION_EXCHANGE [$$81]  |PARTITIONED|
+                    project ([$$81])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$81] <- [$$o.getField("o_custkey")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$o])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (tpch.orders)  |PARTITIONED|
+                            data-scan []<-[$$74, $$o] <- tpch.orders
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                  -- HASH_PARTITION_EXCHANGE [$$85]  |PARTITIONED|
+                  exchange
+                  -- HASH_PARTITION_EXCHANGE [$$80]  |PARTITIONED|
+                    project ([$$80])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$80] <- [{"c": $$c, "n": $$n}.getField("c_custkey")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$c, $$n])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- HYBRID_HASH_JOIN [$$83][$$81]  |PARTITIONED|
-                              -- HASH_PARTITION_EXCHANGE [$$83]  |PARTITIONED|
+                            join (eq($$78, $$76))
+                            -- HYBRID_HASH_JOIN [$$78][$$76]  |PARTITIONED|
+                              exchange
+                              -- HASH_PARTITION_EXCHANGE [$$78]  |PARTITIONED|
+                                assign [$$78] <- [$$c.getField("c_nationkey")]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$c])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (tpch.customer)  |PARTITIONED|
+                                      data-scan []<-[$$75, $$c] <- tpch.customer
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (tpch.nation)  |PARTITIONED|
+                                data-scan []<-[$$76, $$n] <- tpch.nation
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/hashjoin_hint/hashjoin_hint_5.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/hashjoin_hint/hashjoin_hint_5.plan
index c5b8dc2..691c514 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/hashjoin_hint/hashjoin_hint_5.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/hashjoin_hint/hashjoin_hint_5.plan
@@ -1,34 +1,68 @@
+distribute result [$$73]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$73])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$73] <- [{"$1": $$77}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$77] <- [agg-sql-sum($$82)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$82] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- HYBRID_HASH_JOIN [$$85][$$86]  |PARTITIONED|
-                  -- HASH_PARTITION_EXCHANGE [$$85]  |PARTITIONED|
+                join (eq($$80, $$81))
+                -- HYBRID_HASH_JOIN [$$80][$$81]  |PARTITIONED|
+                  exchange
+                  -- HASH_PARTITION_EXCHANGE [$$80]  |PARTITIONED|
+                    project ([$$80])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$80] <- [{"c": $$c, "n": $$n}.getField("c_custkey")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$c, $$n])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- HYBRID_HASH_JOIN [$$83][$$81]  |PARTITIONED|
-                              -- HASH_PARTITION_EXCHANGE [$$83]  |PARTITIONED|
+                            join (eq($$78, $$76))
+                            -- HYBRID_HASH_JOIN [$$78][$$76]  |PARTITIONED|
+                              exchange
+                              -- HASH_PARTITION_EXCHANGE [$$78]  |PARTITIONED|
+                                assign [$$78] <- [$$c.getField("c_nationkey")]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$c])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (tpch.customer)  |PARTITIONED|
+                                      data-scan []<-[$$75, $$c] <- tpch.customer
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (tpch.nation)  |PARTITIONED|
+                                data-scan []<-[$$76, $$n] <- tpch.nation
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                  -- HASH_PARTITION_EXCHANGE [$$86]  |PARTITIONED|
+                  exchange
+                  -- HASH_PARTITION_EXCHANGE [$$81]  |PARTITIONED|
+                    project ([$$81])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$81] <- [$$o.getField("o_custkey")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$o])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (tpch.orders)  |PARTITIONED|
+                            data-scan []<-[$$74, $$o] <- tpch.orders
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/hashjoin_hint/hashjoin_hint_6.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/hashjoin_hint/hashjoin_hint_6.plan
index c5b8dc2..691c514 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/hashjoin_hint/hashjoin_hint_6.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/hints/hashjoin_hint/hashjoin_hint_6.plan
@@ -1,34 +1,68 @@
+distribute result [$$73]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$73])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$73] <- [{"$1": $$77}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$77] <- [agg-sql-sum($$82)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$82] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- HYBRID_HASH_JOIN [$$85][$$86]  |PARTITIONED|
-                  -- HASH_PARTITION_EXCHANGE [$$85]  |PARTITIONED|
+                join (eq($$80, $$81))
+                -- HYBRID_HASH_JOIN [$$80][$$81]  |PARTITIONED|
+                  exchange
+                  -- HASH_PARTITION_EXCHANGE [$$80]  |PARTITIONED|
+                    project ([$$80])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$80] <- [{"c": $$c, "n": $$n}.getField("c_custkey")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$c, $$n])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- HYBRID_HASH_JOIN [$$83][$$81]  |PARTITIONED|
-                              -- HASH_PARTITION_EXCHANGE [$$83]  |PARTITIONED|
+                            join (eq($$78, $$76))
+                            -- HYBRID_HASH_JOIN [$$78][$$76]  |PARTITIONED|
+                              exchange
+                              -- HASH_PARTITION_EXCHANGE [$$78]  |PARTITIONED|
+                                assign [$$78] <- [$$c.getField("c_nationkey")]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$c])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (tpch.customer)  |PARTITIONED|
+                                      data-scan []<-[$$75, $$c] <- tpch.customer
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (tpch.nation)  |PARTITIONED|
+                                data-scan []<-[$$76, $$n] <- tpch.nation
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                  -- HASH_PARTITION_EXCHANGE [$$86]  |PARTITIONED|
+                  exchange
+                  -- HASH_PARTITION_EXCHANGE [$$81]  |PARTITIONED|
+                    project ([$$81])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$81] <- [$$o.getField("o_custkey")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$o])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (tpch.orders)  |PARTITIONED|
+                            data-scan []<-[$$74, $$o] <- tpch.orders
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/insert-and-scan-dataset.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/insert-and-scan-dataset.plan
index 9c4bd33..3923c3f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/insert-and-scan-dataset.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/insert-and-scan-dataset.plan
@@ -1,15 +1,30 @@
+commit
 -- COMMIT  |PARTITIONED|
+  project ([$$16])
   -- STREAM_PROJECT  |PARTITIONED|
+    exchange
     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+      insert into test.myData from record: $$17 partitioned by [$$16]
       -- INSERT_DELETE  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          materialize
           -- MATERIALIZE  |PARTITIONED|
+            exchange
             -- HASH_PARTITION_EXCHANGE [$$16]  |PARTITIONED|
+              assign [$$16] <- [$$17.getField(0)]
               -- ASSIGN  |PARTITIONED|
+                project ([$$17])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$17] <- [cast({"id": numeric-add($$18, 1)})]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$18])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.myData)  |PARTITIONED|
+                        data-scan []<-[$$18, $$x] <- test.myData
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/introhashpartitionmerge.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/introhashpartitionmerge.plan
index d122327..e0b8abf 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/introhashpartitionmerge.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/introhashpartitionmerge.plan
@@ -1,22 +1,44 @@
+distribute result [$$42]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$42(ASC) ]  |PARTITIONED|
+    order (ASC, $$42)
     -- STABLE_SORT [$$42(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$42])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$43, $$44))
             -- HYBRID_HASH_JOIN [$$43][$$44]  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$43]  |PARTITIONED|
+                project ([$$43])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$43] <- [$$token1.getField(0)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$token1])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (fuzzyjoin.TOKENSRANKEDADM)  |PARTITIONED|
+                        data-scan []<-[$$41, $$token1] <- fuzzyjoin.TOKENSRANKEDADM
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_MERGE_EXCHANGE MERGE:[$$42(ASC)] HASH:[$$44]  |PARTITIONED|
+                project ([$$42, $$44])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$44] <- [$$tokenRanked.getField(0)]
                   -- ASSIGN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (fuzzyjoin.TOKENSRANKEDADM)  |PARTITIONED|
+                      data-scan []<-[$$42, $$tokenRanked] <- fuzzyjoin.TOKENSRANKEDADM
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-contains-panic.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-contains-panic.plan
index 8a9e3fa..8aa2a40 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-contains-panic.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-contains-panic.plan
@@ -1,9 +1,18 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$o])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- SORT_MERGE_EXCHANGE [$$15(ASC) ]  |PARTITIONED|
+        select (contains($$o.getField(2), "Mu"))
         -- STREAM_SELECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+            data-scan []<-[$$15, $$o] <- test.DBLP
+            -- DATASOURCE_SCAN  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                empty-tuple-source
                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-contains-panic_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-contains-panic_ps.plan
index 93ca5bd..2c2fae0 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-contains-panic_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-contains-panic_ps.plan
@@ -1,28 +1,56 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$o])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$15)
         -- STABLE_SORT [$$15(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$15(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$20
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (contains($$o.getField(2), "Mu"))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                        data-scan []<-[$$15, $$o] <- test.DBLP
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$20] <- [agg-range-map($$18, $$19)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$18, $$19] <- [agg-local-sampling($$15), agg-null-writer($$15)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$15])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (contains($$o.getField(2), "Mu"))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                  data-scan []<-[$$15, $$o] <- test.DBLP
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-contains.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-contains.plan
index 540bb89..310832c 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-contains.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-contains.plan
@@ -1,14 +1,28 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$o])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- SORT_MERGE_EXCHANGE [$$15(ASC) ]  |PARTITIONED|
+        select (contains($$o.getField(2), "Multimedia"))
         -- STREAM_SELECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+            unnest-map [$$15, $$o] <- index-search("DBLP", 0, "test", "DBLP", false, false, 1, $$19, 1, $$19, true, true, true)
+            -- BTREE_SEARCH  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (ASC, $$19)
                 -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                    unnest-map [$$19] <- index-search("ngram_index", 5, "test", "DBLP", false, false, 0, missing, 12, false, 1, $$18)
+                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        assign [$$18] <- ["Multimedia"]
                         -- ASSIGN  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-contains_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-contains_ps.plan
index ed6a9c5..a3847e3 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-contains_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-contains_ps.plan
@@ -1,38 +1,76 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$o])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$15)
         -- STABLE_SORT [$$15(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$15(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$22
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (contains($$o.getField(2), "Multimedia"))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                        unnest-map [$$15, $$o] <- index-search("DBLP", 0, "test", "DBLP", false, false, 1, $$19, 1, $$19, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$19)
                             -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                                unnest-map [$$19] <- index-search("ngram_index", 5, "test", "DBLP", false, false, 0, missing, 12, false, 1, $$18)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    assign [$$18] <- ["Multimedia"]
                                     -- ASSIGN  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$22] <- [agg-range-map($$20, $$21)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$20, $$21] <- [agg-local-sampling($$15), agg-null-writer($$15)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$15])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (contains($$o.getField(2), "Multimedia"))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                                  unnest-map [$$15, $$o] <- index-search("DBLP", 0, "test", "DBLP", false, false, 1, $$19, 1, $$19, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$19)
                                       -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                                          unnest-map [$$19] <- index-search("ngram_index", 5, "test", "DBLP", false, false, 0, missing, 12, false, 1, $$18)
+                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$18] <- ["Multimedia"]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-edit-distance-check.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-edit-distance-check.plan
index 0589004..890199d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-edit-distance-check.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-edit-distance-check.plan
@@ -1,13 +1,26 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (get-item(edit-distance-check($$o.getField(3), "Amihay Motro", 1), 0))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$o])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+          unnest-map [$$15, $$o] <- index-search("DBLP", 0, "test", "DBLP", false, false, 1, $$18, 1, $$18, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$18)
               -- STABLE_SORT [$$18(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                  unnest-map [$$18] <- index-search("ngram_index", 5, "test", "DBLP", false, false, 2, 1, 12, false, 1, $$17)
+                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      assign [$$17] <- ["Amihay Motro"]
                       -- ASSIGN  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-edit-distance.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-edit-distance.plan
index 0589004..890199d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-edit-distance.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-edit-distance.plan
@@ -1,13 +1,26 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (get-item(edit-distance-check($$o.getField(3), "Amihay Motro", 1), 0))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$o])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+          unnest-map [$$15, $$o] <- index-search("DBLP", 0, "test", "DBLP", false, false, 1, $$18, 1, $$18, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$18)
               -- STABLE_SORT [$$18(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                  unnest-map [$$18] <- index-search("ngram_index", 5, "test", "DBLP", false, false, 2, 1, 12, false, 1, $$17)
+                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      assign [$$17] <- ["Amihay Motro"]
                       -- ASSIGN  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-fuzzyeq-edit-distance.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-fuzzyeq-edit-distance.plan
index 8112a91..0cce130 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-fuzzyeq-edit-distance.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-fuzzyeq-edit-distance.plan
@@ -1,13 +1,26 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (get-item(edit-distance-check($$o.getField(3), "Amihay Motro", 1), 0))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$o])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+          unnest-map [$$14, $$o] <- index-search("DBLP", 0, "test", "DBLP", false, false, 1, $$17, 1, $$17, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$17)
               -- STABLE_SORT [$$17(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                  unnest-map [$$17] <- index-search("ngram_index", 5, "test", "DBLP", false, false, 2, 1, 12, false, 1, $$16)
+                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      assign [$$16] <- ["Amihay Motro"]
                       -- ASSIGN  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-fuzzyeq-jaccard.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-fuzzyeq-jaccard.plan
index 334be33..8890f37 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-fuzzyeq-jaccard.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-fuzzyeq-jaccard.plan
@@ -1,13 +1,26 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (get-item(similarity-jaccard-check(gram-tokens($$o.getField(2), 3, false), array: [ "tra", "ran", "ans", "nsa", "sac", "act", "cti", "tio", "ion", "ons", "ns ", "s f", " fo", "for", "or ", "r c", " co", "coo", "oop", "ope", "per", "era", "rat", "ati", "tiv", "ive", "ve ", "e e", " en", "env", "nvi", "vir", "iro", "ron", "onm", "nme", "men", "ent", "nts" ], 0.8), 0))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$o])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+          unnest-map [$$16, $$o] <- index-search("DBLP", 0, "test", "DBLP", false, false, 1, $$19, 1, $$19, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$19)
               -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                  unnest-map [$$19] <- index-search("ngram_index", 5, "test", "DBLP", false, false, 1, 0.8, 21, false, 1, $$18)
+                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      assign [$$18] <- [array: [ "tra", "ran", "ans", "nsa", "sac", "act", "cti", "tio", "ion", "ons", "ns ", "s f", " fo", "for", "or ", "r c", " co", "coo", "oop", "ope", "per", "era", "rat", "ati", "tiv", "ive", "ve ", "e e", " en", "env", "nvi", "vir", "iro", "ron", "onm", "nme", "men", "ent", "nts" ]]
                       -- ASSIGN  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-jaccard-check.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-jaccard-check.plan
index b415aa0..f55bf6a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-jaccard-check.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-jaccard-check.plan
@@ -1,13 +1,26 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (get-item(similarity-jaccard-check(gram-tokens($$o.getField(2), 3, false), array: [ "tra", "ran", "ans", "nsa", "sac", "act", "cti", "tio", "ion", "ons", "ns ", "s f", " fo", "for", "or ", "r c", " co", "coo", "oop", "ope", "per", "era", "rat", "ati", "tiv", "ive", "ve ", "e e", " en", "env", "nvi", "vir", "iro", "ron", "onm", "nme", "men", "ent", "nts" ], 0.5), 0))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$o])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+          unnest-map [$$17, $$o] <- index-search("DBLP", 0, "test", "DBLP", false, false, 1, $$20, 1, $$20, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$20)
               -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                  unnest-map [$$20] <- index-search("ngram_index", 5, "test", "DBLP", false, false, 1, 0.5, 21, false, 1, $$19)
+                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      assign [$$19] <- [array: [ "tra", "ran", "ans", "nsa", "sac", "act", "cti", "tio", "ion", "ons", "ns ", "s f", " fo", "for", "or ", "r c", " co", "coo", "oop", "ope", "per", "era", "rat", "ati", "tiv", "ive", "ve ", "e e", " en", "env", "nvi", "vir", "iro", "ron", "onm", "nme", "men", "ent", "nts" ]]
                       -- ASSIGN  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-jaccard.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-jaccard.plan
index b415aa0..f55bf6a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-jaccard.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ngram-jaccard.plan
@@ -1,13 +1,26 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (get-item(similarity-jaccard-check(gram-tokens($$o.getField(2), 3, false), array: [ "tra", "ran", "ans", "nsa", "sac", "act", "cti", "tio", "ion", "ons", "ns ", "s f", " fo", "for", "or ", "r c", " co", "coo", "oop", "ope", "per", "era", "rat", "ati", "tiv", "ive", "ve ", "e e", " en", "env", "nvi", "vir", "iro", "ron", "onm", "nme", "men", "ent", "nts" ], 0.5), 0))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$o])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+          unnest-map [$$17, $$o] <- index-search("DBLP", 0, "test", "DBLP", false, false, 1, $$20, 1, $$20, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$20)
               -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                  unnest-map [$$20] <- index-search("ngram_index", 5, "test", "DBLP", false, false, 1, 0.5, 21, false, 1, $$19)
+                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      assign [$$19] <- [array: [ "tra", "ran", "ans", "nsa", "sac", "act", "cti", "tio", "ion", "ons", "ns ", "s f", " fo", "for", "or ", "r c", " co", "coo", "oop", "ope", "per", "era", "rat", "ati", "tiv", "ive", "ve ", "e e", " en", "env", "nvi", "vir", "iro", "ron", "onm", "nme", "men", "ent", "nts" ]]
                       -- ASSIGN  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance-check-panic.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance-check-panic.plan
index 7434db4..1faa4e0 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance-check-panic.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance-check-panic.plan
@@ -1,9 +1,18 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$c])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- SORT_MERGE_EXCHANGE [$$17(ASC) ]  |PARTITIONED|
+        select (get-item(edit-distance-check($$c.getField(4), array: [ "computers", "wine", "walking" ], 3), 0))
         -- STREAM_SELECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+            data-scan []<-[$$17, $$c] <- test.Customers
+            -- DATASOURCE_SCAN  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                empty-tuple-source
                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance-check-panic_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance-check-panic_ps.plan
index 1e433b8..61d5347 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance-check-panic_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance-check-panic_ps.plan
@@ -1,28 +1,56 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$c])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$17)
         -- STABLE_SORT [$$17(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$17(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$22
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (get-item(edit-distance-check($$c.getField(4), array: [ "computers", "wine", "walking" ], 3), 0))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                        data-scan []<-[$$17, $$c] <- test.Customers
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$22] <- [agg-range-map($$20, $$21)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$20, $$21] <- [agg-local-sampling($$17), agg-null-writer($$17)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$17])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (get-item(edit-distance-check($$c.getField(4), array: [ "computers", "wine", "walking" ], 3), 0))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                  data-scan []<-[$$17, $$c] <- test.Customers
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance-check.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance-check.plan
index 719fa63..520b484 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance-check.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance-check.plan
@@ -1,14 +1,28 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$c])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- SORT_MERGE_EXCHANGE [$$17(ASC) ]  |PARTITIONED|
+        select (get-item(edit-distance-check($$c.getField(4), array: [ "computers", "wine", "walking" ], 1), 0))
         -- STREAM_SELECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+            unnest-map [$$17, $$c] <- index-search("Customers", 0, "test", "Customers", false, false, 1, $$21, 1, $$21, true, true, true)
+            -- BTREE_SEARCH  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (ASC, $$21)
                 -- STABLE_SORT [$$21(ASC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                    unnest-map [$$21] <- index-search("interests_index", 4, "test", "Customers", false, false, 2, 1, 21, false, 1, $$20)
+                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        assign [$$20] <- [array: [ "computers", "wine", "walking" ]]
                         -- ASSIGN  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance-check_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance-check_ps.plan
index 7a151d5..445ad70 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance-check_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance-check_ps.plan
@@ -1,38 +1,76 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$c])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$17)
         -- STABLE_SORT [$$17(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$17(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$24
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (get-item(edit-distance-check($$c.getField(4), array: [ "computers", "wine", "walking" ], 1), 0))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                        unnest-map [$$17, $$c] <- index-search("Customers", 0, "test", "Customers", false, false, 1, $$21, 1, $$21, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$21)
                             -- STABLE_SORT [$$21(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                unnest-map [$$21] <- index-search("interests_index", 4, "test", "Customers", false, false, 2, 1, 21, false, 1, $$20)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    assign [$$20] <- [array: [ "computers", "wine", "walking" ]]
                                     -- ASSIGN  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$24] <- [agg-range-map($$22, $$23)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$22, $$23] <- [agg-local-sampling($$17), agg-null-writer($$17)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$17])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (get-item(edit-distance-check($$c.getField(4), array: [ "computers", "wine", "walking" ], 1), 0))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                                  unnest-map [$$17, $$c] <- index-search("Customers", 0, "test", "Customers", false, false, 1, $$21, 1, $$21, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$21)
                                       -- STABLE_SORT [$$21(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                          unnest-map [$$21] <- index-search("interests_index", 4, "test", "Customers", false, false, 2, 1, 21, false, 1, $$20)
+                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$20] <- [array: [ "computers", "wine", "walking" ]]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance-panic.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance-panic.plan
index 7434db4..1faa4e0 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance-panic.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance-panic.plan
@@ -1,9 +1,18 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$c])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- SORT_MERGE_EXCHANGE [$$17(ASC) ]  |PARTITIONED|
+        select (get-item(edit-distance-check($$c.getField(4), array: [ "computers", "wine", "walking" ], 3), 0))
         -- STREAM_SELECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+            data-scan []<-[$$17, $$c] <- test.Customers
+            -- DATASOURCE_SCAN  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                empty-tuple-source
                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance-panic_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance-panic_ps.plan
index 1e433b8..61d5347 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance-panic_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance-panic_ps.plan
@@ -1,28 +1,56 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$c])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$17)
         -- STABLE_SORT [$$17(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$17(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$22
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (get-item(edit-distance-check($$c.getField(4), array: [ "computers", "wine", "walking" ], 3), 0))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                        data-scan []<-[$$17, $$c] <- test.Customers
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$22] <- [agg-range-map($$20, $$21)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$20, $$21] <- [agg-local-sampling($$17), agg-null-writer($$17)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$17])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (get-item(edit-distance-check($$c.getField(4), array: [ "computers", "wine", "walking" ], 3), 0))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                  data-scan []<-[$$17, $$c] <- test.Customers
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance.plan
index 719fa63..520b484 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance.plan
@@ -1,14 +1,28 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$c])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- SORT_MERGE_EXCHANGE [$$17(ASC) ]  |PARTITIONED|
+        select (get-item(edit-distance-check($$c.getField(4), array: [ "computers", "wine", "walking" ], 1), 0))
         -- STREAM_SELECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+            unnest-map [$$17, $$c] <- index-search("Customers", 0, "test", "Customers", false, false, 1, $$21, 1, $$21, true, true, true)
+            -- BTREE_SEARCH  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (ASC, $$21)
                 -- STABLE_SORT [$$21(ASC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                    unnest-map [$$21] <- index-search("interests_index", 4, "test", "Customers", false, false, 2, 1, 21, false, 1, $$20)
+                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        assign [$$20] <- [array: [ "computers", "wine", "walking" ]]
                         -- ASSIGN  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance_ps.plan
index 7a151d5..445ad70 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-edit-distance_ps.plan
@@ -1,38 +1,76 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$c])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$17)
         -- STABLE_SORT [$$17(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$17(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$24
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (get-item(edit-distance-check($$c.getField(4), array: [ "computers", "wine", "walking" ], 1), 0))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                        unnest-map [$$17, $$c] <- index-search("Customers", 0, "test", "Customers", false, false, 1, $$21, 1, $$21, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$21)
                             -- STABLE_SORT [$$21(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                unnest-map [$$21] <- index-search("interests_index", 4, "test", "Customers", false, false, 2, 1, 21, false, 1, $$20)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    assign [$$20] <- [array: [ "computers", "wine", "walking" ]]
                                     -- ASSIGN  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$24] <- [agg-range-map($$22, $$23)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$22, $$23] <- [agg-local-sampling($$17), agg-null-writer($$17)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$17])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (get-item(edit-distance-check($$c.getField(4), array: [ "computers", "wine", "walking" ], 1), 0))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                                  unnest-map [$$17, $$c] <- index-search("Customers", 0, "test", "Customers", false, false, 1, $$21, 1, $$21, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$21)
                                       -- STABLE_SORT [$$21(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                          unnest-map [$$21] <- index-search("interests_index", 4, "test", "Customers", false, false, 2, 1, 21, false, 1, $$20)
+                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$20] <- [array: [ "computers", "wine", "walking" ]]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-fuzzyeq-edit-distance.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-fuzzyeq-edit-distance.plan
index a4d6af9..31fd309 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-fuzzyeq-edit-distance.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-fuzzyeq-edit-distance.plan
@@ -1,14 +1,28 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$c])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- SORT_MERGE_EXCHANGE [$$16(ASC) ]  |PARTITIONED|
+        select (get-item(edit-distance-check($$c.getField(4), array: [ "computers", "wine", "walking" ], 1), 0))
         -- STREAM_SELECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+            unnest-map [$$16, $$c] <- index-search("Customers", 0, "test", "Customers", false, false, 1, $$20, 1, $$20, true, true, true)
+            -- BTREE_SEARCH  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (ASC, $$20)
                 -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                    unnest-map [$$20] <- index-search("interests_index", 4, "test", "Customers", false, false, 2, 1, 21, false, 1, $$19)
+                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        assign [$$19] <- [array: [ "computers", "wine", "walking" ]]
                         -- ASSIGN  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-fuzzyeq-edit-distance_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-fuzzyeq-edit-distance_ps.plan
index b9cf357..ab97e40 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-fuzzyeq-edit-distance_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-fuzzyeq-edit-distance_ps.plan
@@ -1,38 +1,76 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$c])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$16)
         -- STABLE_SORT [$$16(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$16(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$23
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (get-item(edit-distance-check($$c.getField(4), array: [ "computers", "wine", "walking" ], 1), 0))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                        unnest-map [$$16, $$c] <- index-search("Customers", 0, "test", "Customers", false, false, 1, $$20, 1, $$20, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$20)
                             -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                unnest-map [$$20] <- index-search("interests_index", 4, "test", "Customers", false, false, 2, 1, 21, false, 1, $$19)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    assign [$$19] <- [array: [ "computers", "wine", "walking" ]]
                                     -- ASSIGN  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$23] <- [agg-range-map($$21, $$22)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$21, $$22] <- [agg-local-sampling($$16), agg-null-writer($$16)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$16])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (get-item(edit-distance-check($$c.getField(4), array: [ "computers", "wine", "walking" ], 1), 0))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                                  unnest-map [$$16, $$c] <- index-search("Customers", 0, "test", "Customers", false, false, 1, $$20, 1, $$20, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$20)
                                       -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                          unnest-map [$$20] <- index-search("interests_index", 4, "test", "Customers", false, false, 2, 1, 21, false, 1, $$19)
+                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$19] <- [array: [ "computers", "wine", "walking" ]]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-fuzzyeq-jaccard.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-fuzzyeq-jaccard.plan
index 79c9758..83c2bba 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-fuzzyeq-jaccard.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-fuzzyeq-jaccard.plan
@@ -1,13 +1,26 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (get-item(similarity-jaccard-check($$c.getField(4), array: [ "databases", "computers", "wine" ], 0.8), 0))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$c])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+          unnest-map [$$15, $$c] <- index-search("Customers", 0, "test", "Customers", false, false, 1, $$18, 1, $$18, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$18)
               -- STABLE_SORT [$$18(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                  unnest-map [$$18] <- index-search("interests_index", 4, "test", "Customers", false, false, 1, 0.8, 21, false, 1, $$17)
+                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      assign [$$17] <- [array: [ "databases", "computers", "wine" ]]
                       -- ASSIGN  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-jaccard-check.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-jaccard-check.plan
index a9465ae..b2bb55b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-jaccard-check.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-jaccard-check.plan
@@ -1,13 +1,26 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (get-item(similarity-jaccard-check($$c.getField(4), array: [ "databases", "computers", "wine" ], 0.7), 0))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$c])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+          unnest-map [$$16, $$c] <- index-search("Customers", 0, "test", "Customers", false, false, 1, $$19, 1, $$19, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$19)
               -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                  unnest-map [$$19] <- index-search("interests_index", 4, "test", "Customers", false, false, 1, 0.7, 21, false, 1, $$18)
+                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      assign [$$18] <- [array: [ "databases", "computers", "wine" ]]
                       -- ASSIGN  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-jaccard.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-jaccard.plan
index a9465ae..b2bb55b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-jaccard.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/olist-jaccard.plan
@@ -1,13 +1,26 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (get-item(similarity-jaccard-check($$c.getField(4), array: [ "databases", "computers", "wine" ], 0.7), 0))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$c])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+          unnest-map [$$16, $$c] <- index-search("Customers", 0, "test", "Customers", false, false, 1, $$19, 1, $$19, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$19)
               -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                  unnest-map [$$19] <- index-search("interests_index", 4, "test", "Customers", false, false, 1, 0.7, 21, false, 1, $$18)
+                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      assign [$$18] <- [array: [ "databases", "computers", "wine" ]]
                       -- ASSIGN  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ulist-fuzzyeq-jaccard.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ulist-fuzzyeq-jaccard.plan
index 79c9758..928f341 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ulist-fuzzyeq-jaccard.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ulist-fuzzyeq-jaccard.plan
@@ -1,13 +1,26 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (get-item(similarity-jaccard-check($$c.getField(4), multiset: {{ "computers", "wine", "databases" }}, 0.8), 0))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$c])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+          unnest-map [$$15, $$c] <- index-search("Customers", 0, "test", "Customers", false, false, 1, $$18, 1, $$18, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$18)
               -- STABLE_SORT [$$18(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                  unnest-map [$$18] <- index-search("interests_index", 4, "test", "Customers", false, false, 1, 0.8, 22, false, 1, $$17)
+                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      assign [$$17] <- [multiset: {{ "computers", "wine", "databases" }}]
                       -- ASSIGN  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ulist-jaccard-check.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ulist-jaccard-check.plan
index a9465ae..795f0e1 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ulist-jaccard-check.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ulist-jaccard-check.plan
@@ -1,13 +1,26 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (get-item(similarity-jaccard-check($$c.getField(4), multiset: {{ "computers", "wine", "databases" }}, 0.7), 0))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$c])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+          unnest-map [$$16, $$c] <- index-search("Customers", 0, "test", "Customers", false, false, 1, $$19, 1, $$19, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$19)
               -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                  unnest-map [$$19] <- index-search("interests_index", 4, "test", "Customers", false, false, 1, 0.7, 22, false, 1, $$18)
+                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      assign [$$18] <- [multiset: {{ "computers", "wine", "databases" }}]
                       -- ASSIGN  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ulist-jaccard.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ulist-jaccard.plan
index a9465ae..e2eab53 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ulist-jaccard.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/ulist-jaccard.plan
@@ -1,13 +1,26 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (get-item(similarity-jaccard-check($$c.getField(4), multiset: {{ "computers", "databases", "wine" }}, 0.7), 0))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$c])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+          unnest-map [$$16, $$c] <- index-search("Customers", 0, "test", "Customers", false, false, 1, $$19, 1, $$19, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$19)
               -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                  unnest-map [$$19] <- index-search("interests_index", 4, "test", "Customers", false, false, 1, 0.7, 22, false, 1, $$18)
+                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      assign [$$18] <- [multiset: {{ "computers", "databases", "wine" }}]
                       -- ASSIGN  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/word-contains.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/word-contains.plan
index 8a9e3fa..529a662 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/word-contains.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/word-contains.plan
@@ -1,9 +1,18 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$o])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- SORT_MERGE_EXCHANGE [$$15(ASC) ]  |PARTITIONED|
+        select (contains($$o.getField(2), "Multimedia"))
         -- STREAM_SELECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+            data-scan []<-[$$15, $$o] <- test.DBLP
+            -- DATASOURCE_SCAN  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                empty-tuple-source
                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/word-contains_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/word-contains_ps.plan
index 93ca5bd..d6a002c 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/word-contains_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/word-contains_ps.plan
@@ -1,28 +1,56 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$o])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$15)
         -- STABLE_SORT [$$15(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$15(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$20
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (contains($$o.getField(2), "Multimedia"))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                        data-scan []<-[$$15, $$o] <- test.DBLP
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$20] <- [agg-range-map($$18, $$19)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$18, $$19] <- [agg-local-sampling($$15), agg-null-writer($$15)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$15])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (contains($$o.getField(2), "Multimedia"))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                  data-scan []<-[$$15, $$o] <- test.DBLP
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/word-fuzzyeq-jaccard.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/word-fuzzyeq-jaccard.plan
index 062460e..ac8d77d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/word-fuzzyeq-jaccard.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/word-fuzzyeq-jaccard.plan
@@ -1,13 +1,26 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (get-item(similarity-jaccard-check(word-tokens($$o.getField(2)), array: [ "transactions", "for", "cooperative", "environments" ], 0.5), 0))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$o])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+          unnest-map [$$16, $$o] <- index-search("DBLP", 0, "test", "DBLP", false, false, 1, $$19, 1, $$19, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$19)
               -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.keyword_index)  |PARTITIONED|
+                  unnest-map [$$19] <- index-search("keyword_index", 4, "test", "DBLP", false, false, 1, 0.5, 21, false, 1, $$18)
+                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      assign [$$18] <- [array: [ "transactions", "for", "cooperative", "environments" ]]
                       -- ASSIGN  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/word-jaccard-check.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/word-jaccard-check.plan
index f4a3522..721d2d5 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/word-jaccard-check.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/word-jaccard-check.plan
@@ -1,13 +1,26 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (get-item(similarity-jaccard-check(word-tokens($$o.getField(2)), array: [ "transactions", "for", "cooperative", "environments" ], 0.5), 0))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$o])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+          unnest-map [$$17, $$o] <- index-search("DBLP", 0, "test", "DBLP", false, false, 1, $$20, 1, $$20, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$20)
               -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.keyword_index)  |PARTITIONED|
+                  unnest-map [$$20] <- index-search("keyword_index", 4, "test", "DBLP", false, false, 1, 0.5, 21, false, 1, $$19)
+                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      assign [$$19] <- [array: [ "transactions", "for", "cooperative", "environments" ]]
                       -- ASSIGN  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/word-jaccard.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/word-jaccard.plan
index f4a3522..721d2d5 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/word-jaccard.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-basic/word-jaccard.plan
@@ -1,13 +1,26 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (get-item(similarity-jaccard-check(word-tokens($$o.getField(2)), array: [ "transactions", "for", "cooperative", "environments" ], 0.5), 0))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$o])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+          unnest-map [$$17, $$o] <- index-search("DBLP", 0, "test", "DBLP", false, false, 1, $$20, 1, $$20, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$20)
               -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.keyword_index)  |PARTITIONED|
+                  unnest-map [$$20] <- index-search("keyword_index", 4, "test", "DBLP", false, false, 1, 0.5, 21, false, 1, $$19)
+                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      assign [$$19] <- [array: [ "transactions", "for", "cooperative", "environments" ]]
                       -- ASSIGN  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_01.plan
index 3003bc7..54f8fc5 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_01.plan
@@ -1,15 +1,30 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$o])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (and(get-item(edit-distance-check($$39, "Amihay Motro", 5), 0), get-item(edit-distance-check($$39, "Amihay Motro", 3), 0)))
       -- STREAM_SELECT  |PARTITIONED|
+        assign [$$39] <- [$$o.getField(3)]
         -- ASSIGN  |PARTITIONED|
+          project ([$$o])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+              unnest-map [$$40, $$o] <- index-search("DBLP", 0, "test", "DBLP", false, false, 1, $$42, 1, $$42, true, true, true)
+              -- BTREE_SEARCH  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  order (ASC, $$42)
                   -- STABLE_SORT [$$42(ASC)]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                      unnest-map [$$42] <- index-search("ngram_index", 5, "test", "DBLP", false, false, 2, 3, 12, false, 1, $$41)
+                      -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$41] <- ["Amihay Motro"]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_02.plan
index 3003bc7..59a824b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_02.plan
@@ -1,15 +1,30 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$o])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (and(get-item(edit-distance-check($$39, "Amihay Motro", 3), 0), get-item(edit-distance-check($$39, "Amihay Motro", 5), 0)))
       -- STREAM_SELECT  |PARTITIONED|
+        assign [$$39] <- [$$o.getField(3)]
         -- ASSIGN  |PARTITIONED|
+          project ([$$o])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+              unnest-map [$$40, $$o] <- index-search("DBLP", 0, "test", "DBLP", false, false, 1, $$42, 1, $$42, true, true, true)
+              -- BTREE_SEARCH  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  order (ASC, $$42)
                   -- STABLE_SORT [$$42(ASC)]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                      unnest-map [$$42] <- index-search("ngram_index", 5, "test", "DBLP", false, false, 2, 3, 12, false, 1, $$41)
+                      -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$41] <- ["Amihay Motro"]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-edit-distance-check-let.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-edit-distance-check-let.plan
index 117d73c..9fdb178 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-edit-distance-check-let.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-edit-distance-check-let.plan
@@ -1,13 +1,26 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (get-item(edit-distance-check($$o.getField(3), "Amihay Motro", 1), 0))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$o])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+          unnest-map [$$25, $$o] <- index-search("DBLP", 0, "test", "DBLP", false, false, 1, $$28, 1, $$28, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$28)
               -- STABLE_SORT [$$28(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                  unnest-map [$$28] <- index-search("ngram_index", 5, "test", "DBLP", false, false, 2, 1, 12, false, 1, $$27)
+                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      assign [$$27] <- ["Amihay Motro"]
                       -- ASSIGN  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-edit-distance-check-substring.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-edit-distance-check-substring.plan
index 94e20b4..a6eb9ba 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-edit-distance-check-substring.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-edit-distance-check-substring.plan
@@ -1,16 +1,32 @@
+distribute result [$$19]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$19])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$19] <- [{"id": $$21, "title": $$20}]
       -- ASSIGN  |PARTITIONED|
+        select (get-item(edit-distance-check(substring($$20, 0, 8), "datbase", 1), 0))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$21, $$20])
           -- STREAM_PROJECT  |PARTITIONED|
+            assign [$$20] <- [$$paper.getField(2)]
             -- ASSIGN  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                unnest-map [$$21, $$paper] <- index-search("DBLP", 0, "test", "DBLP", false, false, 1, $$24, 1, $$24, true, true, true)
+                -- BTREE_SEARCH  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    order (ASC, $$24)
                     -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                        unnest-map [$$24] <- index-search("ngram_index", 5, "test", "DBLP", false, false, 2, 1, 12, false, 1, $$23)
+                        -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            assign [$$23] <- ["datbase"]
                             -- ASSIGN  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-jaccard-check-let.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-jaccard-check-let.plan
index f1cac23..000c0c6 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-jaccard-check-let.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-jaccard-check-let.plan
@@ -1,13 +1,26 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (get-item(similarity-jaccard-check(gram-tokens($$o.getField(2), 3, false), array: [ "tra", "ran", "ans", "nsa", "sac", "act", "cti", "tio", "ion", "ons", "ns ", "s f", " fo", "for", "or ", "r c", " co", "coo", "oop", "ope", "per", "era", "rat", "ati", "tiv", "ive", "ve ", "e e", " en", "env", "nvi", "vir", "iro", "ron", "onm", "nme", "men", "ent", "nts" ], 0.5), 0))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$o])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+          unnest-map [$$27, $$o] <- index-search("DBLP", 0, "test", "DBLP", false, false, 1, $$30, 1, $$30, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$30)
               -- STABLE_SORT [$$30(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                  unnest-map [$$30] <- index-search("ngram_index", 5, "test", "DBLP", false, false, 1, 0.5, 21, false, 1, $$29)
+                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      assign [$$29] <- [array: [ "tra", "ran", "ans", "nsa", "sac", "act", "cti", "tio", "ion", "ons", "ns ", "s f", " fo", "for", "or ", "r c", " co", "coo", "oop", "ope", "per", "era", "rat", "ati", "tiv", "ive", "ve ", "e e", " en", "env", "nvi", "vir", "iro", "ron", "onm", "nme", "men", "ent", "nts" ]]
                       -- ASSIGN  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-jaccard-check-multi-let.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-jaccard-check-multi-let.plan
index 41c1583..3544334 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-jaccard-check-multi-let.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-jaccard-check-multi-let.plan
@@ -1,17 +1,34 @@
+distribute result [$$48]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$48])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$48] <- [{"Paper": $$55, "Query": array: [ "tra", "ran", "ans", "nsa", "sac", "act", "cti", "tio", "ion", "ons", "ns ", "s f", " fo", "for", "or ", "r c", " co", "coo", "oop", "ope", "per", "era", "rat", "ati", "tiv", "ive", "ve ", "e e", " en", "env", "nvi", "vir", "iro", "ron", "onm", "nme", "men", "ent", "nts" ]}]
       -- ASSIGN  |PARTITIONED|
+        select (get-item(similarity-jaccard-check($$55, array: [ "tra", "ran", "ans", "nsa", "sac", "act", "cti", "tio", "ion", "ons", "ns ", "s f", " fo", "for", "or ", "r c", " co", "coo", "oop", "ope", "per", "era", "rat", "ati", "tiv", "ive", "ve ", "e e", " en", "env", "nvi", "vir", "iro", "ron", "onm", "nme", "men", "ent", "nts" ], 0.5), 0))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$55])
           -- STREAM_PROJECT  |PARTITIONED|
+            assign [$$55] <- [gram-tokens($$paper.getField(2), 3, false)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$paper])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                  unnest-map [$$49, $$paper] <- index-search("DBLP", 0, "test", "DBLP", false, false, 1, $$54, 1, $$54, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$54)
                       -- STABLE_SORT [$$54(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                          unnest-map [$$54] <- index-search("ngram_index", 5, "test", "DBLP", false, false, 1, 0.5, 21, false, 1, $$53)
+                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              assign [$$53] <- [array: [ "tra", "ran", "ans", "nsa", "sac", "act", "cti", "tio", "ion", "ons", "ns ", "s f", " fo", "for", "or ", "r c", " co", "coo", "oop", "ope", "per", "era", "rat", "ati", "tiv", "ive", "ve ", "e e", " en", "env", "nvi", "vir", "iro", "ron", "onm", "nme", "men", "ent", "nts" ]]
                               -- ASSIGN  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/olist-edit-distance-check-let-panic.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/olist-edit-distance-check-let-panic.plan
index 251929c..084bb5e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/olist-edit-distance-check-let-panic.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/olist-edit-distance-check-let-panic.plan
@@ -1,9 +1,18 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$c])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- SORT_MERGE_EXCHANGE [$$27(ASC) ]  |PARTITIONED|
+        select (get-item(edit-distance-check($$c.getField(4), array: [ "computers", "wine", "walking" ], 3), 0))
         -- STREAM_SELECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+            data-scan []<-[$$27, $$c] <- test.Customers
+            -- DATASOURCE_SCAN  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                empty-tuple-source
                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/olist-edit-distance-check-let-panic_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/olist-edit-distance-check-let-panic_ps.plan
index 9b6e544..da8a269 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/olist-edit-distance-check-let-panic_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/olist-edit-distance-check-let-panic_ps.plan
@@ -1,28 +1,56 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$c])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$27)
         -- STABLE_SORT [$$27(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$27(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$32
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (get-item(edit-distance-check($$c.getField(4), array: [ "computers", "wine", "walking" ], 3), 0))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                        data-scan []<-[$$27, $$c] <- test.Customers
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$32] <- [agg-range-map($$30, $$31)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$30, $$31] <- [agg-local-sampling($$27), agg-null-writer($$27)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$27])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (get-item(edit-distance-check($$c.getField(4), array: [ "computers", "wine", "walking" ], 3), 0))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                  data-scan []<-[$$27, $$c] <- test.Customers
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/olist-edit-distance-check-let.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/olist-edit-distance-check-let.plan
index 4ab6ffa..0fe18eb 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/olist-edit-distance-check-let.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/olist-edit-distance-check-let.plan
@@ -1,14 +1,28 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$c])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- SORT_MERGE_EXCHANGE [$$27(ASC) ]  |PARTITIONED|
+        select (get-item(edit-distance-check($$c.getField(4), array: [ "computers", "wine", "walking" ], 1), 0))
         -- STREAM_SELECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+            unnest-map [$$27, $$c] <- index-search("Customers", 0, "test", "Customers", false, false, 1, $$31, 1, $$31, true, true, true)
+            -- BTREE_SEARCH  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (ASC, $$31)
                 -- STABLE_SORT [$$31(ASC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                    unnest-map [$$31] <- index-search("interests_index", 4, "test", "Customers", false, false, 2, 1, 21, false, 1, $$30)
+                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        assign [$$30] <- [array: [ "computers", "wine", "walking" ]]
                         -- ASSIGN  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/olist-edit-distance-check-let_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/olist-edit-distance-check-let_ps.plan
index bbd3d0a..c1f2826 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/olist-edit-distance-check-let_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/olist-edit-distance-check-let_ps.plan
@@ -1,38 +1,76 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$c])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$27)
         -- STABLE_SORT [$$27(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$27(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$34
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (get-item(edit-distance-check($$c.getField(4), array: [ "computers", "wine", "walking" ], 1), 0))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                        unnest-map [$$27, $$c] <- index-search("Customers", 0, "test", "Customers", false, false, 1, $$31, 1, $$31, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$31)
                             -- STABLE_SORT [$$31(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                unnest-map [$$31] <- index-search("interests_index", 4, "test", "Customers", false, false, 2, 1, 21, false, 1, $$30)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    assign [$$30] <- [array: [ "computers", "wine", "walking" ]]
                                     -- ASSIGN  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$34] <- [agg-range-map($$32, $$33)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$32, $$33] <- [agg-local-sampling($$27), agg-null-writer($$27)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$27])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (get-item(edit-distance-check($$c.getField(4), array: [ "computers", "wine", "walking" ], 1), 0))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                                  unnest-map [$$27, $$c] <- index-search("Customers", 0, "test", "Customers", false, false, 1, $$31, 1, $$31, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$31)
                                       -- STABLE_SORT [$$31(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                          unnest-map [$$31] <- index-search("interests_index", 4, "test", "Customers", false, false, 2, 1, 21, false, 1, $$30)
+                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$30] <- [array: [ "computers", "wine", "walking" ]]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/olist-jaccard-check-let.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/olist-jaccard-check-let.plan
index cc2976d..012ad3b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/olist-jaccard-check-let.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/olist-jaccard-check-let.plan
@@ -1,13 +1,26 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (get-item(similarity-jaccard-check($$c.getField(4), array: [ "databases", "computers", "wine" ], 0.7), 0))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$c])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+          unnest-map [$$26, $$c] <- index-search("Customers", 0, "test", "Customers", false, false, 1, $$29, 1, $$29, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$29)
               -- STABLE_SORT [$$29(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                  unnest-map [$$29] <- index-search("interests_index", 4, "test", "Customers", false, false, 1, 0.7, 21, false, 1, $$28)
+                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      assign [$$28] <- [array: [ "databases", "computers", "wine" ]]
                       -- ASSIGN  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ulist-jaccard-check-let.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ulist-jaccard-check-let.plan
index cc2976d..012ad3b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ulist-jaccard-check-let.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ulist-jaccard-check-let.plan
@@ -1,13 +1,26 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (get-item(similarity-jaccard-check($$c.getField(4), array: [ "databases", "computers", "wine" ], 0.7), 0))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$c])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+          unnest-map [$$26, $$c] <- index-search("Customers", 0, "test", "Customers", false, false, 1, $$29, 1, $$29, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$29)
               -- STABLE_SORT [$$29(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                  unnest-map [$$29] <- index-search("interests_index", 4, "test", "Customers", false, false, 1, 0.7, 21, false, 1, $$28)
+                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      assign [$$28] <- [array: [ "databases", "computers", "wine" ]]
                       -- ASSIGN  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/word-jaccard-check-let.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/word-jaccard-check-let.plan
index 2011066..b1a66cb 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/word-jaccard-check-let.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/word-jaccard-check-let.plan
@@ -1,13 +1,26 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (get-item(similarity-jaccard-check(word-tokens($$o.getField(2)), array: [ "transactions", "for", "cooperative", "environments" ], 0.5), 0))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$o])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+          unnest-map [$$27, $$o] <- index-search("DBLP", 0, "test", "DBLP", false, false, 1, $$30, 1, $$30, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$30)
               -- STABLE_SORT [$$30(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.keyword_index)  |PARTITIONED|
+                  unnest-map [$$30] <- index-search("keyword_index", 4, "test", "DBLP", false, false, 1, 0.5, 21, false, 1, $$29)
+                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      assign [$$29] <- [array: [ "transactions", "for", "cooperative", "environments" ]]
                       -- ASSIGN  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/word-jaccard-check-multi-let.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/word-jaccard-check-multi-let.plan
index 5c7a694..6f835cf 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/word-jaccard-check-multi-let.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/word-jaccard-check-multi-let.plan
@@ -1,17 +1,34 @@
+distribute result [$$48]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$48])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$48] <- [{"Paper": $$55, "Query": array: [ "transactions", "for", "cooperative", "environments" ]}]
       -- ASSIGN  |PARTITIONED|
+        select (get-item(similarity-jaccard-check($$55, array: [ "transactions", "for", "cooperative", "environments" ], 0.8), 0))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$55])
           -- STREAM_PROJECT  |PARTITIONED|
+            assign [$$55] <- [word-tokens($$paper.getField(2))]
             -- ASSIGN  |PARTITIONED|
+              project ([$$paper])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                  unnest-map [$$49, $$paper] <- index-search("DBLP", 0, "test", "DBLP", false, false, 1, $$54, 1, $$54, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$54)
                       -- STABLE_SORT [$$54(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.keyword_index)  |PARTITIONED|
+                          unnest-map [$$54] <- index-search("keyword_index", 4, "test", "DBLP", false, false, 1, 0.8, 21, false, 1, $$53)
+                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              assign [$$53] <- [array: [ "transactions", "for", "cooperative", "environments" ]]
                               -- ASSIGN  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join-noeqjoin/ngram-edit-distance-inline.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join-noeqjoin/ngram-edit-distance-inline.plan
index 3c96aca..c352057 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join-noeqjoin/ngram-edit-distance-inline.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join-noeqjoin/ngram-edit-distance-inline.plan
@@ -1,62 +1,124 @@
+distribute result [$$44]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    union ($$60, $$69, $$44)
     -- UNION_ALL  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$60])
         -- STREAM_PROJECT  |PARTITIONED|
+          assign [$$60] <- [{"aauthors": $$45, "bauthors": $$46, "ed": get-item($$78, 1)}]
           -- ASSIGN  |PARTITIONED|
+            project ([$$45, $$46, $$78])
             -- STREAM_PROJECT  |PARTITIONED|
+              select (and(get-item($$78, 0), lt($$47, $$48)))
               -- STREAM_SELECT  |PARTITIONED|
+                assign [$$78] <- [edit-distance-check($$45, $$46, 2)]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$47, $$45, $$48, $$46])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$46] <- [$$b.getField(3)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$47, $$45, $$48, $$b])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                          unnest-map [$$48, $$b] <- index-search("DBLP", 0, "test", "DBLP", true, false, 1, $$59, 1, $$59, true, true, true)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$59)
                               -- STABLE_SORT [$$59(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                                  unnest-map [$$59] <- index-search("ngram_index", 5, "test", "DBLP", true, true, 2, 2, 12, false, 1, $$45)
+                                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                      select (edit-distance-string-is-filterable($$45, 2, 3, true))
                                       -- STREAM_SELECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          replicate
                                           -- REPLICATE  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              replicate
                                               -- REPLICATE  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  project ([$$47, $$45])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    assign [$$45] <- [$$55.getField(3)]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                                        data-scan []<-[$$47, $$55] <- test.DBLP
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$69])
         -- STREAM_PROJECT  |PARTITIONED|
+          assign [$$69] <- [{"aauthors": $$45, "bauthors": $$56, "ed": get-item(edit-distance-check($$45, $$56, 2), 1)}]
           -- ASSIGN  |PARTITIONED|
+            project ([$$56, $$45])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                join (and(get-item(edit-distance-check($$45, $$56, 2), 0), lt($$47, $$58)))
                 -- NESTED_LOOP  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$58, $$56])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$58, $$56] <- [$$47, $$45]
                       -- ASSIGN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$47, $$45])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$45] <- [$$55.getField(3)]
                                 -- ASSIGN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                    data-scan []<-[$$47, $$55] <- test.DBLP
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    select (not(edit-distance-string-is-filterable($$45, 2, 3, true)))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        replicate
                         -- REPLICATE  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$47, $$45])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  assign [$$45] <- [$$55.getField(3)]
                                   -- ASSIGN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                      data-scan []<-[$$47, $$55] <- test.DBLP
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join-noeqjoin/ngram-fuzzyeq-edit-distance.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join-noeqjoin/ngram-fuzzyeq-edit-distance.plan
index 22ebacb..b988e4e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join-noeqjoin/ngram-fuzzyeq-edit-distance.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join-noeqjoin/ngram-fuzzyeq-edit-distance.plan
@@ -1,52 +1,104 @@
+distribute result [$$33]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    union ($$48, $$57, $$33)
     -- UNION_ALL  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$48])
         -- STREAM_PROJECT  |PARTITIONED|
+          assign [$$48] <- [{"aauthors": $$34, "bauthors": $$35}]
           -- ASSIGN  |PARTITIONED|
+            project ([$$34, $$35])
             -- STREAM_PROJECT  |PARTITIONED|
+              select (and(get-item(edit-distance-check($$34, $$35, 3), 0), lt($$36, $$37)))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$36, $$34, $$37, $$35])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$35] <- [$$b.getField(3)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$36, $$34, $$37, $$b])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.CSX.CSX)  |PARTITIONED|
+                        unnest-map [$$37, $$b] <- index-search("CSX", 0, "test", "CSX", true, false, 1, $$47, 1, $$47, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$47)
                             -- STABLE_SORT [$$47(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.CSX.ngram_index)  |PARTITIONED|
+                                unnest-map [$$47] <- index-search("ngram_index", 5, "test", "CSX", true, true, 2, 3, 12, false, 1, $$34)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    select (edit-distance-string-is-filterable($$34, 3, 3, true))
                                     -- STREAM_SELECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        replicate
                                         -- REPLICATE  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$36, $$34])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$34] <- [$$43.getField(3)]
                                               -- ASSIGN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                                  data-scan []<-[$$36, $$43] <- test.DBLP
+                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$57])
         -- STREAM_PROJECT  |PARTITIONED|
+          assign [$$57] <- [{"aauthors": $$34, "bauthors": $$44}]
           -- ASSIGN  |PARTITIONED|
+            project ([$$44, $$34])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                join (and(get-item(edit-distance-check($$34, $$44, 3), 0), lt($$36, $$46)))
                 -- NESTED_LOOP  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$46, $$44])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$44] <- [$$45.getField(3)]
                       -- ASSIGN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (test.CSX)  |PARTITIONED|
+                          data-scan []<-[$$46, $$45] <- test.CSX
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    select (not(edit-distance-string-is-filterable($$34, 3, 3, true)))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        replicate
                         -- REPLICATE  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$36, $$34])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$34] <- [$$43.getField(3)]
                               -- ASSIGN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                  data-scan []<-[$$36, $$43] <- test.DBLP
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join-noeqjoin/ngram-jaccard-inline.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join-noeqjoin/ngram-jaccard-inline.plan
index bbc5404..977e23c 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join-noeqjoin/ngram-jaccard-inline.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join-noeqjoin/ngram-jaccard-inline.plan
@@ -1,34 +1,68 @@
+distribute result [$$46]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$46])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$46] <- [{"atitle": $$47, "btitle": $$48, "jacc": get-item(similarity-jaccard-check(gram-tokens($$47, 3, false), $$53, 0.5), 1)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$47, $$48, $$53])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$58, $$49))
             -- HYBRID_HASH_JOIN [$$58][$$49]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$47, $$58])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$47] <- [$$a.getField(2)]
                   -- ASSIGN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                      data-scan []<-[$$58, $$a] <- test.DBLP
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$49]  |PARTITIONED|
+                project ([$$48, $$53, $$49])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(get-item(similarity-jaccard-check($$52, $$53, 0.5), 0), lt($$49, $$50)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    assign [$$53] <- [gram-tokens($$48, 3, false)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$49, $$52, $$50, $$48])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$48] <- [$$b.getField(2)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$49, $$52, $$50, $$b])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                              unnest-map [$$50, $$b] <- index-search("DBLP", 0, "test", "DBLP", true, false, 1, $$61, 1, $$61, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  order (ASC, $$61)
                                   -- STABLE_SORT [$$61(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                                      unnest-map [$$61] <- index-search("ngram_index", 5, "test", "DBLP", true, true, 1, 0.5, 21, false, 1, $$52)
+                                      -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                          project ([$$49, $$52])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$52] <- [gram-tokens($$60.getField(2), 3, false)]
                                             -- ASSIGN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                                data-scan []<-[$$49, $$60] <- test.DBLP
+                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join-noeqjoin/olist-edit-distance-inline.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join-noeqjoin/olist-edit-distance-inline.plan
index 5897e1f..40263fb 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join-noeqjoin/olist-edit-distance-inline.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join-noeqjoin/olist-edit-distance-inline.plan
@@ -1,62 +1,124 @@
+distribute result [$$44]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    union ($$60, $$69, $$44)
     -- UNION_ALL  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$60])
         -- STREAM_PROJECT  |PARTITIONED|
+          assign [$$60] <- [{"ainterests": $$45, "binterests": $$46, "ed": get-item($$78, 1)}]
           -- ASSIGN  |PARTITIONED|
+            project ([$$45, $$46, $$78])
             -- STREAM_PROJECT  |PARTITIONED|
+              select (and(get-item($$78, 0), lt($$47, $$48)))
               -- STREAM_SELECT  |PARTITIONED|
+                assign [$$78] <- [edit-distance-check($$45, $$46, 2)]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$47, $$45, $$48, $$46])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$46] <- [$$b.getField(4)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$47, $$45, $$48, $$b])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                          unnest-map [$$48, $$b] <- index-search("Customers", 0, "test", "Customers", true, false, 1, $$59, 1, $$59, true, true, true)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$59)
                               -- STABLE_SORT [$$59(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                  unnest-map [$$59] <- index-search("interests_index", 4, "test", "Customers", true, true, 2, 2, 21, false, 1, $$45)
+                                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                      select (edit-distance-list-is-filterable($$45, 2))
                                       -- STREAM_SELECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          replicate
                                           -- REPLICATE  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              replicate
                                               -- REPLICATE  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  project ([$$47, $$45])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    assign [$$45] <- [$$55.getField(4)]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                                        data-scan []<-[$$47, $$55] <- test.Customers
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$69])
         -- STREAM_PROJECT  |PARTITIONED|
+          assign [$$69] <- [{"ainterests": $$45, "binterests": $$56, "ed": get-item(edit-distance-check($$45, $$56, 2), 1)}]
           -- ASSIGN  |PARTITIONED|
+            project ([$$56, $$45])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                join (and(get-item(edit-distance-check($$45, $$56, 2), 0), lt($$47, $$58)))
                 -- NESTED_LOOP  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$58, $$56])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$58, $$56] <- [$$47, $$45]
                       -- ASSIGN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$47, $$45])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$45] <- [$$55.getField(4)]
                                 -- ASSIGN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                    data-scan []<-[$$47, $$55] <- test.Customers
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    select (not(edit-distance-list-is-filterable($$45, 2)))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        replicate
                         -- REPLICATE  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$47, $$45])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  assign [$$45] <- [$$55.getField(4)]
                                   -- ASSIGN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                      data-scan []<-[$$47, $$55] <- test.Customers
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join-noeqjoin/olist-jaccard-inline.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join-noeqjoin/olist-jaccard-inline.plan
index 66420f6..1a59489 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join-noeqjoin/olist-jaccard-inline.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join-noeqjoin/olist-jaccard-inline.plan
@@ -1,23 +1,46 @@
+distribute result [$$44]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$44])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$44] <- [{"ainterests": $$45, "binterests": $$46, "jacc": get-item($$57, 1)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$45, $$46, $$57])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and(get-item($$57, 0), lt($$47, $$48)))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$57] <- [similarity-jaccard-check($$45, $$46, 0.7)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$47, $$45, $$48, $$46])
               -- STREAM_PROJECT  |PARTITIONED|
+                assign [$$46] <- [$$b.getField(4)]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$47, $$45, $$48, $$b])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                      unnest-map [$$48, $$b] <- index-search("Customers", 0, "test", "Customers", true, false, 1, $$56, 1, $$56, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$56)
                           -- STABLE_SORT [$$56(ASC)]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                              unnest-map [$$56] <- index-search("interests_index", 4, "test", "Customers", true, true, 1, 0.7, 21, false, 1, $$45)
+                              -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                exchange
                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                  project ([$$47, $$45])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$45] <- [$$55.getField(4)]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                        data-scan []<-[$$47, $$55] <- test.Customers
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join-noeqjoin/ulist-jaccard-inline.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join-noeqjoin/ulist-jaccard-inline.plan
index 66420f6..3b7cfab 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join-noeqjoin/ulist-jaccard-inline.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join-noeqjoin/ulist-jaccard-inline.plan
@@ -1,23 +1,46 @@
+distribute result [$$44]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$44])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$44] <- [{"ainterests": $$45, "binterests": $$46, "jacc": get-item($$57, 1)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$45, $$46, $$57])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and(get-item($$57, 0), lt($$47, $$48)))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$57] <- [similarity-jaccard-check($$45, $$46, 0.7)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$47, $$45, $$48, $$46])
               -- STREAM_PROJECT  |PARTITIONED|
+                assign [$$46] <- [$$b.getField(4)]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$47, $$45, $$48, $$b])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                      unnest-map [$$48, $$b] <- index-search("Customers", 0, "test", "Customers", true, false, 1, $$56, 1, $$56, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$56)
                           -- STABLE_SORT [$$56(ASC)]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                              unnest-map [$$56] <- index-search("interests_index", 4, "test", "Customers", true, true, 1, 0.7, 22, false, 1, $$45)
+                              -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                exchange
                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                  project ([$$47, $$45])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$45] <- [$$55.getField(4)]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                        data-scan []<-[$$47, $$55] <- test.Customers
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join-noeqjoin/word-jaccard-inline.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join-noeqjoin/word-jaccard-inline.plan
index df95f20..ba58b65 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join-noeqjoin/word-jaccard-inline.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join-noeqjoin/word-jaccard-inline.plan
@@ -1,34 +1,68 @@
+distribute result [$$46]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$46])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$46] <- [{"atitle": $$47, "btitle": $$48, "jacc": get-item(similarity-jaccard-check(word-tokens($$47), $$53, 0.5), 1)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$47, $$48, $$53])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$58, $$49))
             -- HYBRID_HASH_JOIN [$$58][$$49]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$47, $$58])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$47] <- [$$a.getField(2)]
                   -- ASSIGN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                      data-scan []<-[$$58, $$a] <- test.DBLP
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$49]  |PARTITIONED|
+                project ([$$48, $$53, $$49])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(get-item(similarity-jaccard-check($$52, $$53, 0.5), 0), lt($$49, $$50)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    assign [$$53] <- [word-tokens($$48)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$49, $$52, $$50, $$48])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$48] <- [$$b.getField(2)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$49, $$52, $$50, $$b])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                              unnest-map [$$50, $$b] <- index-search("DBLP", 0, "test", "DBLP", true, false, 1, $$61, 1, $$61, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  order (ASC, $$61)
                                   -- STABLE_SORT [$$61(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.keyword_index)  |PARTITIONED|
+                                      unnest-map [$$61] <- index-search("keyword_index", 4, "test", "DBLP", true, true, 1, 0.5, 21, false, 1, $$52)
+                                      -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                          project ([$$49, $$52])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$52] <- [word-tokens($$60.getField(2))]
                                             -- ASSIGN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                                data-scan []<-[$$49, $$60] <- test.DBLP
+                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/issue741.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/issue741.plan
index 38e2902..67ca6a6 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/issue741.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/issue741.plan
@@ -1,45 +1,87 @@
+distribute result [$$55]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$55])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$55] <- [{"tweet": $$65, "similar-tweets": $$54}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- PRE_CLUSTERED_GROUP_BY[$$57]  |PARTITIONED|
-                  {
+          group by ([$$65 := $$57]) decor ([]) {
+                    aggregate [$$54] <- [listify($$58)]
                     -- AGGREGATE  |LOCAL|
+                      select (not(is-missing($$58)))
                       -- STREAM_SELECT  |LOCAL|
+                        nested tuple source
                         -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- PRE_CLUSTERED_GROUP_BY[$$57]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$57)
               -- STABLE_SORT [$$57(ASC)]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$57]  |PARTITIONED|
+                  project ([$$58, $$57])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (eq($$68, $$57))
                       -- HYBRID_HASH_JOIN [$$68][$$57]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$68])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            select (and(ge($$56, datetime: { 2011-06-18T14:10:17.000 }), lt($$56, datetime: { 2011-06-18T15:10:17.000 })))
                             -- STREAM_SELECT  |PARTITIONED|
+                              project ([$$68, $$56])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$56] <- [$$t.getField(3)]
                                 -- ASSIGN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (test.TweetMessages)  |PARTITIONED|
+                                    data-scan []<-[$$68, $$t] <- test.TweetMessages
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$57]  |PARTITIONED|
+                          project ([$$58, $$57])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            select (and(neq($$58, $$57), get-item(similarity-jaccard-check($$61, $$t2.getField(4), 0.6), 0))) retain-untrue ($$58 <- MISSING)
                             -- STREAM_SELECT  |PARTITIONED|
+                              project ([$$57, $$61, $$58, $$t2])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                  left-outer-unnest-map [$$58, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$71, 1, $$71, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$71)
                                       -- STABLE_SORT [$$71(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.TweetMessages.topicIIx)  |PARTITIONED|
+                                          left-outer-unnest-map [$$71] <- index-search("topicIIx", 4, "test", "TweetMessages", true, true, 1, 0.6, 22, false, 1, $$61)
+                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                              project ([$$57, $$61])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                select (and(ge($$69, datetime: { 2011-06-18T14:10:17.000 }), lt($$69, datetime: { 2011-06-18T15:10:17.000 })))
                                                 -- STREAM_SELECT  |PARTITIONED|
+                                                  project ([$$57, $$61, $$69])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    assign [$$61, $$69] <- [$$70.getField(4), $$70.getField(3)]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.TweetMessages)  |PARTITIONED|
+                                                        data-scan []<-[$$57, $$70] <- test.TweetMessages
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01.plan
index a49ca8f..8151e1c 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01.plan
@@ -1,78 +1,153 @@
+distribute result [$$56]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$56])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$56] <- [{"tweet": {"id": $$69, "topics": $$64}, "similar-tweets": $$55}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$69(ASC) ]  |PARTITIONED|
-          -- PRE_CLUSTERED_GROUP_BY[$$59]  |PARTITIONED|
-                  {
+          group by ([$$69 := $$59]) decor ([$$64]) {
+                    aggregate [$$55] <- [listify({"id": $$60, "topics": $$62})]
                     -- AGGREGATE  |LOCAL|
+                      select (not(is-missing($$60)))
                       -- STREAM_SELECT  |LOCAL|
+                        nested tuple source
                         -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- PRE_CLUSTERED_GROUP_BY[$$59]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$59) (ASC, $$60)
               -- STABLE_SORT [$$59(ASC), $$60(ASC)]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$59]  |PARTITIONED|
+                  project ([$$64, $$60, $$62, $$59])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (eq($$75, $$59))
                       -- HYBRID_HASH_JOIN [$$75][$$59]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$75])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$75, $$t1] <- [$$59, $$76]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                replicate
                                 -- REPLICATE  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                    unnest-map [$$59, $$76] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$77, 0, false, true, false)
+                                    -- BTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        assign [$$77] <- [240]
                                         -- ASSIGN  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$59]  |PARTITIONED|
+                          union ($$60, $$82, $$60) ($$62, $$80, $$62) ($$59, $$59, $$59) ($$64, $$64, $$64)
                           -- UNION_ALL  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$60, $$62, $$59, $$64])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                select (and(neq($$60, $$59), get-item(edit-distance-check($$64, $$62, 7), 0))) retain-untrue ($$60 <- MISSING)
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  project ([$$59, $$64, $$60, $$62])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$62] <- [$$t2.getField(5)]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$59, $$64, $$60, $$t2])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                          left-outer-unnest-map [$$60, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$83, 1, $$83, true, true, true)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              order (ASC, $$83)
                                               -- STABLE_SORT [$$83(ASC)]  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.TweetMessages.msgNgramIx)  |PARTITIONED|
+                                                  left-outer-unnest-map [$$83] <- index-search("msgNgramIx", 5, "test", "TweetMessages", true, true, 2, 7, 12, false, 1, $$64)
+                                                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                                    exchange
                                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                      select (edit-distance-string-is-filterable($$64, 7, 3, true))
                                                       -- STREAM_SELECT  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          replicate
                                                           -- REPLICATE  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              project ([$$59, $$64])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$64] <- [$$76.getField(5)]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    replicate
                                                                     -- REPLICATE  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                        unnest-map [$$59, $$76] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$77, 0, false, true, false)
+                                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            assign [$$77] <- [240]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              empty-tuple-source
                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              left outer join (and(neq($$82, $$59), get-item(edit-distance-check($$64, $$80, 7), 0)))
                               -- NESTED_LOOP  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$82, $$80])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$80] <- [$$81.getField(5)]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (test.TweetMessages)  |PARTITIONED|
+                                        data-scan []<-[$$82, $$81] <- test.TweetMessages
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                exchange
                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                  select (not(edit-distance-string-is-filterable($$64, 7, 3, true)))
                                   -- STREAM_SELECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      replicate
                                       -- REPLICATE  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$59, $$64])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$64] <- [$$76.getField(5)]
                                             -- ASSIGN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                replicate
                                                 -- REPLICATE  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                    unnest-map [$$59, $$76] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$77, 0, false, true, false)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        assign [$$77] <- [240]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01_ps.plan
index acca388..e23f8db 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01_ps.plan
@@ -1,165 +1,324 @@
+distribute result [$$56]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$56])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$56] <- [{"tweet": {"id": $$69, "topics": $$64}, "similar-tweets": $$55}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$69)
           -- STABLE_SORT [$$69(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$69(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$86
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- PRE_CLUSTERED_GROUP_BY[$$59]  |PARTITIONED|
-                              {
+                      group by ([$$69 := $$59]) decor ([$$64]) {
+                                aggregate [$$55] <- [listify({"id": $$60, "topics": $$62})]
                                 -- AGGREGATE  |LOCAL|
+                                  select (not(is-missing($$60)))
                                   -- STREAM_SELECT  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- PRE_CLUSTERED_GROUP_BY[$$59]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$59) (ASC, $$60)
                           -- STABLE_SORT [$$59(ASC), $$60(ASC)]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$59]  |PARTITIONED|
+                              project ([$$64, $$60, $$62, $$59])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  join (eq($$75, $$59))
                                   -- HYBRID_HASH_JOIN [$$75][$$59]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$75])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$75, $$t1] <- [$$59, $$76]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                unnest-map [$$59, $$76] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$77, 0, false, true, false)
+                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    assign [$$77] <- [240]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$59]  |PARTITIONED|
+                                      union ($$60, $$82, $$60) ($$62, $$80, $$62) ($$59, $$59, $$59) ($$64, $$64, $$64)
                                       -- UNION_ALL  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$60, $$62, $$59, $$64])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            select (and(neq($$60, $$59), get-item(edit-distance-check($$64, $$62, 7), 0))) retain-untrue ($$60 <- MISSING)
                                             -- STREAM_SELECT  |PARTITIONED|
+                                              project ([$$59, $$64, $$60, $$62])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$62] <- [$$t2.getField(5)]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  project ([$$59, $$64, $$60, $$t2])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                      left-outer-unnest-map [$$60, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$83, 1, $$83, true, true, true)
+                                                      -- BTREE_SEARCH  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          order (ASC, $$83)
                                                           -- STABLE_SORT [$$83(ASC)]  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.TweetMessages.msgNgramIx)  |PARTITIONED|
+                                                              left-outer-unnest-map [$$83] <- index-search("msgNgramIx", 5, "test", "TweetMessages", true, true, 2, 7, 12, false, 1, $$64)
+                                                              -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                                                exchange
                                                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                  select (edit-distance-string-is-filterable($$64, 7, 3, true))
                                                                   -- STREAM_SELECT  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      replicate
                                                                       -- REPLICATE  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          project ([$$59, $$64])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            assign [$$64] <- [$$76.getField(5)]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                replicate
                                                                                 -- REPLICATE  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                    -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                                    unnest-map [$$59, $$76] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$77, 0, false, true, false)
+                                                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                        assign [$$77] <- [240]
                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                          empty-tuple-source
                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          left outer join (and(neq($$82, $$59), get-item(edit-distance-check($$64, $$80, 7), 0)))
                                           -- NESTED_LOOP  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$82, $$80])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$80] <- [$$81.getField(5)]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (test.TweetMessages)  |PARTITIONED|
+                                                    data-scan []<-[$$82, $$81] <- test.TweetMessages
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                            exchange
                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                              select (not(edit-distance-string-is-filterable($$64, 7, 3, true)))
                                               -- STREAM_SELECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  replicate
                                                   -- REPLICATE  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      project ([$$59, $$64])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$64] <- [$$76.getField(5)]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            replicate
                                                             -- REPLICATE  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                unnest-map [$$59, $$76] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$77, 0, false, true, false)
+                                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    assign [$$77] <- [240]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      empty-tuple-source
                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$86] <- [agg-range-map($$84, $$85)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$84, $$85] <- [agg-local-sampling($$69), agg-null-writer($$69)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$69])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- PRE_CLUSTERED_GROUP_BY[$$59]  |PARTITIONED|
-                                        {
+                                group by ([$$69 := $$59]) decor ([$$64]) {
+                                          aggregate [$$55] <- [listify({"id": $$60, "topics": $$62})]
                                           -- AGGREGATE  |LOCAL|
+                                            select (not(is-missing($$60)))
                                             -- STREAM_SELECT  |LOCAL|
+                                              nested tuple source
                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- PRE_CLUSTERED_GROUP_BY[$$59]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$59) (ASC, $$60)
                                     -- STABLE_SORT [$$59(ASC), $$60(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$59]  |PARTITIONED|
+                                        project ([$$64, $$60, $$62, $$59])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            join (eq($$75, $$59))
                                             -- HYBRID_HASH_JOIN [$$75][$$59]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$75])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$75, $$t1] <- [$$59, $$76]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      replicate
                                                       -- REPLICATE  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                          unnest-map [$$59, $$76] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$77, 0, false, true, false)
+                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              assign [$$77] <- [240]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                empty-tuple-source
                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                              exchange
                                               -- HASH_PARTITION_EXCHANGE [$$59]  |PARTITIONED|
+                                                union ($$60, $$82, $$60) ($$62, $$80, $$62) ($$59, $$59, $$59) ($$64, $$64, $$64)
                                                 -- UNION_ALL  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$$60, $$62, $$59, $$64])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      select (and(neq($$60, $$59), get-item(edit-distance-check($$64, $$62, 7), 0))) retain-untrue ($$60 <- MISSING)
                                                       -- STREAM_SELECT  |PARTITIONED|
+                                                        project ([$$59, $$64, $$60, $$62])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$62] <- [$$t2.getField(5)]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            project ([$$59, $$64, $$60, $$t2])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                left-outer-unnest-map [$$60, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$83, 1, $$83, true, true, true)
+                                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    order (ASC, $$83)
                                                                     -- STABLE_SORT [$$83(ASC)]  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                        -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.TweetMessages.msgNgramIx)  |PARTITIONED|
+                                                                        left-outer-unnest-map [$$83] <- index-search("msgNgramIx", 5, "test", "TweetMessages", true, true, 2, 7, 12, false, 1, $$64)
+                                                                        -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                                                          exchange
                                                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                            select (edit-distance-string-is-filterable($$64, 7, 3, true))
                                                                             -- STREAM_SELECT  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                replicate
                                                                                 -- REPLICATE  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    project ([$$59, $$64])
                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                      assign [$$64] <- [$$76.getField(5)]
                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                        exchange
                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                          replicate
                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                            exchange
                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                              -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                                              unnest-map [$$59, $$76] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$77, 0, false, true, false)
+                                                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                                                exchange
                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                  assign [$$77] <- [240]
                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                    empty-tuple-source
                                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    left outer join (and(neq($$82, $$59), get-item(edit-distance-check($$64, $$80, 7), 0)))
                                                     -- NESTED_LOOP  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        project ([$$82, $$80])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$80] <- [$$81.getField(5)]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- DATASOURCE_SCAN (test.TweetMessages)  |PARTITIONED|
+                                                              data-scan []<-[$$82, $$81] <- test.TweetMessages
+                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  empty-tuple-source
                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                      exchange
                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                        select (not(edit-distance-string-is-filterable($$64, 7, 3, true)))
                                                         -- STREAM_SELECT  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            replicate
                                                             -- REPLICATE  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                project ([$$59, $$64])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  assign [$$64] <- [$$76.getField(5)]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      replicate
                                                                       -- REPLICATE  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                          -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                          unnest-map [$$59, $$76] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$77, 0, false, true, false)
+                                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              assign [$$77] <- [240]
                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                empty-tuple-source
                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/leftouterjoin-probe-pidx-with-join-jaccard-check-idx_01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/leftouterjoin-probe-pidx-with-join-jaccard-check-idx_01.plan
index a0c5597..56571d3 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/leftouterjoin-probe-pidx-with-join-jaccard-check-idx_01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/leftouterjoin-probe-pidx-with-join-jaccard-check-idx_01.plan
@@ -1,48 +1,93 @@
+distribute result [$$56]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$56])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$56] <- [{"tweet": {"id": $$69, "topics": $$64}, "similar-tweets": $$55}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$69(ASC) ]  |PARTITIONED|
-          -- PRE_CLUSTERED_GROUP_BY[$$59]  |PARTITIONED|
-                  {
+          group by ([$$69 := $$59]) decor ([$$64]) {
+                    aggregate [$$55] <- [listify({"id": $$60, "topics": $$62})]
                     -- AGGREGATE  |LOCAL|
+                      select (not(is-missing($$60)))
                       -- STREAM_SELECT  |LOCAL|
+                        nested tuple source
                         -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- PRE_CLUSTERED_GROUP_BY[$$59]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$59) (ASC, $$60)
               -- STABLE_SORT [$$59(ASC), $$60(ASC)]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$59]  |PARTITIONED|
+                  project ([$$64, $$60, $$62, $$59])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (eq($$75, $$59))
                       -- HYBRID_HASH_JOIN [$$75][$$59]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$75])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$75, $$t1] <- [$$59, $$76]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                replicate
                                 -- REPLICATE  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                    unnest-map [$$59, $$76] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$77, 0, false, true, false)
+                                    -- BTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        assign [$$77] <- [240]
                                         -- ASSIGN  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$59]  |PARTITIONED|
+                          select (and(neq($$60, $$59), get-item(similarity-jaccard-check($$64, $$62, 0.5), 0))) retain-untrue ($$60 <- MISSING)
                           -- STREAM_SELECT  |PARTITIONED|
+                            project ([$$59, $$64, $$60, $$62])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$62] <- [$$t2.getField(4)]
                               -- ASSIGN  |PARTITIONED|
+                                project ([$$59, $$64, $$60, $$t2])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                    left-outer-unnest-map [$$60, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$79, 1, $$79, true, true, true)
+                                    -- BTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        order (ASC, $$79)
                                         -- STABLE_SORT [$$79(ASC)]  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.TweetMessages.topicKeywordIx)  |PARTITIONED|
+                                            left-outer-unnest-map [$$79] <- index-search("topicKeywordIx", 4, "test", "TweetMessages", true, true, 1, 0.5, 22, false, 1, $$64)
+                                            -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                project ([$$59, $$64])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$64] <- [$$76.getField(4)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      replicate
                                                       -- REPLICATE  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                          unnest-map [$$59, $$76] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$77, 0, false, true, false)
+                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              assign [$$77] <- [240]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                empty-tuple-source
                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/leftouterjoin-probe-pidx-with-join-jaccard-check-idx_01_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/leftouterjoin-probe-pidx-with-join-jaccard-check-idx_01_ps.plan
index 0151e1f..71ab8cd 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/leftouterjoin-probe-pidx-with-join-jaccard-check-idx_01_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/leftouterjoin-probe-pidx-with-join-jaccard-check-idx_01_ps.plan
@@ -1,105 +1,204 @@
+distribute result [$$56]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$56])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$56] <- [{"tweet": {"id": $$69, "topics": $$64}, "similar-tweets": $$55}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$69)
           -- STABLE_SORT [$$69(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$69(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$82
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- PRE_CLUSTERED_GROUP_BY[$$59]  |PARTITIONED|
-                              {
+                      group by ([$$69 := $$59]) decor ([$$64]) {
+                                aggregate [$$55] <- [listify({"id": $$60, "topics": $$62})]
                                 -- AGGREGATE  |LOCAL|
+                                  select (not(is-missing($$60)))
                                   -- STREAM_SELECT  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- PRE_CLUSTERED_GROUP_BY[$$59]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$59) (ASC, $$60)
                           -- STABLE_SORT [$$59(ASC), $$60(ASC)]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$59]  |PARTITIONED|
+                              project ([$$64, $$60, $$62, $$59])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  join (eq($$75, $$59))
                                   -- HYBRID_HASH_JOIN [$$75][$$59]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$75])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$75, $$t1] <- [$$59, $$76]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                unnest-map [$$59, $$76] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$77, 0, false, true, false)
+                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    assign [$$77] <- [240]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$59]  |PARTITIONED|
+                                      select (and(neq($$60, $$59), get-item(similarity-jaccard-check($$64, $$62, 0.5), 0))) retain-untrue ($$60 <- MISSING)
                                       -- STREAM_SELECT  |PARTITIONED|
+                                        project ([$$59, $$64, $$60, $$62])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$62] <- [$$t2.getField(4)]
                                           -- ASSIGN  |PARTITIONED|
+                                            project ([$$59, $$64, $$60, $$t2])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                left-outer-unnest-map [$$60, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$79, 1, $$79, true, true, true)
+                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    order (ASC, $$79)
                                                     -- STABLE_SORT [$$79(ASC)]  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.TweetMessages.topicKeywordIx)  |PARTITIONED|
+                                                        left-outer-unnest-map [$$79] <- index-search("topicKeywordIx", 4, "test", "TweetMessages", true, true, 1, 0.5, 22, false, 1, $$64)
+                                                        -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                                          exchange
                                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                            project ([$$59, $$64])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$64] <- [$$76.getField(4)]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  replicate
                                                                   -- REPLICATE  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                      unnest-map [$$59, $$76] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$77, 0, false, true, false)
+                                                                      -- BTREE_SEARCH  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          assign [$$77] <- [240]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            empty-tuple-source
                                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$82] <- [agg-range-map($$80, $$81)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$80, $$81] <- [agg-local-sampling($$69), agg-null-writer($$69)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$69])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- PRE_CLUSTERED_GROUP_BY[$$59]  |PARTITIONED|
-                                        {
+                                group by ([$$69 := $$59]) decor ([$$64]) {
+                                          aggregate [$$55] <- [listify({"id": $$60, "topics": $$62})]
                                           -- AGGREGATE  |LOCAL|
+                                            select (not(is-missing($$60)))
                                             -- STREAM_SELECT  |LOCAL|
+                                              nested tuple source
                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- PRE_CLUSTERED_GROUP_BY[$$59]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$59) (ASC, $$60)
                                     -- STABLE_SORT [$$59(ASC), $$60(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$59]  |PARTITIONED|
+                                        project ([$$64, $$60, $$62, $$59])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            join (eq($$75, $$59))
                                             -- HYBRID_HASH_JOIN [$$75][$$59]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$75])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$75, $$t1] <- [$$59, $$76]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      replicate
                                                       -- REPLICATE  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                          unnest-map [$$59, $$76] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$77, 0, false, true, false)
+                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              assign [$$77] <- [240]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                empty-tuple-source
                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                              exchange
                                               -- HASH_PARTITION_EXCHANGE [$$59]  |PARTITIONED|
+                                                select (and(neq($$60, $$59), get-item(similarity-jaccard-check($$64, $$62, 0.5), 0))) retain-untrue ($$60 <- MISSING)
                                                 -- STREAM_SELECT  |PARTITIONED|
+                                                  project ([$$59, $$64, $$60, $$62])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    assign [$$62] <- [$$t2.getField(4)]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      project ([$$59, $$64, $$60, $$t2])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                          left-outer-unnest-map [$$60, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$79, 1, $$79, true, true, true)
+                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              order (ASC, $$79)
                                                               -- STABLE_SORT [$$79(ASC)]  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.TweetMessages.topicKeywordIx)  |PARTITIONED|
+                                                                  left-outer-unnest-map [$$79] <- index-search("topicKeywordIx", 4, "test", "TweetMessages", true, true, 1, 0.5, 22, false, 1, $$64)
+                                                                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                                                    exchange
                                                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                      project ([$$59, $$64])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        assign [$$64] <- [$$76.getField(4)]
                                                                         -- ASSIGN  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            replicate
                                                                             -- REPLICATE  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                                unnest-map [$$59, $$76] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$77, 0, false, true, false)
+                                                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    assign [$$77] <- [240]
                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                      empty-tuple-source
                                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-contains_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-contains_ps.plan
index b7351a2..5b11c06 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-contains_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-contains_ps.plan
@@ -1,54 +1,108 @@
+distribute result [$$33]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$33])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$33] <- [{"title1": $$36, "title2": $$37}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$36, $$37])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            order (ASC, $$38) (ASC, $$39)
             -- STABLE_SORT [$$38(ASC), $$39(ASC)]  |PARTITIONED|
+              exchange
               -- RANGE_PARTITION_EXCHANGE [$$38(ASC), $$39(ASC)]  |PARTITIONED|
+                forward: shared-variable = $$52
                 -- FORWARD  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        select (and(contains($$36, $$37), lt($$38, $$39)))
                         -- STREAM_SELECT  |PARTITIONED|
+                          project ([$$38, $$36, $$39, $$37])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$37] <- [$$o2.getField(2)]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$38, $$36, $$39, $$o2])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                                  unnest-map [$$39, $$o2] <- index-search("DBLP", 0, "test", "DBLP", true, false, 1, $$48, 1, $$48, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$48)
                                       -- STABLE_SORT [$$48(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                                          unnest-map [$$48] <- index-search("ngram_index", 5, "test", "DBLP", true, true, 0, missing, 12, false, 1, $$36)
+                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                              project ([$$38, $$36])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$36] <- [$$47.getField(2)]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                                    data-scan []<-[$$38, $$47] <- test.DBLP
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    aggregate [$$52] <- [agg-range-map($$49, $$50, $$51)]
                     -- AGGREGATE  |UNPARTITIONED|
+                      exchange
                       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                        aggregate [$$49, $$50, $$51] <- [agg-local-sampling($$38, $$39), agg-null-writer($$38), agg-null-writer($$39)]
                         -- AGGREGATE  |PARTITIONED|
+                          project ([$$38, $$39])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              replicate
                               -- REPLICATE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  select (and(contains($$36, $$37), lt($$38, $$39)))
                                   -- STREAM_SELECT  |PARTITIONED|
+                                    project ([$$38, $$36, $$39, $$37])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$37] <- [$$o2.getField(2)]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$38, $$36, $$39, $$o2])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                                            unnest-map [$$39, $$o2] <- index-search("DBLP", 0, "test", "DBLP", true, false, 1, $$48, 1, $$48, true, true, true)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                order (ASC, $$48)
                                                 -- STABLE_SORT [$$48(ASC)]  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                                                    unnest-map [$$48] <- index-search("ngram_index", 5, "test", "DBLP", true, true, 0, missing, 12, false, 1, $$36)
+                                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                        project ([$$38, $$36])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$36] <- [$$47.getField(2)]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                                              data-scan []<-[$$38, $$47] <- test.DBLP
+                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  empty-tuple-source
                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-edit-distance-check_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-edit-distance-check_02.plan
index 84bdda2..766b677 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-edit-distance-check_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-edit-distance-check_02.plan
@@ -1,55 +1,110 @@
+distribute result [$$32]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$32])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$32] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$41, $$33))
             -- HYBRID_HASH_JOIN [$$41][$$33]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                data-scan []<-[$$41, $$a] <- test.DBLP
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$33]  |PARTITIONED|
+                union ($$b, $$44, $$b) ($$33, $$33, $$33)
                 -- UNION_ALL  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$b, $$33])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      select (and(lt($$33, $$34), get-item(edit-distance-check($$37, $$b.getField(3), 3), 0)))
                       -- STREAM_SELECT  |PARTITIONED|
+                        project ([$$33, $$37, $$34, $$b])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.CSX.CSX)  |PARTITIONED|
+                            unnest-map [$$34, $$b] <- index-search("CSX", 0, "test", "CSX", true, false, 1, $$46, 1, $$46, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$46)
                                 -- STABLE_SORT [$$46(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.CSX.ngram_index)  |PARTITIONED|
+                                    unnest-map [$$46] <- index-search("ngram_index", 5, "test", "CSX", true, true, 2, 3, 12, false, 1, $$37)
+                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                        select (edit-distance-string-is-filterable($$37, 3, 3, true))
                                         -- STREAM_SELECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$33, $$37])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$37] <- [$$42.getField(3)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                                      data-scan []<-[$$33, $$42] <- test.DBLP
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$44, $$33])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        join (and(lt($$33, $$45), get-item(edit-distance-check($$37, $$43, 3), 0)))
                         -- NESTED_LOOP  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            assign [$$43] <- [$$44.getField(3)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.CSX)  |PARTITIONED|
+                                data-scan []<-[$$45, $$44] <- test.CSX
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                            select (not(edit-distance-string-is-filterable($$37, 3, 3, true)))
                             -- STREAM_SELECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                replicate
                                 -- REPLICATE  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$33, $$37])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$37] <- [$$42.getField(3)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                          data-scan []<-[$$33, $$42] <- test.DBLP
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-edit-distance-check_03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-edit-distance-check_03.plan
index eb0c5cb..e547c00 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-edit-distance-check_03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-edit-distance-check_03.plan
@@ -1,55 +1,110 @@
+distribute result [$$32]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$32])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$32] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$41, $$33))
             -- HYBRID_HASH_JOIN [$$41][$$33]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                data-scan []<-[$$41, $$a] <- test.DBLP
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$33]  |PARTITIONED|
+                union ($$b, $$44, $$b) ($$33, $$33, $$33)
                 -- UNION_ALL  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$b, $$33])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      select (and(lt($$33, $$34), get-item(edit-distance-check($$37, $$b.getField(3), 3), 0)))
                       -- STREAM_SELECT  |PARTITIONED|
+                        project ([$$33, $$37, $$34, $$b])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                            unnest-map [$$34, $$b] <- index-search("DBLP", 0, "test", "DBLP", true, false, 1, $$46, 1, $$46, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$46)
                                 -- STABLE_SORT [$$46(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                                    unnest-map [$$46] <- index-search("ngram_index", 5, "test", "DBLP", true, true, 2, 3, 12, false, 1, $$37)
+                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                        select (edit-distance-string-is-filterable($$37, 3, 3, true))
                                         -- STREAM_SELECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$33, $$37])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$37] <- [$$42.getField(3)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                                      data-scan []<-[$$33, $$42] <- test.DBLP
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$44, $$33])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        join (and(lt($$33, $$45), get-item(edit-distance-check($$37, $$43, 3), 0)))
                         -- NESTED_LOOP  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            assign [$$43] <- [$$44.getField(3)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                data-scan []<-[$$45, $$44] <- test.DBLP
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                            select (not(edit-distance-string-is-filterable($$37, 3, 3, true)))
                             -- STREAM_SELECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                replicate
                                 -- REPLICATE  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$33, $$37])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$37] <- [$$42.getField(3)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                          data-scan []<-[$$33, $$42] <- test.DBLP
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-edit-distance-check_04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-edit-distance-check_04.plan
index 3ebf17f..a997654 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-edit-distance-check_04.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-edit-distance-check_04.plan
@@ -1,59 +1,118 @@
+distribute result [$$43]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$43])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$43] <- [{"arec": $$a, "brec": $$b, "ed": get-item($$60, 1)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b, $$60])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$54, $$44))
             -- HYBRID_HASH_JOIN [$$54][$$44]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                data-scan []<-[$$54, $$a] <- test.DBLP
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$44]  |PARTITIONED|
+                union ($$b, $$57, $$b) ($$44, $$44, $$44) ($$79, $$70, $$60)
                 -- UNION_ALL  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$b, $$44, $$79])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      select (and(get-item($$79, 0), lt($$44, $$45)))
                       -- STREAM_SELECT  |PARTITIONED|
+                        project ([$$44, $$45, $$b, $$79])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$79] <- [edit-distance-check($$46, $$b.getField(3), 3)]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$44, $$46, $$45, $$b])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                                unnest-map [$$45, $$b] <- index-search("DBLP", 0, "test", "DBLP", true, false, 1, $$59, 1, $$59, true, true, true)
+                                -- BTREE_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$59)
                                     -- STABLE_SORT [$$59(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                                        unnest-map [$$59] <- index-search("ngram_index", 5, "test", "DBLP", true, true, 2, 3, 12, false, 1, $$46)
+                                        -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                            select (edit-distance-string-is-filterable($$46, 3, 3, true))
                                             -- STREAM_SELECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                replicate
                                                 -- REPLICATE  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$$44, $$46])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      assign [$$46] <- [$$55.getField(3)]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                                          data-scan []<-[$$44, $$55] <- test.DBLP
+                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              empty-tuple-source
                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$57, $$44, $$70])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$70] <- [edit-distance-check($$46, $$56, 3)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$57, $$56, $$44, $$46])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            join (and(get-item(edit-distance-check($$46, $$56, 3), 0), lt($$44, $$58)))
                             -- NESTED_LOOP  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                assign [$$56] <- [$$57.getField(3)]
                                 -- ASSIGN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                    data-scan []<-[$$58, $$57] <- test.DBLP
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                select (not(edit-distance-string-is-filterable($$46, 3, 3, true)))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    replicate
                                     -- REPLICATE  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$44, $$46])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$46] <- [$$55.getField(3)]
                                           -- ASSIGN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                              data-scan []<-[$$44, $$55] <- test.DBLP
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-edit-distance_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-edit-distance_02.plan
index 84bdda2..91a00a5 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-edit-distance_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-edit-distance_02.plan
@@ -1,55 +1,110 @@
+distribute result [$$32]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$32])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$32] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$41, $$33))
             -- HYBRID_HASH_JOIN [$$41][$$33]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                data-scan []<-[$$41, $$a] <- test.DBLP
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$33]  |PARTITIONED|
+                union ($$b, $$44, $$b) ($$33, $$33, $$33)
                 -- UNION_ALL  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$b, $$33])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      select (and(lt($$33, $$34), get-item(edit-distance-check($$37, $$b.getField(3), 2), 0)))
                       -- STREAM_SELECT  |PARTITIONED|
+                        project ([$$33, $$37, $$34, $$b])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.CSX.CSX)  |PARTITIONED|
+                            unnest-map [$$34, $$b] <- index-search("CSX", 0, "test", "CSX", true, false, 1, $$46, 1, $$46, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$46)
                                 -- STABLE_SORT [$$46(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.CSX.ngram_index)  |PARTITIONED|
+                                    unnest-map [$$46] <- index-search("ngram_index", 5, "test", "CSX", true, true, 2, 2, 12, false, 1, $$37)
+                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                        select (edit-distance-string-is-filterable($$37, 2, 3, true))
                                         -- STREAM_SELECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$33, $$37])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$37] <- [$$42.getField(3)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                                      data-scan []<-[$$33, $$42] <- test.DBLP
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$44, $$33])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        join (and(lt($$33, $$45), get-item(edit-distance-check($$37, $$43, 2), 0)))
                         -- NESTED_LOOP  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            assign [$$43] <- [$$44.getField(3)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.CSX)  |PARTITIONED|
+                                data-scan []<-[$$45, $$44] <- test.CSX
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                            select (not(edit-distance-string-is-filterable($$37, 2, 3, true)))
                             -- STREAM_SELECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                replicate
                                 -- REPLICATE  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$33, $$37])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$37] <- [$$42.getField(3)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                          data-scan []<-[$$33, $$42] <- test.DBLP
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-edit-distance_03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-edit-distance_03.plan
index eb0c5cb..f290700 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-edit-distance_03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-edit-distance_03.plan
@@ -1,55 +1,110 @@
+distribute result [$$32]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$32])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$32] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$41, $$33))
             -- HYBRID_HASH_JOIN [$$41][$$33]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                data-scan []<-[$$41, $$a] <- test.DBLP
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$33]  |PARTITIONED|
+                union ($$b, $$44, $$b) ($$33, $$33, $$33)
                 -- UNION_ALL  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$b, $$33])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      select (and(lt($$33, $$34), get-item(edit-distance-check($$37, $$b.getField(3), 2), 0)))
                       -- STREAM_SELECT  |PARTITIONED|
+                        project ([$$33, $$37, $$34, $$b])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                            unnest-map [$$34, $$b] <- index-search("DBLP", 0, "test", "DBLP", true, false, 1, $$46, 1, $$46, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$46)
                                 -- STABLE_SORT [$$46(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                                    unnest-map [$$46] <- index-search("ngram_index", 5, "test", "DBLP", true, true, 2, 2, 12, false, 1, $$37)
+                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                        select (edit-distance-string-is-filterable($$37, 2, 3, true))
                                         -- STREAM_SELECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$33, $$37])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$37] <- [$$42.getField(3)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                                      data-scan []<-[$$33, $$42] <- test.DBLP
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$44, $$33])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        join (and(lt($$33, $$45), get-item(edit-distance-check($$37, $$43, 2), 0)))
                         -- NESTED_LOOP  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            assign [$$43] <- [$$44.getField(3)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                data-scan []<-[$$45, $$44] <- test.DBLP
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                            select (not(edit-distance-string-is-filterable($$37, 2, 3, true)))
                             -- STREAM_SELECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                replicate
                                 -- REPLICATE  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$33, $$37])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$37] <- [$$42.getField(3)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                          data-scan []<-[$$33, $$42] <- test.DBLP
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-edit-distance_04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-edit-distance_04.plan
index 21ec002..4ad7ee2 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-edit-distance_04.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-edit-distance_04.plan
@@ -1,59 +1,118 @@
+distribute result [$$42]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$42])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$42] <- [{"arec": $$a, "brec": $$b, "ed": get-item($$60, 1)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b, $$60])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$54, $$43))
             -- HYBRID_HASH_JOIN [$$54][$$43]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                data-scan []<-[$$54, $$a] <- test.DBLP
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$43]  |PARTITIONED|
+                union ($$b, $$57, $$b) ($$43, $$43, $$43) ($$79, $$70, $$60)
                 -- UNION_ALL  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$b, $$43, $$79])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      select (and(get-item($$79, 0), lt($$43, $$44)))
                       -- STREAM_SELECT  |PARTITIONED|
+                        project ([$$43, $$44, $$b, $$79])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$79] <- [edit-distance-check($$46, $$b.getField(3), 2)]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$43, $$46, $$44, $$b])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                                unnest-map [$$44, $$b] <- index-search("DBLP", 0, "test", "DBLP", true, false, 1, $$59, 1, $$59, true, true, true)
+                                -- BTREE_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$59)
                                     -- STABLE_SORT [$$59(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                                        unnest-map [$$59] <- index-search("ngram_index", 5, "test", "DBLP", true, true, 2, 2, 12, false, 1, $$46)
+                                        -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                            select (edit-distance-string-is-filterable($$46, 2, 3, true))
                                             -- STREAM_SELECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                replicate
                                                 -- REPLICATE  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$$43, $$46])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      assign [$$46] <- [$$55.getField(3)]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                                          data-scan []<-[$$43, $$55] <- test.DBLP
+                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              empty-tuple-source
                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$57, $$43, $$70])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$70] <- [edit-distance-check($$46, $$56, 2)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$57, $$56, $$43, $$46])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            join (and(get-item(edit-distance-check($$46, $$56, 2), 0), lt($$43, $$58)))
                             -- NESTED_LOOP  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                assign [$$56] <- [$$57.getField(3)]
                                 -- ASSIGN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                    data-scan []<-[$$58, $$57] <- test.DBLP
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                select (not(edit-distance-string-is-filterable($$46, 2, 3, true)))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    replicate
                                     -- REPLICATE  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$43, $$46])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$46] <- [$$55.getField(3)]
                                           -- ASSIGN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                              data-scan []<-[$$43, $$55] <- test.DBLP
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-fuzzyeq-edit-distance_01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-fuzzyeq-edit-distance_01.plan
index fd02f50..7d83116 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-fuzzyeq-edit-distance_01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-fuzzyeq-edit-distance_01.plan
@@ -1,55 +1,110 @@
+distribute result [$$31]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$31])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$31] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$40, $$32))
             -- HYBRID_HASH_JOIN [$$40][$$32]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                data-scan []<-[$$40, $$a] <- test.DBLP
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$32]  |PARTITIONED|
+                union ($$b, $$43, $$b) ($$32, $$32, $$32)
                 -- UNION_ALL  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$b, $$32])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      select (and(lt($$32, $$33), get-item(edit-distance-check($$36, $$b.getField(3), 3), 0)))
                       -- STREAM_SELECT  |PARTITIONED|
+                        project ([$$32, $$36, $$33, $$b])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.CSX.CSX)  |PARTITIONED|
+                            unnest-map [$$33, $$b] <- index-search("CSX", 0, "test", "CSX", true, false, 1, $$45, 1, $$45, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$45)
                                 -- STABLE_SORT [$$45(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.CSX.ngram_index)  |PARTITIONED|
+                                    unnest-map [$$45] <- index-search("ngram_index", 5, "test", "CSX", true, true, 2, 3, 12, false, 1, $$36)
+                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                        select (edit-distance-string-is-filterable($$36, 3, 3, true))
                                         -- STREAM_SELECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$32, $$36])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$36] <- [$$41.getField(3)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                                      data-scan []<-[$$32, $$41] <- test.DBLP
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$43, $$32])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        join (and(lt($$32, $$44), get-item(edit-distance-check($$36, $$42, 3), 0)))
                         -- NESTED_LOOP  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            assign [$$42] <- [$$43.getField(3)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.CSX)  |PARTITIONED|
+                                data-scan []<-[$$44, $$43] <- test.CSX
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                            select (not(edit-distance-string-is-filterable($$36, 3, 3, true)))
                             -- STREAM_SELECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                replicate
                                 -- REPLICATE  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$32, $$36])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$36] <- [$$41.getField(3)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                          data-scan []<-[$$32, $$41] <- test.DBLP
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-fuzzyeq-edit-distance_03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-fuzzyeq-edit-distance_03.plan
index 0d31425..0b79baa 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-fuzzyeq-edit-distance_03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-fuzzyeq-edit-distance_03.plan
@@ -1,55 +1,110 @@
+distribute result [$$31]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$31])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$31] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$40, $$32))
             -- HYBRID_HASH_JOIN [$$40][$$32]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                data-scan []<-[$$40, $$a] <- test.DBLP
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$32]  |PARTITIONED|
+                union ($$b, $$43, $$b) ($$32, $$32, $$32)
                 -- UNION_ALL  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$b, $$32])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      select (and(lt($$32, $$33), get-item(edit-distance-check($$36, $$b.getField(3), 3), 0)))
                       -- STREAM_SELECT  |PARTITIONED|
+                        project ([$$32, $$36, $$33, $$b])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                            unnest-map [$$33, $$b] <- index-search("DBLP", 0, "test", "DBLP", true, false, 1, $$45, 1, $$45, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$45)
                                 -- STABLE_SORT [$$45(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                                    unnest-map [$$45] <- index-search("ngram_index", 5, "test", "DBLP", true, true, 2, 3, 12, false, 1, $$36)
+                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                        select (edit-distance-string-is-filterable($$36, 3, 3, true))
                                         -- STREAM_SELECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$32, $$36])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$36] <- [$$41.getField(3)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                                      data-scan []<-[$$32, $$41] <- test.DBLP
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$43, $$32])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        join (and(lt($$32, $$44), get-item(edit-distance-check($$36, $$42, 3), 0)))
                         -- NESTED_LOOP  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            assign [$$42] <- [$$43.getField(3)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                data-scan []<-[$$44, $$43] <- test.DBLP
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                            select (not(edit-distance-string-is-filterable($$36, 3, 3, true)))
                             -- STREAM_SELECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                replicate
                                 -- REPLICATE  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$32, $$36])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$36] <- [$$41.getField(3)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                          data-scan []<-[$$32, $$41] <- test.DBLP
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-fuzzyeq-jaccard_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-fuzzyeq-jaccard_02.plan
index 4231897..7d97167 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-fuzzyeq-jaccard_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-fuzzyeq-jaccard_02.plan
@@ -1,28 +1,56 @@
+distribute result [$$33]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$33])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$33] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$44, $$34))
             -- HYBRID_HASH_JOIN [$$44][$$34]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                data-scan []<-[$$44, $$a] <- test.DBLP
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$34]  |PARTITIONED|
+                project ([$$b, $$34])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(lt($$34, $$35), get-item(similarity-jaccard-check($$38, gram-tokens($$b.getField(2), 3, false), 0.5), 0)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$34, $$38, $$35, $$b])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.CSX.CSX)  |PARTITIONED|
+                        unnest-map [$$35, $$b] <- index-search("CSX", 0, "test", "CSX", true, false, 1, $$47, 1, $$47, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$47)
                             -- STABLE_SORT [$$47(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.CSX.ngram_index)  |PARTITIONED|
+                                unnest-map [$$47] <- index-search("ngram_index", 5, "test", "CSX", true, true, 1, 0.5, 21, false, 1, $$38)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    project ([$$34, $$38])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$38] <- [gram-tokens($$46.getField(2), 3, false)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                          data-scan []<-[$$34, $$46] <- test.DBLP
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-fuzzyeq-jaccard_03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-fuzzyeq-jaccard_03.plan
index 6993ea0..b25c67b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-fuzzyeq-jaccard_03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-fuzzyeq-jaccard_03.plan
@@ -1,28 +1,56 @@
+distribute result [$$33]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$33])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$33] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$44, $$34))
             -- HYBRID_HASH_JOIN [$$44][$$34]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                data-scan []<-[$$44, $$a] <- test.DBLP
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$34]  |PARTITIONED|
+                project ([$$b, $$34])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(lt($$34, $$35), get-item(similarity-jaccard-check($$38, gram-tokens($$b.getField(2), 3, false), 0.5), 0)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$34, $$38, $$35, $$b])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                        unnest-map [$$35, $$b] <- index-search("DBLP", 0, "test", "DBLP", true, false, 1, $$47, 1, $$47, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$47)
                             -- STABLE_SORT [$$47(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                                unnest-map [$$47] <- index-search("ngram_index", 5, "test", "DBLP", true, true, 1, 0.5, 21, false, 1, $$38)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    project ([$$34, $$38])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$38] <- [gram-tokens($$46.getField(2), 3, false)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                          data-scan []<-[$$34, $$46] <- test.DBLP
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-jaccard-check_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-jaccard-check_02.plan
index 25dffe2..ddbb7b6 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-jaccard-check_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-jaccard-check_02.plan
@@ -1,28 +1,56 @@
+distribute result [$$34]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$34])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$34] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$45, $$35))
             -- HYBRID_HASH_JOIN [$$45][$$35]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                data-scan []<-[$$45, $$a] <- test.DBLP
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$35]  |PARTITIONED|
+                project ([$$b, $$35])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(lt($$35, $$36), get-item(similarity-jaccard-check($$39, gram-tokens($$b.getField(2), 3, false), 0.5), 0)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$35, $$39, $$36, $$b])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.CSX.CSX)  |PARTITIONED|
+                        unnest-map [$$36, $$b] <- index-search("CSX", 0, "test", "CSX", true, false, 1, $$48, 1, $$48, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$48)
                             -- STABLE_SORT [$$48(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.CSX.ngram_index)  |PARTITIONED|
+                                unnest-map [$$48] <- index-search("ngram_index", 5, "test", "CSX", true, true, 1, 0.5, 21, false, 1, $$39)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    project ([$$35, $$39])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$39] <- [gram-tokens($$47.getField(2), 3, false)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                          data-scan []<-[$$35, $$47] <- test.DBLP
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-jaccard-check_03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-jaccard-check_03.plan
index 760eb13..4b07256 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-jaccard-check_03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-jaccard-check_03.plan
@@ -1,28 +1,56 @@
+distribute result [$$34]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$34])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$34] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$45, $$35))
             -- HYBRID_HASH_JOIN [$$45][$$35]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                data-scan []<-[$$45, $$a] <- test.DBLP
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$35]  |PARTITIONED|
+                project ([$$b, $$35])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(lt($$35, $$36), get-item(similarity-jaccard-check($$39, gram-tokens($$b.getField(2), 3, false), 0.5), 0)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$35, $$39, $$36, $$b])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                        unnest-map [$$36, $$b] <- index-search("DBLP", 0, "test", "DBLP", true, false, 1, $$48, 1, $$48, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$48)
                             -- STABLE_SORT [$$48(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                                unnest-map [$$48] <- index-search("ngram_index", 5, "test", "DBLP", true, true, 1, 0.5, 21, false, 1, $$39)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    project ([$$35, $$39])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$39] <- [gram-tokens($$47.getField(2), 3, false)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                          data-scan []<-[$$35, $$47] <- test.DBLP
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-jaccard-check_04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-jaccard-check_04.plan
index 69b1d36..8385fe6 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-jaccard-check_04.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-jaccard-check_04.plan
@@ -1,29 +1,58 @@
+distribute result [$$45]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$45])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$45] <- [{"arec": $$a, "brec": $$b, "jacc": get-item(similarity-jaccard-check(gram-tokens($$a.getField(2), 3, false), $$49, 0.5), 1)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b, $$49])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$58, $$46))
             -- HYBRID_HASH_JOIN [$$58][$$46]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                data-scan []<-[$$58, $$a] <- test.DBLP
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$46]  |PARTITIONED|
+                project ([$$b, $$49, $$46])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(get-item(similarity-jaccard-check($$48, $$49, 0.5), 0), lt($$46, $$47)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    assign [$$49] <- [gram-tokens($$b.getField(2), 3, false)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$46, $$48, $$47, $$b])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                          unnest-map [$$47, $$b] <- index-search("DBLP", 0, "test", "DBLP", true, false, 1, $$61, 1, $$61, true, true, true)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$61)
                               -- STABLE_SORT [$$61(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                                  unnest-map [$$61] <- index-search("ngram_index", 5, "test", "DBLP", true, true, 1, 0.5, 21, false, 1, $$48)
+                                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                      project ([$$46, $$48])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$48] <- [gram-tokens($$60.getField(2), 3, false)]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                            data-scan []<-[$$46, $$60] <- test.DBLP
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-jaccard_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-jaccard_02.plan
index 25dffe2..ddbb7b6 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-jaccard_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-jaccard_02.plan
@@ -1,28 +1,56 @@
+distribute result [$$34]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$34])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$34] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$45, $$35))
             -- HYBRID_HASH_JOIN [$$45][$$35]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                data-scan []<-[$$45, $$a] <- test.DBLP
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$35]  |PARTITIONED|
+                project ([$$b, $$35])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(lt($$35, $$36), get-item(similarity-jaccard-check($$39, gram-tokens($$b.getField(2), 3, false), 0.5), 0)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$35, $$39, $$36, $$b])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.CSX.CSX)  |PARTITIONED|
+                        unnest-map [$$36, $$b] <- index-search("CSX", 0, "test", "CSX", true, false, 1, $$48, 1, $$48, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$48)
                             -- STABLE_SORT [$$48(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.CSX.ngram_index)  |PARTITIONED|
+                                unnest-map [$$48] <- index-search("ngram_index", 5, "test", "CSX", true, true, 1, 0.5, 21, false, 1, $$39)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    project ([$$35, $$39])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$39] <- [gram-tokens($$47.getField(2), 3, false)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                          data-scan []<-[$$35, $$47] <- test.DBLP
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-jaccard_03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-jaccard_03.plan
index 760eb13..4b07256 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-jaccard_03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-jaccard_03.plan
@@ -1,28 +1,56 @@
+distribute result [$$34]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$34])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$34] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$45, $$35))
             -- HYBRID_HASH_JOIN [$$45][$$35]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                data-scan []<-[$$45, $$a] <- test.DBLP
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$35]  |PARTITIONED|
+                project ([$$b, $$35])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(lt($$35, $$36), get-item(similarity-jaccard-check($$39, gram-tokens($$b.getField(2), 3, false), 0.5), 0)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$35, $$39, $$36, $$b])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                        unnest-map [$$36, $$b] <- index-search("DBLP", 0, "test", "DBLP", true, false, 1, $$48, 1, $$48, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$48)
                             -- STABLE_SORT [$$48(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                                unnest-map [$$48] <- index-search("ngram_index", 5, "test", "DBLP", true, true, 1, 0.5, 21, false, 1, $$39)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    project ([$$35, $$39])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$39] <- [gram-tokens($$47.getField(2), 3, false)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                          data-scan []<-[$$35, $$47] <- test.DBLP
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-jaccard_04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-jaccard_04.plan
index a037692..dac9f6e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-jaccard_04.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ngram-jaccard_04.plan
@@ -1,29 +1,58 @@
+distribute result [$$44]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$44])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$44] <- [{"arec": $$a, "brec": $$b, "jacc": get-item(similarity-jaccard-check(gram-tokens($$a.getField(2), 3, false), $$49, 0.5), 1)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b, $$49])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$58, $$45))
             -- HYBRID_HASH_JOIN [$$58][$$45]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                data-scan []<-[$$58, $$a] <- test.DBLP
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$45]  |PARTITIONED|
+                project ([$$b, $$49, $$45])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(get-item(similarity-jaccard-check($$48, $$49, 0.5), 0), lt($$45, $$46)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    assign [$$49] <- [gram-tokens($$b.getField(2), 3, false)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$45, $$48, $$46, $$b])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                          unnest-map [$$46, $$b] <- index-search("DBLP", 0, "test", "DBLP", true, false, 1, $$61, 1, $$61, true, true, true)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$61)
                               -- STABLE_SORT [$$61(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                                  unnest-map [$$61] <- index-search("ngram_index", 5, "test", "DBLP", true, true, 1, 0.5, 21, false, 1, $$48)
+                                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                      project ([$$45, $$48])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$48] <- [gram-tokens($$60.getField(2), 3, false)]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                            data-scan []<-[$$45, $$60] <- test.DBLP
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-edit-distance-check_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-edit-distance-check_02.plan
index be6eb79..4e7f92e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-edit-distance-check_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-edit-distance-check_02.plan
@@ -1,55 +1,110 @@
+distribute result [$$32]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$32])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$32] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$41, $$33))
             -- HYBRID_HASH_JOIN [$$41][$$33]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                data-scan []<-[$$41, $$a] <- test.Customers
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$33]  |PARTITIONED|
+                union ($$b, $$44, $$b) ($$33, $$33, $$33)
                 -- UNION_ALL  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$b, $$33])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      select (and(lt($$33, $$34), get-item(edit-distance-check($$37, $$b.getField(4), 3), 0)))
                       -- STREAM_SELECT  |PARTITIONED|
+                        project ([$$33, $$37, $$34, $$b])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.Customers2.Customers2)  |PARTITIONED|
+                            unnest-map [$$34, $$b] <- index-search("Customers2", 0, "test", "Customers2", true, false, 1, $$46, 1, $$46, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$46)
                                 -- STABLE_SORT [$$46(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers2.interests_index)  |PARTITIONED|
+                                    unnest-map [$$46] <- index-search("interests_index", 4, "test", "Customers2", true, true, 2, 3, 21, false, 1, $$37)
+                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                        select (edit-distance-list-is-filterable($$37, 3))
                                         -- STREAM_SELECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$33, $$37])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$37] <- [$$42.getField(4)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                                      data-scan []<-[$$33, $$42] <- test.Customers
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$44, $$33])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        join (and(lt($$33, $$45), get-item(edit-distance-check($$37, $$43, 3), 0)))
                         -- NESTED_LOOP  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            assign [$$43] <- [$$44.getField(4)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.Customers2)  |PARTITIONED|
+                                data-scan []<-[$$45, $$44] <- test.Customers2
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                            select (not(edit-distance-list-is-filterable($$37, 3)))
                             -- STREAM_SELECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                replicate
                                 -- REPLICATE  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$33, $$37])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$37] <- [$$42.getField(4)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                          data-scan []<-[$$33, $$42] <- test.Customers
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-edit-distance-check_03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-edit-distance-check_03.plan
index cd50a99..3fee479 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-edit-distance-check_03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-edit-distance-check_03.plan
@@ -1,55 +1,110 @@
+distribute result [$$32]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$32])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$32] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$41, $$33))
             -- HYBRID_HASH_JOIN [$$41][$$33]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                data-scan []<-[$$41, $$a] <- test.Customers
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$33]  |PARTITIONED|
+                union ($$b, $$44, $$b) ($$33, $$33, $$33)
                 -- UNION_ALL  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$b, $$33])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      select (and(lt($$33, $$34), get-item(edit-distance-check($$37, $$b.getField(4), 3), 0)))
                       -- STREAM_SELECT  |PARTITIONED|
+                        project ([$$33, $$37, $$34, $$b])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                            unnest-map [$$34, $$b] <- index-search("Customers", 0, "test", "Customers", true, false, 1, $$46, 1, $$46, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$46)
                                 -- STABLE_SORT [$$46(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                    unnest-map [$$46] <- index-search("interests_index", 4, "test", "Customers", true, true, 2, 3, 21, false, 1, $$37)
+                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                        select (edit-distance-list-is-filterable($$37, 3))
                                         -- STREAM_SELECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$33, $$37])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$37] <- [$$42.getField(4)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                                      data-scan []<-[$$33, $$42] <- test.Customers
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$44, $$33])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        join (and(lt($$33, $$45), get-item(edit-distance-check($$37, $$43, 3), 0)))
                         -- NESTED_LOOP  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            assign [$$43] <- [$$44.getField(4)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                data-scan []<-[$$45, $$44] <- test.Customers
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                            select (not(edit-distance-list-is-filterable($$37, 3)))
                             -- STREAM_SELECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                replicate
                                 -- REPLICATE  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$33, $$37])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$37] <- [$$42.getField(4)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                          data-scan []<-[$$33, $$42] <- test.Customers
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-edit-distance-check_04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-edit-distance-check_04.plan
index 05a02d8..6e76036 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-edit-distance-check_04.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-edit-distance-check_04.plan
@@ -1,59 +1,118 @@
+distribute result [$$43]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$43])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$43] <- [{"arec": $$a, "brec": $$b, "ed": get-item($$60, 1)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b, $$60])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$54, $$44))
             -- HYBRID_HASH_JOIN [$$54][$$44]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                data-scan []<-[$$54, $$a] <- test.Customers
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$44]  |PARTITIONED|
+                union ($$b, $$57, $$b) ($$44, $$44, $$44) ($$79, $$70, $$60)
                 -- UNION_ALL  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$b, $$44, $$79])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      select (and(get-item($$79, 0), lt($$44, $$45)))
                       -- STREAM_SELECT  |PARTITIONED|
+                        project ([$$44, $$45, $$b, $$79])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$79] <- [edit-distance-check($$46, $$b.getField(4), 3)]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$44, $$46, $$45, $$b])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                                unnest-map [$$45, $$b] <- index-search("Customers", 0, "test", "Customers", true, false, 1, $$59, 1, $$59, true, true, true)
+                                -- BTREE_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$59)
                                     -- STABLE_SORT [$$59(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                        unnest-map [$$59] <- index-search("interests_index", 4, "test", "Customers", true, true, 2, 3, 21, false, 1, $$46)
+                                        -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                            select (edit-distance-list-is-filterable($$46, 3))
                                             -- STREAM_SELECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                replicate
                                                 -- REPLICATE  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$$44, $$46])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      assign [$$46] <- [$$55.getField(4)]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                                          data-scan []<-[$$44, $$55] <- test.Customers
+                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              empty-tuple-source
                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$57, $$44, $$70])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$70] <- [edit-distance-check($$46, $$56, 3)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$57, $$56, $$44, $$46])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            join (and(get-item(edit-distance-check($$46, $$56, 3), 0), lt($$44, $$58)))
                             -- NESTED_LOOP  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                assign [$$56] <- [$$57.getField(4)]
                                 -- ASSIGN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                    data-scan []<-[$$58, $$57] <- test.Customers
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                select (not(edit-distance-list-is-filterable($$46, 3)))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    replicate
                                     -- REPLICATE  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$44, $$46])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$46] <- [$$55.getField(4)]
                                           -- ASSIGN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                              data-scan []<-[$$44, $$55] <- test.Customers
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-edit-distance_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-edit-distance_02.plan
index be6eb79..6122780 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-edit-distance_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-edit-distance_02.plan
@@ -1,55 +1,110 @@
+distribute result [$$32]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$32])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$32] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$41, $$33))
             -- HYBRID_HASH_JOIN [$$41][$$33]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                data-scan []<-[$$41, $$a] <- test.Customers
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$33]  |PARTITIONED|
+                union ($$b, $$44, $$b) ($$33, $$33, $$33)
                 -- UNION_ALL  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$b, $$33])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      select (and(lt($$33, $$34), get-item(edit-distance-check($$37, $$b.getField(4), 2), 0)))
                       -- STREAM_SELECT  |PARTITIONED|
+                        project ([$$33, $$37, $$34, $$b])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.Customers2.Customers2)  |PARTITIONED|
+                            unnest-map [$$34, $$b] <- index-search("Customers2", 0, "test", "Customers2", true, false, 1, $$46, 1, $$46, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$46)
                                 -- STABLE_SORT [$$46(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers2.interests_index)  |PARTITIONED|
+                                    unnest-map [$$46] <- index-search("interests_index", 4, "test", "Customers2", true, true, 2, 2, 21, false, 1, $$37)
+                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                        select (edit-distance-list-is-filterable($$37, 2))
                                         -- STREAM_SELECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$33, $$37])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$37] <- [$$42.getField(4)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                                      data-scan []<-[$$33, $$42] <- test.Customers
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$44, $$33])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        join (and(lt($$33, $$45), get-item(edit-distance-check($$37, $$43, 2), 0)))
                         -- NESTED_LOOP  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            assign [$$43] <- [$$44.getField(4)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.Customers2)  |PARTITIONED|
+                                data-scan []<-[$$45, $$44] <- test.Customers2
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                            select (not(edit-distance-list-is-filterable($$37, 2)))
                             -- STREAM_SELECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                replicate
                                 -- REPLICATE  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$33, $$37])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$37] <- [$$42.getField(4)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                          data-scan []<-[$$33, $$42] <- test.Customers
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-edit-distance_03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-edit-distance_03.plan
index cd50a99..e03e3b7 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-edit-distance_03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-edit-distance_03.plan
@@ -1,55 +1,110 @@
+distribute result [$$32]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$32])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$32] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$41, $$33))
             -- HYBRID_HASH_JOIN [$$41][$$33]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                data-scan []<-[$$41, $$a] <- test.Customers
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$33]  |PARTITIONED|
+                union ($$b, $$44, $$b) ($$33, $$33, $$33)
                 -- UNION_ALL  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$b, $$33])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      select (and(lt($$33, $$34), get-item(edit-distance-check($$37, $$b.getField(4), 2), 0)))
                       -- STREAM_SELECT  |PARTITIONED|
+                        project ([$$33, $$37, $$34, $$b])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                            unnest-map [$$34, $$b] <- index-search("Customers", 0, "test", "Customers", true, false, 1, $$46, 1, $$46, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$46)
                                 -- STABLE_SORT [$$46(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                    unnest-map [$$46] <- index-search("interests_index", 4, "test", "Customers", true, true, 2, 2, 21, false, 1, $$37)
+                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                        select (edit-distance-list-is-filterable($$37, 2))
                                         -- STREAM_SELECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$33, $$37])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$37] <- [$$42.getField(4)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                                      data-scan []<-[$$33, $$42] <- test.Customers
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$44, $$33])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        join (and(lt($$33, $$45), get-item(edit-distance-check($$37, $$43, 2), 0)))
                         -- NESTED_LOOP  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            assign [$$43] <- [$$44.getField(4)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                data-scan []<-[$$45, $$44] <- test.Customers
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                            select (not(edit-distance-list-is-filterable($$37, 2)))
                             -- STREAM_SELECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                replicate
                                 -- REPLICATE  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$33, $$37])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$37] <- [$$42.getField(4)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                          data-scan []<-[$$33, $$42] <- test.Customers
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-edit-distance_04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-edit-distance_04.plan
index a5ea5f3..a2ccac7 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-edit-distance_04.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-edit-distance_04.plan
@@ -1,59 +1,118 @@
+distribute result [$$42]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$42])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$42] <- [{"arec": $$a, "brec": $$b, "ed": get-item($$60, 1)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b, $$60])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$54, $$43))
             -- HYBRID_HASH_JOIN [$$54][$$43]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                data-scan []<-[$$54, $$a] <- test.Customers
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$43]  |PARTITIONED|
+                union ($$b, $$57, $$b) ($$43, $$43, $$43) ($$79, $$70, $$60)
                 -- UNION_ALL  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$b, $$43, $$79])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      select (and(get-item($$79, 0), lt($$43, $$44)))
                       -- STREAM_SELECT  |PARTITIONED|
+                        project ([$$43, $$44, $$b, $$79])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$79] <- [edit-distance-check($$46, $$b.getField(4), 2)]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$43, $$46, $$44, $$b])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                                unnest-map [$$44, $$b] <- index-search("Customers", 0, "test", "Customers", true, false, 1, $$59, 1, $$59, true, true, true)
+                                -- BTREE_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$59)
                                     -- STABLE_SORT [$$59(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                        unnest-map [$$59] <- index-search("interests_index", 4, "test", "Customers", true, true, 2, 2, 21, false, 1, $$46)
+                                        -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                            select (edit-distance-list-is-filterable($$46, 2))
                                             -- STREAM_SELECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                replicate
                                                 -- REPLICATE  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$$43, $$46])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      assign [$$46] <- [$$55.getField(4)]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                                          data-scan []<-[$$43, $$55] <- test.Customers
+                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              empty-tuple-source
                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$57, $$43, $$70])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$70] <- [edit-distance-check($$46, $$56, 2)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$57, $$56, $$43, $$46])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            join (and(get-item(edit-distance-check($$46, $$56, 2), 0), lt($$43, $$58)))
                             -- NESTED_LOOP  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                assign [$$56] <- [$$57.getField(4)]
                                 -- ASSIGN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                    data-scan []<-[$$58, $$57] <- test.Customers
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                select (not(edit-distance-list-is-filterable($$46, 2)))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    replicate
                                     -- REPLICATE  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$43, $$46])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$46] <- [$$55.getField(4)]
                                           -- ASSIGN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                              data-scan []<-[$$43, $$55] <- test.Customers
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-fuzzyeq-edit-distance_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-fuzzyeq-edit-distance_02.plan
index 2797eef..0706940 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-fuzzyeq-edit-distance_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-fuzzyeq-edit-distance_02.plan
@@ -1,55 +1,110 @@
+distribute result [$$31]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$31])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$31] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$40, $$32))
             -- HYBRID_HASH_JOIN [$$40][$$32]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                data-scan []<-[$$40, $$a] <- test.Customers
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$32]  |PARTITIONED|
+                union ($$b, $$43, $$b) ($$32, $$32, $$32)
                 -- UNION_ALL  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$b, $$32])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      select (and(lt($$32, $$33), get-item(edit-distance-check($$36, $$b.getField(4), 3), 0)))
                       -- STREAM_SELECT  |PARTITIONED|
+                        project ([$$32, $$36, $$33, $$b])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.Customers2.Customers2)  |PARTITIONED|
+                            unnest-map [$$33, $$b] <- index-search("Customers2", 0, "test", "Customers2", true, false, 1, $$45, 1, $$45, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$45)
                                 -- STABLE_SORT [$$45(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers2.interests_index)  |PARTITIONED|
+                                    unnest-map [$$45] <- index-search("interests_index", 4, "test", "Customers2", true, true, 2, 3, 21, false, 1, $$36)
+                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                        select (edit-distance-list-is-filterable($$36, 3))
                                         -- STREAM_SELECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$32, $$36])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$36] <- [$$41.getField(4)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                                      data-scan []<-[$$32, $$41] <- test.Customers
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$43, $$32])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        join (and(lt($$32, $$44), get-item(edit-distance-check($$36, $$42, 3), 0)))
                         -- NESTED_LOOP  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            assign [$$42] <- [$$43.getField(4)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.Customers2)  |PARTITIONED|
+                                data-scan []<-[$$44, $$43] <- test.Customers2
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                            select (not(edit-distance-list-is-filterable($$36, 3)))
                             -- STREAM_SELECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                replicate
                                 -- REPLICATE  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$32, $$36])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$36] <- [$$41.getField(4)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                          data-scan []<-[$$32, $$41] <- test.Customers
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-fuzzyeq-edit-distance_03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-fuzzyeq-edit-distance_03.plan
index 9d950ce..7a09506 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-fuzzyeq-edit-distance_03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-fuzzyeq-edit-distance_03.plan
@@ -1,55 +1,110 @@
+distribute result [$$31]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$31])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$31] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$40, $$32))
             -- HYBRID_HASH_JOIN [$$40][$$32]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                data-scan []<-[$$40, $$a] <- test.Customers
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$32]  |PARTITIONED|
+                union ($$b, $$43, $$b) ($$32, $$32, $$32)
                 -- UNION_ALL  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$b, $$32])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      select (and(lt($$32, $$33), get-item(edit-distance-check($$36, $$b.getField(4), 3), 0)))
                       -- STREAM_SELECT  |PARTITIONED|
+                        project ([$$32, $$36, $$33, $$b])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                            unnest-map [$$33, $$b] <- index-search("Customers", 0, "test", "Customers", true, false, 1, $$45, 1, $$45, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$45)
                                 -- STABLE_SORT [$$45(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                    unnest-map [$$45] <- index-search("interests_index", 4, "test", "Customers", true, true, 2, 3, 21, false, 1, $$36)
+                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                        select (edit-distance-list-is-filterable($$36, 3))
                                         -- STREAM_SELECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$32, $$36])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$36] <- [$$41.getField(4)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                                      data-scan []<-[$$32, $$41] <- test.Customers
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$43, $$32])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        join (and(lt($$32, $$44), get-item(edit-distance-check($$36, $$42, 3), 0)))
                         -- NESTED_LOOP  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            assign [$$42] <- [$$43.getField(4)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                data-scan []<-[$$44, $$43] <- test.Customers
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                            select (not(edit-distance-list-is-filterable($$36, 3)))
                             -- STREAM_SELECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                replicate
                                 -- REPLICATE  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$32, $$36])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$36] <- [$$41.getField(4)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                          data-scan []<-[$$32, $$41] <- test.Customers
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-fuzzyeq-jaccard_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-fuzzyeq-jaccard_02.plan
index 8e921c5..7268621 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-fuzzyeq-jaccard_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-fuzzyeq-jaccard_02.plan
@@ -1,28 +1,56 @@
+distribute result [$$31]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$31])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$31] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$40, $$32))
             -- HYBRID_HASH_JOIN [$$40][$$32]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                data-scan []<-[$$40, $$a] <- test.Customers
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$32]  |PARTITIONED|
+                project ([$$b, $$32])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(lt($$32, $$33), get-item(similarity-jaccard-check($$36, $$b.getField(4), 0.7), 0)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$32, $$36, $$33, $$b])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.Customers2.Customers2)  |PARTITIONED|
+                        unnest-map [$$33, $$b] <- index-search("Customers2", 0, "test", "Customers2", true, false, 1, $$42, 1, $$42, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$42)
                             -- STABLE_SORT [$$42(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers2.interests_index)  |PARTITIONED|
+                                unnest-map [$$42] <- index-search("interests_index", 4, "test", "Customers2", true, true, 1, 0.7, 21, false, 1, $$36)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    project ([$$32, $$36])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$36] <- [$$41.getField(4)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                          data-scan []<-[$$32, $$41] <- test.Customers
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-fuzzyeq-jaccard_03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-fuzzyeq-jaccard_03.plan
index fe7125d..fde57ca 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-fuzzyeq-jaccard_03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-fuzzyeq-jaccard_03.plan
@@ -1,28 +1,56 @@
+distribute result [$$31]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$31])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$31] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$40, $$32))
             -- HYBRID_HASH_JOIN [$$40][$$32]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                data-scan []<-[$$40, $$a] <- test.Customers
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$32]  |PARTITIONED|
+                project ([$$b, $$32])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(lt($$32, $$33), get-item(similarity-jaccard-check($$36, $$b.getField(4), 0.7), 0)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$32, $$36, $$33, $$b])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                        unnest-map [$$33, $$b] <- index-search("Customers", 0, "test", "Customers", true, false, 1, $$42, 1, $$42, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$42)
                             -- STABLE_SORT [$$42(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                unnest-map [$$42] <- index-search("interests_index", 4, "test", "Customers", true, true, 1, 0.7, 21, false, 1, $$36)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    project ([$$32, $$36])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$36] <- [$$41.getField(4)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                          data-scan []<-[$$32, $$41] <- test.Customers
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-jaccard-check_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-jaccard-check_02.plan
index 8350b49..cd5e0e0 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-jaccard-check_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-jaccard-check_02.plan
@@ -1,28 +1,56 @@
+distribute result [$$32]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$32])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$32] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$41, $$33))
             -- HYBRID_HASH_JOIN [$$41][$$33]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                data-scan []<-[$$41, $$a] <- test.Customers
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$33]  |PARTITIONED|
+                project ([$$b, $$33])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(lt($$33, $$34), get-item(similarity-jaccard-check($$37, $$b.getField(4), 0.7), 0)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$33, $$37, $$34, $$b])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.Customers2.Customers2)  |PARTITIONED|
+                        unnest-map [$$34, $$b] <- index-search("Customers2", 0, "test", "Customers2", true, false, 1, $$43, 1, $$43, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$43)
                             -- STABLE_SORT [$$43(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers2.interests_index)  |PARTITIONED|
+                                unnest-map [$$43] <- index-search("interests_index", 4, "test", "Customers2", true, true, 1, 0.7, 21, false, 1, $$37)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    project ([$$33, $$37])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$37] <- [$$42.getField(4)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                          data-scan []<-[$$33, $$42] <- test.Customers
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-jaccard-check_03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-jaccard-check_03.plan
index 2682723..f7a362c 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-jaccard-check_03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-jaccard-check_03.plan
@@ -1,28 +1,56 @@
+distribute result [$$32]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$32])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$32] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$41, $$33))
             -- HYBRID_HASH_JOIN [$$41][$$33]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                data-scan []<-[$$41, $$a] <- test.Customers
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$33]  |PARTITIONED|
+                project ([$$b, $$33])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(lt($$33, $$34), get-item(similarity-jaccard-check($$37, $$b.getField(4), 0.7), 0)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$33, $$37, $$34, $$b])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                        unnest-map [$$34, $$b] <- index-search("Customers", 0, "test", "Customers", true, false, 1, $$43, 1, $$43, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$43)
                             -- STABLE_SORT [$$43(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                unnest-map [$$43] <- index-search("interests_index", 4, "test", "Customers", true, true, 1, 0.7, 21, false, 1, $$37)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    project ([$$33, $$37])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$37] <- [$$42.getField(4)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                          data-scan []<-[$$33, $$42] <- test.Customers
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-jaccard-check_04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-jaccard-check_04.plan
index c482198..25ea154 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-jaccard-check_04.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-jaccard-check_04.plan
@@ -1,30 +1,60 @@
+distribute result [$$43]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$43])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$43] <- [{"arec": $$a, "brec": $$b, "jacc": get-item($$58, 1)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b, $$58])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$54, $$44))
             -- HYBRID_HASH_JOIN [$$54][$$44]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                data-scan []<-[$$54, $$a] <- test.Customers
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$44]  |PARTITIONED|
+                project ([$$b, $$58, $$44])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(get-item($$58, 0), lt($$44, $$45)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$44, $$45, $$b, $$58])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$58] <- [similarity-jaccard-check($$46, $$b.getField(4), 0.7)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$44, $$46, $$45, $$b])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                            unnest-map [$$45, $$b] <- index-search("Customers", 0, "test", "Customers", true, false, 1, $$56, 1, $$56, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$56)
                                 -- STABLE_SORT [$$56(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                    unnest-map [$$56] <- index-search("interests_index", 4, "test", "Customers", true, true, 1, 0.7, 21, false, 1, $$46)
+                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                        project ([$$44, $$46])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$46] <- [$$55.getField(4)]
                                           -- ASSIGN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                              data-scan []<-[$$44, $$55] <- test.Customers
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-jaccard_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-jaccard_02.plan
index 8350b49..cd5e0e0 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-jaccard_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-jaccard_02.plan
@@ -1,28 +1,56 @@
+distribute result [$$32]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$32])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$32] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$41, $$33))
             -- HYBRID_HASH_JOIN [$$41][$$33]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                data-scan []<-[$$41, $$a] <- test.Customers
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$33]  |PARTITIONED|
+                project ([$$b, $$33])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(lt($$33, $$34), get-item(similarity-jaccard-check($$37, $$b.getField(4), 0.7), 0)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$33, $$37, $$34, $$b])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.Customers2.Customers2)  |PARTITIONED|
+                        unnest-map [$$34, $$b] <- index-search("Customers2", 0, "test", "Customers2", true, false, 1, $$43, 1, $$43, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$43)
                             -- STABLE_SORT [$$43(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers2.interests_index)  |PARTITIONED|
+                                unnest-map [$$43] <- index-search("interests_index", 4, "test", "Customers2", true, true, 1, 0.7, 21, false, 1, $$37)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    project ([$$33, $$37])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$37] <- [$$42.getField(4)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                          data-scan []<-[$$33, $$42] <- test.Customers
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-jaccard_03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-jaccard_03.plan
index 2682723..f7a362c 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-jaccard_03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-jaccard_03.plan
@@ -1,28 +1,56 @@
+distribute result [$$32]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$32])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$32] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$41, $$33))
             -- HYBRID_HASH_JOIN [$$41][$$33]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                data-scan []<-[$$41, $$a] <- test.Customers
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$33]  |PARTITIONED|
+                project ([$$b, $$33])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(lt($$33, $$34), get-item(similarity-jaccard-check($$37, $$b.getField(4), 0.7), 0)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$33, $$37, $$34, $$b])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                        unnest-map [$$34, $$b] <- index-search("Customers", 0, "test", "Customers", true, false, 1, $$43, 1, $$43, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$43)
                             -- STABLE_SORT [$$43(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                unnest-map [$$43] <- index-search("interests_index", 4, "test", "Customers", true, true, 1, 0.7, 21, false, 1, $$37)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    project ([$$33, $$37])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$37] <- [$$42.getField(4)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                          data-scan []<-[$$33, $$42] <- test.Customers
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-jaccard_04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-jaccard_04.plan
index 173a0b2..4df939b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-jaccard_04.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/olist-jaccard_04.plan
@@ -1,30 +1,60 @@
+distribute result [$$42]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$42])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$42] <- [{"arec": $$a, "brec": $$b, "jacc": get-item($$58, 1)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b, $$58])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$54, $$43))
             -- HYBRID_HASH_JOIN [$$54][$$43]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                data-scan []<-[$$54, $$a] <- test.Customers
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$43]  |PARTITIONED|
+                project ([$$b, $$58, $$43])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(get-item($$58, 0), lt($$43, $$44)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$43, $$44, $$b, $$58])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$58] <- [similarity-jaccard-check($$46, $$b.getField(4), 0.7)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$43, $$46, $$44, $$b])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                            unnest-map [$$44, $$b] <- index-search("Customers", 0, "test", "Customers", true, false, 1, $$56, 1, $$56, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$56)
                                 -- STABLE_SORT [$$56(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                    unnest-map [$$56] <- index-search("interests_index", 4, "test", "Customers", true, true, 1, 0.7, 21, false, 1, $$46)
+                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                        project ([$$43, $$46])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$46] <- [$$55.getField(4)]
                                           -- ASSIGN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                              data-scan []<-[$$43, $$55] <- test.Customers
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-fuzzyeq-jaccard_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-fuzzyeq-jaccard_02.plan
index 8e921c5..8b70258 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-fuzzyeq-jaccard_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-fuzzyeq-jaccard_02.plan
@@ -1,28 +1,56 @@
+distribute result [$$31]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$31])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$31] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$40, $$32))
             -- HYBRID_HASH_JOIN [$$40][$$32]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                data-scan []<-[$$40, $$a] <- test.Customers
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$32]  |PARTITIONED|
+                project ([$$b, $$32])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(lt($$32, $$33), get-item(similarity-jaccard-check($$36, $$b.getField(4), 0.7), 0)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$32, $$36, $$33, $$b])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.Customers2.Customers2)  |PARTITIONED|
+                        unnest-map [$$33, $$b] <- index-search("Customers2", 0, "test", "Customers2", true, false, 1, $$42, 1, $$42, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$42)
                             -- STABLE_SORT [$$42(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers2.interests_index)  |PARTITIONED|
+                                unnest-map [$$42] <- index-search("interests_index", 4, "test", "Customers2", true, true, 1, 0.7, 22, false, 1, $$36)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    project ([$$32, $$36])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$36] <- [$$41.getField(4)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                          data-scan []<-[$$32, $$41] <- test.Customers
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-fuzzyeq-jaccard_03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-fuzzyeq-jaccard_03.plan
index fe7125d..1c99c8d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-fuzzyeq-jaccard_03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-fuzzyeq-jaccard_03.plan
@@ -1,28 +1,56 @@
+distribute result [$$31]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$31])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$31] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$40, $$32))
             -- HYBRID_HASH_JOIN [$$40][$$32]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                data-scan []<-[$$40, $$a] <- test.Customers
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$32]  |PARTITIONED|
+                project ([$$b, $$32])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(lt($$32, $$33), get-item(similarity-jaccard-check($$36, $$b.getField(4), 0.7), 0)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$32, $$36, $$33, $$b])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                        unnest-map [$$33, $$b] <- index-search("Customers", 0, "test", "Customers", true, false, 1, $$42, 1, $$42, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$42)
                             -- STABLE_SORT [$$42(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                unnest-map [$$42] <- index-search("interests_index", 4, "test", "Customers", true, true, 1, 0.7, 22, false, 1, $$36)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    project ([$$32, $$36])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$36] <- [$$41.getField(4)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                          data-scan []<-[$$32, $$41] <- test.Customers
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-jaccard-check_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-jaccard-check_02.plan
index 8350b49..a9bb511 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-jaccard-check_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-jaccard-check_02.plan
@@ -1,28 +1,56 @@
+distribute result [$$32]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$32])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$32] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$41, $$33))
             -- HYBRID_HASH_JOIN [$$41][$$33]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                data-scan []<-[$$41, $$a] <- test.Customers
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$33]  |PARTITIONED|
+                project ([$$b, $$33])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(lt($$33, $$34), get-item(similarity-jaccard-check($$37, $$b.getField(4), 0.7), 0)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$33, $$37, $$34, $$b])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.Customers2.Customers2)  |PARTITIONED|
+                        unnest-map [$$34, $$b] <- index-search("Customers2", 0, "test", "Customers2", true, false, 1, $$43, 1, $$43, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$43)
                             -- STABLE_SORT [$$43(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers2.interests_index)  |PARTITIONED|
+                                unnest-map [$$43] <- index-search("interests_index", 4, "test", "Customers2", true, true, 1, 0.7, 22, false, 1, $$37)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    project ([$$33, $$37])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$37] <- [$$42.getField(4)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                          data-scan []<-[$$33, $$42] <- test.Customers
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-jaccard-check_03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-jaccard-check_03.plan
index 2682723..264170f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-jaccard-check_03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-jaccard-check_03.plan
@@ -1,28 +1,56 @@
+distribute result [$$32]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$32])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$32] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$41, $$33))
             -- HYBRID_HASH_JOIN [$$41][$$33]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                data-scan []<-[$$41, $$a] <- test.Customers
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$33]  |PARTITIONED|
+                project ([$$b, $$33])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(lt($$33, $$34), get-item(similarity-jaccard-check($$37, $$b.getField(4), 0.7), 0)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$33, $$37, $$34, $$b])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                        unnest-map [$$34, $$b] <- index-search("Customers", 0, "test", "Customers", true, false, 1, $$43, 1, $$43, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$43)
                             -- STABLE_SORT [$$43(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                unnest-map [$$43] <- index-search("interests_index", 4, "test", "Customers", true, true, 1, 0.7, 22, false, 1, $$37)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    project ([$$33, $$37])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$37] <- [$$42.getField(4)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                          data-scan []<-[$$33, $$42] <- test.Customers
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-jaccard-check_04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-jaccard-check_04.plan
index c482198..1a72f11 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-jaccard-check_04.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-jaccard-check_04.plan
@@ -1,30 +1,60 @@
+distribute result [$$43]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$43])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$43] <- [{"arec": $$a, "brec": $$b, "jacc": get-item($$58, 1)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b, $$58])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$54, $$44))
             -- HYBRID_HASH_JOIN [$$54][$$44]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                data-scan []<-[$$54, $$a] <- test.Customers
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$44]  |PARTITIONED|
+                project ([$$b, $$58, $$44])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(get-item($$58, 0), lt($$44, $$45)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$44, $$45, $$b, $$58])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$58] <- [similarity-jaccard-check($$46, $$b.getField(4), 0.7)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$44, $$46, $$45, $$b])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                            unnest-map [$$45, $$b] <- index-search("Customers", 0, "test", "Customers", true, false, 1, $$56, 1, $$56, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$56)
                                 -- STABLE_SORT [$$56(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                    unnest-map [$$56] <- index-search("interests_index", 4, "test", "Customers", true, true, 1, 0.7, 22, false, 1, $$46)
+                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                        project ([$$44, $$46])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$46] <- [$$55.getField(4)]
                                           -- ASSIGN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                              data-scan []<-[$$44, $$55] <- test.Customers
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-jaccard_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-jaccard_02.plan
index 8350b49..a9bb511 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-jaccard_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-jaccard_02.plan
@@ -1,28 +1,56 @@
+distribute result [$$32]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$32])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$32] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$41, $$33))
             -- HYBRID_HASH_JOIN [$$41][$$33]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                data-scan []<-[$$41, $$a] <- test.Customers
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$33]  |PARTITIONED|
+                project ([$$b, $$33])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(lt($$33, $$34), get-item(similarity-jaccard-check($$37, $$b.getField(4), 0.7), 0)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$33, $$37, $$34, $$b])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.Customers2.Customers2)  |PARTITIONED|
+                        unnest-map [$$34, $$b] <- index-search("Customers2", 0, "test", "Customers2", true, false, 1, $$43, 1, $$43, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$43)
                             -- STABLE_SORT [$$43(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers2.interests_index)  |PARTITIONED|
+                                unnest-map [$$43] <- index-search("interests_index", 4, "test", "Customers2", true, true, 1, 0.7, 22, false, 1, $$37)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    project ([$$33, $$37])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$37] <- [$$42.getField(4)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                          data-scan []<-[$$33, $$42] <- test.Customers
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-jaccard_03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-jaccard_03.plan
index 2682723..264170f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-jaccard_03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-jaccard_03.plan
@@ -1,28 +1,56 @@
+distribute result [$$32]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$32])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$32] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$41, $$33))
             -- HYBRID_HASH_JOIN [$$41][$$33]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                data-scan []<-[$$41, $$a] <- test.Customers
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$33]  |PARTITIONED|
+                project ([$$b, $$33])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(lt($$33, $$34), get-item(similarity-jaccard-check($$37, $$b.getField(4), 0.7), 0)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$33, $$37, $$34, $$b])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                        unnest-map [$$34, $$b] <- index-search("Customers", 0, "test", "Customers", true, false, 1, $$43, 1, $$43, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$43)
                             -- STABLE_SORT [$$43(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                unnest-map [$$43] <- index-search("interests_index", 4, "test", "Customers", true, true, 1, 0.7, 22, false, 1, $$37)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    project ([$$33, $$37])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$37] <- [$$42.getField(4)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                          data-scan []<-[$$33, $$42] <- test.Customers
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-jaccard_04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-jaccard_04.plan
index 173a0b2..5818799 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-jaccard_04.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/ulist-jaccard_04.plan
@@ -1,30 +1,60 @@
+distribute result [$$42]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$42])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$42] <- [{"arec": $$a, "brec": $$b, "jacc": get-item($$58, 1)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b, $$58])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$54, $$43))
             -- HYBRID_HASH_JOIN [$$54][$$43]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                data-scan []<-[$$54, $$a] <- test.Customers
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$43]  |PARTITIONED|
+                project ([$$b, $$58, $$43])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(get-item($$58, 0), lt($$43, $$44)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$43, $$44, $$b, $$58])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$58] <- [similarity-jaccard-check($$46, $$b.getField(4), 0.7)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$43, $$46, $$44, $$b])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                            unnest-map [$$44, $$b] <- index-search("Customers", 0, "test", "Customers", true, false, 1, $$56, 1, $$56, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$56)
                                 -- STABLE_SORT [$$56(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                    unnest-map [$$56] <- index-search("interests_index", 4, "test", "Customers", true, true, 1, 0.7, 22, false, 1, $$46)
+                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                        project ([$$43, $$46])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$46] <- [$$55.getField(4)]
                                           -- ASSIGN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                              data-scan []<-[$$43, $$55] <- test.Customers
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-fuzzyeq-jaccard_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-fuzzyeq-jaccard_02.plan
index c0704d0..fbdbea5 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-fuzzyeq-jaccard_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-fuzzyeq-jaccard_02.plan
@@ -1,28 +1,56 @@
+distribute result [$$33]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$33])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$33] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$44, $$34))
             -- HYBRID_HASH_JOIN [$$44][$$34]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                data-scan []<-[$$44, $$a] <- test.DBLP
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$34]  |PARTITIONED|
+                project ([$$b, $$34])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(lt($$34, $$35), get-item(similarity-jaccard-check($$38, word-tokens($$b.getField(2)), 0.5), 0)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$34, $$38, $$35, $$b])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.CSX.CSX)  |PARTITIONED|
+                        unnest-map [$$35, $$b] <- index-search("CSX", 0, "test", "CSX", true, false, 1, $$47, 1, $$47, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$47)
                             -- STABLE_SORT [$$47(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.CSX.keyword_index)  |PARTITIONED|
+                                unnest-map [$$47] <- index-search("keyword_index", 4, "test", "CSX", true, true, 1, 0.5, 21, false, 1, $$38)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    project ([$$34, $$38])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$38] <- [word-tokens($$46.getField(2))]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                          data-scan []<-[$$34, $$46] <- test.DBLP
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-fuzzyeq-jaccard_03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-fuzzyeq-jaccard_03.plan
index 002d0c5..3361ddc 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-fuzzyeq-jaccard_03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-fuzzyeq-jaccard_03.plan
@@ -1,28 +1,56 @@
+distribute result [$$33]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$33])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$33] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$44, $$34))
             -- HYBRID_HASH_JOIN [$$44][$$34]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                data-scan []<-[$$44, $$a] <- test.DBLP
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$34]  |PARTITIONED|
+                project ([$$b, $$34])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(lt($$34, $$35), get-item(similarity-jaccard-check($$38, word-tokens($$b.getField(2)), 0.5), 0)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$34, $$38, $$35, $$b])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                        unnest-map [$$35, $$b] <- index-search("DBLP", 0, "test", "DBLP", true, false, 1, $$47, 1, $$47, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$47)
                             -- STABLE_SORT [$$47(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.keyword_index)  |PARTITIONED|
+                                unnest-map [$$47] <- index-search("keyword_index", 4, "test", "DBLP", true, true, 1, 0.5, 21, false, 1, $$38)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    project ([$$34, $$38])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$38] <- [word-tokens($$46.getField(2))]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                          data-scan []<-[$$34, $$46] <- test.DBLP
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-jaccard-check-after-btree-access.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-jaccard-check-after-btree-access.plan
index 0767902..976086e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-jaccard-check-after-btree-access.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-jaccard-check-after-btree-access.plan
@@ -1,41 +1,82 @@
+distribute result [$$50]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$50])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$50] <- [{"t1": $$53, "t2": $$54, "sim": get-item(similarity-jaccard-check(word-tokens($$57), $$56, 0.6), 1)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$57, $$53, $$54, $$56])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$66, $$53))
             -- HYBRID_HASH_JOIN [$$66][$$53]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$57, $$66])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$57] <- [$$t1.getField(5)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$66, $$t1])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$66, $$t1] <- [$$53, $$68]
                       -- ASSIGN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                              unnest-map [$$53, $$68] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$69, true, false, false)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$69] <- [20]
                                   -- ASSIGN  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$53]  |PARTITIONED|
+                project ([$$53, $$54, $$56])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(neq($$54, $$53), get-item(similarity-jaccard-check($$55, $$56, 0.6), 0)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$53, $$55, $$54, $$56])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$56] <- [word-tokens($$t2.getField(5))]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$53, $$55, $$54, $$t2])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                            unnest-map [$$54, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$71, 1, $$71, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$71)
                                 -- STABLE_SORT [$$71(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.TweetMessages.msgTextIx)  |PARTITIONED|
+                                    unnest-map [$$71] <- index-search("msgTextIx", 4, "test", "TweetMessages", true, true, 1, 0.6, 21, false, 1, $$55)
+                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                        project ([$$53, $$55])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$55] <- [word-tokens($$68.getField(5))]
                                           -- ASSIGN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              replicate
                                               -- REPLICATE  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                  unnest-map [$$53, $$68] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$69, true, false, false)
+                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      assign [$$69] <- [20]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-jaccard-check_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-jaccard-check_02.plan
index 40582ac..48d9dba 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-jaccard-check_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-jaccard-check_02.plan
@@ -1,28 +1,56 @@
+distribute result [$$34]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$34])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$34] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$45, $$35))
             -- HYBRID_HASH_JOIN [$$45][$$35]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                data-scan []<-[$$45, $$a] <- test.DBLP
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$35]  |PARTITIONED|
+                project ([$$b, $$35])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(lt($$35, $$36), get-item(similarity-jaccard-check($$39, word-tokens($$b.getField(2)), 0.5), 0)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$35, $$39, $$36, $$b])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.CSX.CSX)  |PARTITIONED|
+                        unnest-map [$$36, $$b] <- index-search("CSX", 0, "test", "CSX", true, false, 1, $$48, 1, $$48, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$48)
                             -- STABLE_SORT [$$48(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.CSX.keyword_index)  |PARTITIONED|
+                                unnest-map [$$48] <- index-search("keyword_index", 4, "test", "CSX", true, true, 1, 0.5, 21, false, 1, $$39)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    project ([$$35, $$39])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$39] <- [word-tokens($$47.getField(2))]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                          data-scan []<-[$$35, $$47] <- test.DBLP
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-jaccard-check_03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-jaccard-check_03.plan
index c752bfe..af9f485 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-jaccard-check_03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-jaccard-check_03.plan
@@ -1,28 +1,56 @@
+distribute result [$$34]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$34])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$34] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$45, $$35))
             -- HYBRID_HASH_JOIN [$$45][$$35]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                data-scan []<-[$$45, $$a] <- test.DBLP
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$35]  |PARTITIONED|
+                project ([$$b, $$35])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(lt($$35, $$36), get-item(similarity-jaccard-check($$39, word-tokens($$b.getField(2)), 0.5), 0)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$35, $$39, $$36, $$b])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                        unnest-map [$$36, $$b] <- index-search("DBLP", 0, "test", "DBLP", true, false, 1, $$48, 1, $$48, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$48)
                             -- STABLE_SORT [$$48(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.keyword_index)  |PARTITIONED|
+                                unnest-map [$$48] <- index-search("keyword_index", 4, "test", "DBLP", true, true, 1, 0.5, 21, false, 1, $$39)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    project ([$$35, $$39])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$39] <- [word-tokens($$47.getField(2))]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                          data-scan []<-[$$35, $$47] <- test.DBLP
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-jaccard-check_04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-jaccard-check_04.plan
index ee21d84..9a26b8b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-jaccard-check_04.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-jaccard-check_04.plan
@@ -1,29 +1,58 @@
+distribute result [$$45]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$45])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$45] <- [{"arec": $$a, "brec": $$b, "jacc": get-item(similarity-jaccard-check(word-tokens($$a.getField(2)), $$49, 0.5), 1)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b, $$49])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$58, $$46))
             -- HYBRID_HASH_JOIN [$$58][$$46]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                data-scan []<-[$$58, $$a] <- test.DBLP
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$46]  |PARTITIONED|
+                project ([$$b, $$49, $$46])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(get-item(similarity-jaccard-check($$48, $$49, 0.5), 0), lt($$46, $$47)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    assign [$$49] <- [word-tokens($$b.getField(2))]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$46, $$48, $$47, $$b])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                          unnest-map [$$47, $$b] <- index-search("DBLP", 0, "test", "DBLP", true, false, 1, $$61, 1, $$61, true, true, true)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$61)
                               -- STABLE_SORT [$$61(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.keyword_index)  |PARTITIONED|
+                                  unnest-map [$$61] <- index-search("keyword_index", 4, "test", "DBLP", true, true, 1, 0.5, 21, false, 1, $$48)
+                                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                      project ([$$46, $$48])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$48] <- [word-tokens($$60.getField(2))]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                            data-scan []<-[$$46, $$60] <- test.DBLP
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-jaccard_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-jaccard_02.plan
index 40582ac..48d9dba 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-jaccard_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-jaccard_02.plan
@@ -1,28 +1,56 @@
+distribute result [$$34]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$34])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$34] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$45, $$35))
             -- HYBRID_HASH_JOIN [$$45][$$35]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                data-scan []<-[$$45, $$a] <- test.DBLP
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$35]  |PARTITIONED|
+                project ([$$b, $$35])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(lt($$35, $$36), get-item(similarity-jaccard-check($$39, word-tokens($$b.getField(2)), 0.5), 0)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$35, $$39, $$36, $$b])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.CSX.CSX)  |PARTITIONED|
+                        unnest-map [$$36, $$b] <- index-search("CSX", 0, "test", "CSX", true, false, 1, $$48, 1, $$48, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$48)
                             -- STABLE_SORT [$$48(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.CSX.keyword_index)  |PARTITIONED|
+                                unnest-map [$$48] <- index-search("keyword_index", 4, "test", "CSX", true, true, 1, 0.5, 21, false, 1, $$39)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    project ([$$35, $$39])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$39] <- [word-tokens($$47.getField(2))]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                          data-scan []<-[$$35, $$47] <- test.DBLP
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-jaccard_03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-jaccard_03.plan
index c752bfe..af9f485 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-jaccard_03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-jaccard_03.plan
@@ -1,28 +1,56 @@
+distribute result [$$34]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$34])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$34] <- [{"arec": $$a, "brec": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$45, $$35))
             -- HYBRID_HASH_JOIN [$$45][$$35]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                data-scan []<-[$$45, $$a] <- test.DBLP
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$35]  |PARTITIONED|
+                project ([$$b, $$35])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(lt($$35, $$36), get-item(similarity-jaccard-check($$39, word-tokens($$b.getField(2)), 0.5), 0)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$35, $$39, $$36, $$b])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                        unnest-map [$$36, $$b] <- index-search("DBLP", 0, "test", "DBLP", true, false, 1, $$48, 1, $$48, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$48)
                             -- STABLE_SORT [$$48(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.keyword_index)  |PARTITIONED|
+                                unnest-map [$$48] <- index-search("keyword_index", 4, "test", "DBLP", true, true, 1, 0.5, 21, false, 1, $$39)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    project ([$$35, $$39])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$39] <- [word-tokens($$47.getField(2))]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                          data-scan []<-[$$35, $$47] <- test.DBLP
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-jaccard_04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-jaccard_04.plan
index 627e111..b717260 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-jaccard_04.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/inverted-index-join/word-jaccard_04.plan
@@ -1,29 +1,58 @@
+distribute result [$$44]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$44])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$44] <- [{"arec": $$a, "brec": $$b, "jacc": get-item(similarity-jaccard-check(word-tokens($$a.getField(2)), $$49, 0.5), 1)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b, $$49])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$58, $$45))
             -- HYBRID_HASH_JOIN [$$58][$$45]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                data-scan []<-[$$58, $$a] <- test.DBLP
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$45]  |PARTITIONED|
+                project ([$$b, $$49, $$45])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (and(get-item(similarity-jaccard-check($$48, $$49, 0.5), 0), lt($$45, $$46)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    assign [$$49] <- [word-tokens($$b.getField(2))]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$45, $$48, $$46, $$b])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                          unnest-map [$$46, $$b] <- index-search("DBLP", 0, "test", "DBLP", true, false, 1, $$61, 1, $$61, true, true, true)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$61)
                               -- STABLE_SORT [$$61(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.keyword_index)  |PARTITIONED|
+                                  unnest-map [$$61] <- index-search("keyword_index", 4, "test", "DBLP", true, true, 1, 0.5, 21, false, 1, $$48)
+                                  -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                      project ([$$45, $$48])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$48] <- [word-tokens($$60.getField(2))]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                            data-scan []<-[$$45, $$60] <- test.DBLP
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/join-singletonbranch-2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/join-singletonbranch-2.plan
index 21d633b..bd3e534 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/join-singletonbranch-2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/join-singletonbranch-2.plan
@@ -1,28 +1,56 @@
+distribute result [$$60]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$60])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$60] <- [{"f": $$53, "b": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$b, $$53])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (lt($$63, $$64))
             -- NESTED_LOOP  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                assign [$$63] <- [$$b.getField("fee")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$b])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (test.Bar)  |PARTITIONED|
+                      data-scan []<-[$$62, $$b] <- test.Bar
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                assign [$$64] <- [$$53.getField("avg")]
                 -- ASSIGN  |UNPARTITIONED|
+                  project ([$$53])
                   -- STREAM_PROJECT  |UNPARTITIONED|
+                    assign [$$53] <- [{"foo_avg": $$65}]
                     -- ASSIGN  |UNPARTITIONED|
+                      aggregate [$$65] <- [agg-global-sql-avg($$67)]
                       -- AGGREGATE  |UNPARTITIONED|
+                        exchange
                         -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                          aggregate [$$67] <- [agg-local-sql-avg($$51)]
                           -- AGGREGATE  |PARTITIONED|
+                            project ([$$51])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$51] <- [$$f.getField("fee")]
                               -- ASSIGN  |PARTITIONED|
+                                project ([$$f])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (test.Foo)  |PARTITIONED|
+                                    data-scan []<-[$$61, $$f] <- test.Foo
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/join-singletonbranch-3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/join-singletonbranch-3.plan
index bb190b0..ff46a94 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/join-singletonbranch-3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/join-singletonbranch-3.plan
@@ -1,23 +1,46 @@
+distribute result [$$60]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$60])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$60] <- [{"f": $$53, "b": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$53, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (lt($$b.getField("fee"), $$65))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$53, $$65, $$b])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.Bar)  |PARTITIONED|
+                data-scan []<-[$$62, $$b] <- test.Bar
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    assign [$$65] <- [$$53.getField("avg")]
                     -- ASSIGN  |UNPARTITIONED|
+                      project ([$$53])
                       -- STREAM_PROJECT  |UNPARTITIONED|
+                        assign [$$53] <- [{"foo_avg": $$63}]
                         -- ASSIGN  |UNPARTITIONED|
+                          aggregate [$$63] <- [agg-global-sql-avg($$67)]
                           -- AGGREGATE  |UNPARTITIONED|
+                            exchange
                             -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                              aggregate [$$67] <- [agg-local-sql-avg($$51)]
                               -- AGGREGATE  |PARTITIONED|
+                                project ([$$51])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  assign [$$51] <- [$$f.getField("fee")]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$f])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (test.Foo)  |PARTITIONED|
+                                        data-scan []<-[$$61, $$f] <- test.Foo
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/join-singletonbranch.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/join-singletonbranch.plan
index de98287..df9b8a5 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/join-singletonbranch.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/join-singletonbranch.plan
@@ -1,28 +1,56 @@
+distribute result [$$49]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$49])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$49] <- [{"b": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (lt($$57, $$58))
             -- NESTED_LOOP  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                assign [$$57] <- [$$b.getField("fee")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$b])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (test.Bar)  |PARTITIONED|
+                      data-scan []<-[$$50, $$b] <- test.Bar
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                project ([$$58])
                 -- STREAM_PROJECT  |UNPARTITIONED|
+                  assign [$$58] <- [get-item($$45, 0)]
                   -- ASSIGN  |UNPARTITIONED|
+                    aggregate [$$45] <- [listify($$52)]
                     -- AGGREGATE  |UNPARTITIONED|
+                      aggregate [$$52] <- [agg-global-sql-avg($$60)]
                       -- AGGREGATE  |UNPARTITIONED|
+                        exchange
                         -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                          aggregate [$$60] <- [agg-local-sql-avg($$42)]
                           -- AGGREGATE  |PARTITIONED|
+                            project ([$$42])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$42] <- [$$55.getField("fee")]
                               -- ASSIGN  |PARTITIONED|
+                                project ([$$55])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (test.Foo)  |PARTITIONED|
+                                    data-scan []<-[$$56, $$55] <- test.Foo
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/join-super-key_01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/join-super-key_01.plan
index 2526adf..264ef8c 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/join-super-key_01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/join-super-key_01.plan
@@ -1,22 +1,44 @@
+distribute result [$$35]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$35])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$35] <- [{"l_partkey": $$37}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$37])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (and(eq($$37, $$39), eq($$42, $$43), eq($$44, $$40)))
             -- HYBRID_HASH_JOIN [$$37, $$42, $$44][$$39, $$43, $$40]  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$37, $$44]  |PARTITIONED|
+                project ([$$37, $$42, $$44])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$44, $$42] <- [$$li.getField(2), $$li.getField(5)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$37, $$li])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (`join-super-key_1`.LineItems)  |PARTITIONED|
+                        data-scan []<-[$$37, $$38, $$li] <- `join-super-key_1`.LineItems
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$39, $$43, $$40])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$43] <- [$$ps.getField(3)]
                   -- ASSIGN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (`join-super-key_1`.PartSupp)  |PARTITIONED|
+                      data-scan []<-[$$39, $$40, $$ps] <- `join-super-key_1`.PartSupp
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/join-super-key_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/join-super-key_02.plan
index 5010ca8..b8aa61f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/join-super-key_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/join-super-key_02.plan
@@ -1,22 +1,44 @@
+distribute result [$$35]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$35])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$35] <- [{"l_partkey": $$39}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$39])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (and(eq($$39, $$37), eq($$42, $$43), eq($$44, $$38)))
             -- HYBRID_HASH_JOIN [$$37, $$43, $$38][$$39, $$42, $$44]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$37, $$43, $$38])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$43] <- [$$ps.getField(3)]
                   -- ASSIGN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (`join-super-key_01`.PartSupp)  |PARTITIONED|
+                      data-scan []<-[$$37, $$38, $$ps] <- `join-super-key_01`.PartSupp
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$39, $$44]  |PARTITIONED|
+                project ([$$39, $$42, $$44])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$44, $$42] <- [$$li.getField(2), $$li.getField(5)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$39, $$li])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (`join-super-key_01`.LineItems)  |PARTITIONED|
+                        data-scan []<-[$$39, $$40, $$li] <- `join-super-key_01`.LineItems
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/joins/fnds_join_ds.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/joins/fnds_join_ds.plan
index a561ca4..d48962f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/joins/fnds_join_ds.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/joins/fnds_join_ds.plan
@@ -1,24 +1,48 @@
+distribute result [$$46]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$46])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$46] <- [{"$1": $$50}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$50] <- [agg-sql-sum($$51)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$51] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                join (eq($$48, $$49))
                 -- HYBRID_HASH_JOIN [$$48][$$49]  |PARTITIONED|
+                  exchange
                   -- HASH_PARTITION_EXCHANGE [$$48]  |PARTITIONED|
+                    project ([$$48])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$48] <- [$$tpcds.getField("ca_address_id")]
                       -- ASSIGN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (asterix.tpcds-datagen.customer_address.1.0)  |PARTITIONED|
+                          data-scan []<-[$$tpcds] <- asterix.tpcds-datagen.customer_address.1.0
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- HASH_PARTITION_EXCHANGE [$$49]  |PARTITIONED|
+                    project ([$$49])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$49] <- [$$t1.getField("aid")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$t1])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (test.t1)  |PARTITIONED|
+                            data-scan []<-[$$47, $$t1] <- test.t1
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                empty-tuple-source
+                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/joins/inner_right_corr.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/joins/inner_right_corr.plan
index 7a7a543..68d409e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/joins/inner_right_corr.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/joins/inner_right_corr.plan
@@ -1,53 +1,100 @@
+distribute result [$$70]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$70])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$70] <- [{"a": $$68}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$68])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- PRE_CLUSTERED_GROUP_BY[$$71]  |PARTITIONED|
-                    {
+            group by ([$$89 := $$71]) decor ([]) {
+                      aggregate [$$68] <- [listify($$73)]
                       -- AGGREGATE  |LOCAL|
+                        aggregate [$$73] <- [agg-sql-count(1)]
                         -- AGGREGATE  |LOCAL|
+                          select (not(is-missing($$88)))
                           -- STREAM_SELECT  |LOCAL|
+                            nested tuple source
                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                    }
+                   }
+            -- PRE_CLUSTERED_GROUP_BY[$$71]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$88, $$71])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    left outer join (eq($$71, $$87))
                     -- HYBRID_HASH_JOIN [$$71][$$87]  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$71])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (test.t1)  |PARTITIONED|
+                            data-scan []<-[$$71, $$t1] <- test.t1
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        assign [$$88] <- [true]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$87])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            unnest $$77 <- scan-collection($$78)
                             -- UNNEST  |PARTITIONED|
+                              project ([$$87, $$78])
                               -- STREAM_PROJECT  |PARTITIONED|
-                                -- SUBPLAN  |PARTITIONED|
-                                        {
+                                subplan {
+                                          aggregate [$$78] <- [listify($$80)]
                                           -- AGGREGATE  |LOCAL|
+                                            select (eq($$82, $$83))
                                             -- STREAM_SELECT  |LOCAL|
+                                              assign [$$83] <- [$$80.getField("b")]
                                               -- ASSIGN  |LOCAL|
+                                                unnest $$80 <- scan-collection($$85)
                                                 -- UNNEST  |LOCAL|
+                                                  nested tuple source
                                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- SUBPLAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    join (true)
                                     -- NESTED_LOOP  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$87, $$85])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$85] <- [$$86.getField("x")]
                                           -- ASSIGN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.t1)  |PARTITIONED|
+                                              data-scan []<-[$$87, $$86] <- test.t1
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                      exchange
                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                        project ([$$82])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$82] <- [$$76.getField("y")]
                                           -- ASSIGN  |PARTITIONED|
+                                            project ([$$76])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- DATASOURCE_SCAN (test.t2)  |PARTITIONED|
+                                                data-scan []<-[$$79, $$76] <- test.t2
+                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/joins/nested_query_with_bcast.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/joins/nested_query_with_bcast.plan
index 15c163d..b80ab96 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/joins/nested_query_with_bcast.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/joins/nested_query_with_bcast.plan
@@ -1,37 +1,71 @@
+commit
 -- COMMIT  |PARTITIONED|
+  project ([$$35])
   -- STREAM_PROJECT  |PARTITIONED|
+    exchange
     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+      insert into test.targetDataset from record: $$37 partitioned by [$$35]
       -- INSERT_DELETE  |PARTITIONED|
+        exchange
         -- HASH_PARTITION_EXCHANGE [$$35]  |PARTITIONED|
+          assign [$$35] <- [$$37.getField(0)]
           -- ASSIGN  |PARTITIONED|
+            project ([$$37])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$37] <- [cast(check-unknown(object-merge-ignore-duplicates($$33, {"tid": create-uuid()})))]
               -- ASSIGN  |PARTITIONED|
+                project ([$$33])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$33] <- [{"$1": object-merge($$x, {"full-country": $$32})}]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$32, $$x])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- PRE_CLUSTERED_GROUP_BY[$$38]  |PARTITIONED|
-                                {
+                        group by ([$$43 := $$38]) decor ([$$x]) {
+                                  aggregate [$$32] <- [listify($$31)]
                                   -- AGGREGATE  |LOCAL|
+                                    select (not(is-missing($$42)))
                                     -- STREAM_SELECT  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                }
+                               }
+                        -- PRE_CLUSTERED_GROUP_BY[$$38]  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$38)
                             -- STABLE_SORT [$$38(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$x, $$31, $$42, $$38])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    left outer join (eq($$39, $$41))
                                     -- HYBRID_HASH_JOIN [$$41][$$39]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        assign [$$41] <- [$$x.getField(1)]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (test.tweetDataset)  |PARTITIONED|
+                                            data-scan []<-[$$38, $$x] <- test.tweetDataset
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                      exchange
                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                        project ([$$31, $$42, $$39])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$42, $$31] <- [true, $$c.getField(1)]
                                           -- ASSIGN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.countryDataset)  |PARTITIONED|
+                                              data-scan []<-[$$39, $$c] <- test.countryDataset
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/joins/nlj_partitioning_property_1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/joins/nlj_partitioning_property_1.plan
index f5d57d5..a2bc155 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/joins/nlj_partitioning_property_1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/joins/nlj_partitioning_property_1.plan
@@ -1,29 +1,58 @@
+distribute result [$$70]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$70])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$70] <- [{"count": $$77}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$77] <- [agg-sql-sum($$79)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$79] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                join (eq($$71, $$73))
                 -- HYBRID_HASH_JOIN [$$71][$$73]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$71])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (tpch.Supplier)  |PARTITIONED|
+                        data-scan []<-[$$71, $$s] <- tpch.Supplier
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    join (true)
                     -- NESTED_LOOP  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$73])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (tpch.Partsupp)  |PARTITIONED|
+                            data-scan []<-[$$72, $$73, $$ps] <- tpch.Partsupp
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      exchange
                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                        project ([])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (tpch.Part)  |PARTITIONED|
+                            data-scan []<-[$$74, $$p] <- tpch.Part
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                empty-tuple-source
+                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/joins/nlj_partitioning_property_2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/joins/nlj_partitioning_property_2.plan
index 4cd1213..4d6a1ab 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/joins/nlj_partitioning_property_2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/joins/nlj_partitioning_property_2.plan
@@ -1,29 +1,58 @@
+distribute result [$$67]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$67])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$67] <- [{"count": $$72}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$72] <- [agg-sql-sum($$73)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$73] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                join (true)
                 -- NESTED_LOOP  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (tpch.Supplier)  |PARTITIONED|
+                        data-scan []<-[$$68, $$s] <- tpch.Supplier
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    join (true)
                     -- NESTED_LOOP  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (tpch.Partsupp)  |PARTITIONED|
+                            data-scan []<-[$$69, $$70, $$ps] <- tpch.Partsupp
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      exchange
                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                        project ([])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (tpch.Part)  |PARTITIONED|
+                            data-scan []<-[$$71, $$p] <- tpch.Part
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/joins/query-ASTERIXDB-2986.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/joins/query-ASTERIXDB-2986.plan
index 4bbdb3e..a9857a8 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/joins/query-ASTERIXDB-2986.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/joins/query-ASTERIXDB-2986.plan
@@ -1,39 +1,78 @@
+distribute result [$$66]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$66])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$66] <- [{"$1": $$76}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$76] <- [agg-sql-sum($$85)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$85] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                join (eq($$74, numeric-add($$82, $$67)))
                 -- NESTED_LOOP  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$67, $$74])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$74] <- [numeric-add($$o.getField("o_custkey"), $$67)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$o, $$67])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            join (eq($$77, $$78))
                             -- HYBRID_HASH_JOIN [$$78][$$77]  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$78]  |PARTITIONED|
+                                assign [$$78] <- [$$o.getField("o_orderkey")]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$o])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test1.orders)  |PARTITIONED|
+                                      data-scan []<-[$$68, $$o, $$69] <- test1.orders
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$77]  |PARTITIONED|
+                                assign [$$77] <- [to-bigint($$67)]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$67])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$67] <- [$$l.getField("l_orderkey")]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$l])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test1.lineitem)  |PARTITIONED|
+                                          data-scan []<-[$$70, $$l, $$71] <- test1.lineitem
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    project ([$$82])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$82] <- [$$c.getField("c_custkey")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$c])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (test1.customer)  |PARTITIONED|
+                            data-scan []<-[$$72, $$c, $$73] <- test1.customer
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                empty-tuple-source
+                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/leftouterjoin/loj-03-no-listify.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/leftouterjoin/loj-03-no-listify.plan
index 6d569dc..c280f04 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/leftouterjoin/loj-03-no-listify.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/leftouterjoin/loj-03-no-listify.plan
@@ -1,127 +1,230 @@
+distribute result [$$240]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$240])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$240] <- [{"taskId": $$taskId, "cnt_all": $$250, "cnt_x": $$267, "cnt_y": $$268, "cnt_z": $$227.getField(0)}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$taskId(ASC) ]  |PARTITIONED|
+          order (ASC, $$taskId)
           -- STABLE_SORT [$$taskId(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$taskId, $$250, $$267, $$268, $$227])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  left outer join (eq($$taskId, $$taskId))
                   -- HYBRID_HASH_JOIN [$$taskId][$$taskId]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$taskId, $$250, $$267, $$268])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          left outer join (eq($$taskId, $$taskId))
                           -- HYBRID_HASH_JOIN [$$taskId][$$taskId]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$taskId, $$250, $$267])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  left outer join (eq($$taskId, $$taskId))
                                   -- HYBRID_HASH_JOIN [$$taskId][$$taskId]  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_MERGE_EXCHANGE MERGE:[$$taskId(ASC)] HASH:[$$taskId]  |PARTITIONED|
-                                      -- SORT_GROUP_BY[$$279]  |PARTITIONED|
-                                              {
+                                      group by ([$$taskId := $$279]) decor ([]) {
+                                                aggregate [$$250] <- [agg-sql-sum($$278)]
                                                 -- AGGREGATE  |LOCAL|
+                                                  nested tuple source
                                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                              }
+                                             }
+                                      -- SORT_GROUP_BY[$$279]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$279]  |PARTITIONED|
-                                          -- SORT_GROUP_BY[$$242]  |PARTITIONED|
-                                                  {
+                                          group by ([$$279 := $$242]) decor ([]) {
+                                                    aggregate [$$278] <- [agg-sql-count(1)]
                                                     -- AGGREGATE  |LOCAL|
+                                                      nested tuple source
                                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                  }
+                                                 }
+                                          -- SORT_GROUP_BY[$$242]  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$242])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$tasks, $$242] <- [$$tasks, $$243]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    replicate
                                                     -- REPLICATE  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        assign [$$243] <- [$$tasks.getField("taskId")]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          project ([$$tasks])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- DATASOURCE_SCAN (test.tasks)  |PARTITIONED|
+                                                              data-scan []<-[$$247, $$tasks] <- test.tasks
+                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  empty-tuple-source
                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$267, $$taskId])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$267] <- [{"taskId": $$taskId, "cnt_x": $$258}.getField(0)]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- SORT_GROUP_BY[$$281]  |PARTITIONED|
-                                                    {
+                                            group by ([$$taskId := $$281]) decor ([]) {
+                                                      aggregate [$$258] <- [agg-sql-sum($$280)]
                                                       -- AGGREGATE  |LOCAL|
+                                                        nested tuple source
                                                         -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                    }
+                                                   }
+                                            -- SORT_GROUP_BY[$$281]  |PARTITIONED|
+                                              exchange
                                               -- HASH_PARTITION_EXCHANGE [$$281]  |PARTITIONED|
-                                                -- SORT_GROUP_BY[$$243]  |PARTITIONED|
-                                                        {
+                                                group by ([$$281 := $$243]) decor ([]) {
+                                                          aggregate [$$280] <- [agg-sql-count(1)]
                                                           -- AGGREGATE  |LOCAL|
+                                                            nested tuple source
                                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                        }
+                                                       }
+                                                -- SORT_GROUP_BY[$$243]  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$$243])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      select (eq($$tasks.getField("status"), "x"))
                                                       -- STREAM_SELECT  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          replicate
                                                           -- REPLICATE  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              assign [$$243] <- [$$tasks.getField("taskId")]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                project ([$$tasks])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (test.tasks)  |PARTITIONED|
+                                                                    data-scan []<-[$$247, $$tasks] <- test.tasks
+                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        empty-tuple-source
                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$268, $$taskId])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$268] <- [{"taskId": $$taskId, "cnt_y": $$259}.getField(0)]
                                 -- ASSIGN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- SORT_GROUP_BY[$$283]  |PARTITIONED|
-                                            {
+                                    group by ([$$taskId := $$283]) decor ([]) {
+                                              aggregate [$$259] <- [agg-sql-sum($$282)]
                                               -- AGGREGATE  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                            }
+                                           }
+                                    -- SORT_GROUP_BY[$$283]  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$283]  |PARTITIONED|
-                                        -- SORT_GROUP_BY[$$244]  |PARTITIONED|
-                                                {
+                                        group by ([$$283 := $$244]) decor ([]) {
+                                                  aggregate [$$282] <- [agg-sql-count(1)]
                                                   -- AGGREGATE  |LOCAL|
+                                                    nested tuple source
                                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                }
+                                               }
+                                        -- SORT_GROUP_BY[$$244]  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$244])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              select (eq($$tasks.getField("status"), "y"))
                                               -- STREAM_SELECT  |PARTITIONED|
+                                                project ([$$tasks, $$244])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$tasks, $$244] <- [$$tasks, $$243]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      replicate
                                                       -- REPLICATE  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          assign [$$243] <- [$$tasks.getField("taskId")]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            project ([$$tasks])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- DATASOURCE_SCAN (test.tasks)  |PARTITIONED|
+                                                                data-scan []<-[$$247, $$tasks] <- test.tasks
+                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    empty-tuple-source
                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$227, $$taskId])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$227] <- [{"taskId": $$taskId, "cnt_z": $$260}]
                         -- ASSIGN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- SORT_GROUP_BY[$$285]  |PARTITIONED|
-                                    {
+                            group by ([$$taskId := $$285]) decor ([]) {
+                                      aggregate [$$260] <- [agg-sql-sum($$284)]
                                       -- AGGREGATE  |LOCAL|
+                                        nested tuple source
                                         -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                    }
+                                   }
+                            -- SORT_GROUP_BY[$$285]  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$285]  |PARTITIONED|
-                                -- SORT_GROUP_BY[$$245]  |PARTITIONED|
-                                        {
+                                group by ([$$285 := $$245]) decor ([]) {
+                                          aggregate [$$284] <- [agg-sql-count(1)]
                                           -- AGGREGATE  |LOCAL|
+                                            nested tuple source
                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- SORT_GROUP_BY[$$245]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$245])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      select (eq($$tasks.getField("status"), "z"))
                                       -- STREAM_SELECT  |PARTITIONED|
+                                        project ([$$tasks, $$245])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$tasks, $$245] <- [$$tasks, $$243]
                                           -- ASSIGN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              replicate
                                               -- REPLICATE  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  assign [$$243] <- [$$tasks.getField("taskId")]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$tasks])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.tasks)  |PARTITIONED|
+                                                        data-scan []<-[$$247, $$tasks] <- test.tasks
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/leftouterjoin/query-ASTERIXDB-2857.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/leftouterjoin/query-ASTERIXDB-2857.plan
index 393f1db..f3f55cd 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/leftouterjoin/query-ASTERIXDB-2857.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/leftouterjoin/query-ASTERIXDB-2857.plan
@@ -1,39 +1,78 @@
+distribute result [$$124]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$124])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$124] <- [{"t0_unique1": $$136, "t1_unique1": $$137, "t2_unique1": $#3}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$136(ASC), $$137(ASC), $#3(ASC) ]  |PARTITIONED|
+          order (ASC, $$136) (ASC, $$137) (ASC, $#3)
           -- STABLE_SORT [$$136(ASC), $$137(ASC), $#3(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$136, $$137, $#3])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  left outer join (eq(numeric-add($$127, $$129), $$134))
                   -- NESTED_LOOP  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$136, $$137, $$127, $$134])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$134] <- [numeric-multiply(2, $$128)]
                         -- ASSIGN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            join (eq($$127, $$128))
                             -- HYBRID_HASH_JOIN [$$127][$$128]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$136, $$127])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  assign [$$136] <- [$$tenk.getField(0)]
                                   -- ASSIGN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                                      unnest-map [$$127, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 0, 1, $$150, true, false, false)
+                                      -- BTREE_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$150] <- [2]
                                           -- ASSIGN  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$137, $$128])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  assign [$$137] <- [$$tenk.getField(0)]
                                   -- ASSIGN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                                      unnest-map [$$128, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 0, 1, $$153, true, false, false)
+                                      -- BTREE_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$153] <- [4]
                                           -- ASSIGN  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                    exchange
                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                      project ([$#3, $$129])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$#3] <- [{"unique1": $$tenk.getField(0), "unique2": $$129}.getField(0)]
                         -- ASSIGN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                            unnest-map [$$129, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 0, 1, $$156, true, false, false)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                assign [$$156] <- [6]
                                 -- ASSIGN  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/leftouterjoin/query-ASTERIXDB-2988.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/leftouterjoin/query-ASTERIXDB-2988.plan
index 96fbf3a..bbf9915 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/leftouterjoin/query-ASTERIXDB-2988.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/leftouterjoin/query-ASTERIXDB-2988.plan
@@ -1,20 +1,40 @@
+distribute result [$$30]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$30])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$30] <- [{"r1": $$r1, "x": $$ds1.getField(0), "y": $$ds1.getField(1)}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$r1(ASC) ]  |PARTITIONED|
+          order (ASC, $$r1)
           -- STABLE_SORT [$$r1(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$r1, $$ds1])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  left outer join (eq($$r1, $$32))
                   -- HYBRID_HASH_JOIN [$$r1][$$32]  |PARTITIONED|
+                    exchange
                     -- HASH_PARTITION_EXCHANGE [$$r1]  |PARTITIONED|
+                      unnest $$r1 <- range(0, 4)
                       -- UNNEST  |UNPARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                    exchange
                     -- HASH_PARTITION_EXCHANGE [$$32]  |PARTITIONED|
+                      assign [$$32] <- [$$ds1.getField(1)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$ds1])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (test.ds1)  |PARTITIONED|
+                            data-scan []<-[$$31, $$ds1] <- test.ds1
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/loj-core.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/loj-core.plan
index 677ef19..ac4a579 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/loj-core.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/loj-core.plan
@@ -1,24 +1,48 @@
+distribute result [$$40]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$40])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$40] <- [{"aid": $$42, "bid": $$b.getField(0)}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$42(ASC) ]  |PARTITIONED|
+          order (ASC, $$42)
           -- STABLE_SORT [$$42(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$42, $$b])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  left outer join (eq($$44, $$45))
                   -- HYBRID_HASH_JOIN [$$44][$$45]  |PARTITIONED|
+                    exchange
                     -- HASH_PARTITION_EXCHANGE [$$44]  |PARTITIONED|
+                      project ([$$42, $$44])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$44] <- [$$a.getField(3)]
                         -- ASSIGN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                            data-scan []<-[$$42, $$a] <- test.DBLP
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                    exchange
                     -- HASH_PARTITION_EXCHANGE [$$45]  |PARTITIONED|
+                      assign [$$45] <- [$$b.getField(3)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$b])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (test.CSX)  |PARTITIONED|
+                            data-scan []<-[$$43, $$b] <- test.CSX
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/loj-core_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/loj-core_ps.plan
index 0061daa..9adfdd0 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/loj-core_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/loj-core_ps.plan
@@ -1,53 +1,106 @@
+distribute result [$$40]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$40])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$40] <- [{"aid": $$42, "bid": $$b.getField(0)}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$42)
           -- STABLE_SORT [$$42(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$42(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$53
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$42, $$b])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          left outer join (eq($$44, $$45))
                           -- HYBRID_HASH_JOIN [$$44][$$45]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$44]  |PARTITIONED|
+                              project ([$$42, $$44])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$44] <- [$$a.getField(3)]
                                 -- ASSIGN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                    data-scan []<-[$$42, $$a] <- test.DBLP
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$45]  |PARTITIONED|
+                              assign [$$45] <- [$$b.getField(3)]
                               -- ASSIGN  |PARTITIONED|
+                                project ([$$b])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (test.CSX)  |PARTITIONED|
+                                    data-scan []<-[$$43, $$b] <- test.CSX
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$53] <- [agg-range-map($$51, $$52)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$51, $$52] <- [agg-local-sampling($$42), agg-null-writer($$42)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$42])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$42, $$b])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    left outer join (eq($$44, $$45))
                                     -- HYBRID_HASH_JOIN [$$44][$$45]  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$44]  |PARTITIONED|
+                                        project ([$$42, $$44])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$44] <- [$$a.getField(3)]
                                           -- ASSIGN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                              data-scan []<-[$$42, $$a] <- test.DBLP
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$45]  |PARTITIONED|
+                                        assign [$$45] <- [$$b.getField(3)]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$b])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.CSX)  |PARTITIONED|
+                                              data-scan []<-[$$43, $$b] <- test.CSX
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/loj-sugar.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/loj-sugar.plan
index 1dd720b..43ab673 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/loj-sugar.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/loj-sugar.plan
@@ -1,24 +1,48 @@
+distribute result [$$31]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$31])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$31] <- [{"aid": $$33, "bid": $$b.getField(0)}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$33(ASC) ]  |PARTITIONED|
+          order (ASC, $$33)
           -- STABLE_SORT [$$33(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$33, $$b])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  left outer join (eq($$35, $$36))
                   -- HYBRID_HASH_JOIN [$$35][$$36]  |PARTITIONED|
+                    exchange
                     -- HASH_PARTITION_EXCHANGE [$$35]  |PARTITIONED|
+                      project ([$$33, $$35])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$35] <- [$$a.getField(3)]
                         -- ASSIGN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                            data-scan []<-[$$33, $$a] <- test.DBLP
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                    exchange
                     -- HASH_PARTITION_EXCHANGE [$$36]  |PARTITIONED|
+                      assign [$$36] <- [$$b.getField(3)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$b])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (test.CSX)  |PARTITIONED|
+                            data-scan []<-[$$34, $$b] <- test.CSX
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/loj-sugar_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/loj-sugar_ps.plan
index d0c36bc..974df30 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/loj-sugar_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/loj-sugar_ps.plan
@@ -1,53 +1,106 @@
+distribute result [$$31]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$31])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$31] <- [{"aid": $$33, "bid": $$b.getField(0)}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$33)
           -- STABLE_SORT [$$33(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$33(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$44
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$33, $$b])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          left outer join (eq($$35, $$36))
                           -- HYBRID_HASH_JOIN [$$35][$$36]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$35]  |PARTITIONED|
+                              project ([$$33, $$35])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$35] <- [$$a.getField(3)]
                                 -- ASSIGN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                    data-scan []<-[$$33, $$a] <- test.DBLP
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$36]  |PARTITIONED|
+                              assign [$$36] <- [$$b.getField(3)]
                               -- ASSIGN  |PARTITIONED|
+                                project ([$$b])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (test.CSX)  |PARTITIONED|
+                                    data-scan []<-[$$34, $$b] <- test.CSX
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$44] <- [agg-range-map($$42, $$43)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$42, $$43] <- [agg-local-sampling($$33), agg-null-writer($$33)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$33])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$33, $$b])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    left outer join (eq($$35, $$36))
                                     -- HYBRID_HASH_JOIN [$$35][$$36]  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$35]  |PARTITIONED|
+                                        project ([$$33, $$35])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$35] <- [$$a.getField(3)]
                                           -- ASSIGN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                              data-scan []<-[$$33, $$a] <- test.DBLP
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$36]  |PARTITIONED|
+                                        assign [$$36] <- [$$b.getField(3)]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$b])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.CSX)  |PARTITIONED|
+                                              data-scan []<-[$$34, $$b] <- test.CSX
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/loj-super-key_01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/loj-super-key_01.plan
index ad0ffd7..cecfa8b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/loj-super-key_01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/loj-super-key_01.plan
@@ -1,30 +1,57 @@
+distribute result [$$45]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$45])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$45] <- [{"li": $$li, "partsupp": $$43}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$43, $$li])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- PRE_CLUSTERED_GROUP_BY[$$46, $$47]  |PARTITIONED|
-                    {
+            group by ([$$57 := $$46; $$58 := $$47]) decor ([$$li]) {
+                      aggregate [$$43] <- [listify($$ps)]
                       -- AGGREGATE  |LOCAL|
+                        select (not(is-missing($$56)))
                         -- STREAM_SELECT  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                    }
+                   }
+            -- PRE_CLUSTERED_GROUP_BY[$$46, $$47]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (ASC, $$46) (ASC, $$47)
                 -- STABLE_SORT [$$46(ASC), $$47(ASC)]  |PARTITIONED|
+                  exchange
                   -- HASH_PARTITION_EXCHANGE [$$46, $$47]  |PARTITIONED|
+                    project ([$$li, $$ps, $$56, $$46, $$47])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        left outer join (and(eq($$50, $$51), eq($$46, $$48), eq($$54, $$49)))
                         -- HYBRID_HASH_JOIN [$$50, $$46, $$54][$$51, $$48, $$49]  |PARTITIONED|
+                          exchange
                           -- HASH_PARTITION_EXCHANGE [$$46, $$54]  |PARTITIONED|
+                            assign [$$54, $$50] <- [$$li.getField(2), $$li.getField(5)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (`loj-super-key_01`.LineItems)  |PARTITIONED|
+                                data-scan []<-[$$46, $$47, $$li] <- `loj-super-key_01`.LineItems
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            assign [$$56, $$51] <- [true, $$ps.getField(3)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (`loj-super-key_01`.PartSupp)  |PARTITIONED|
+                                data-scan []<-[$$48, $$49, $$ps] <- `loj-super-key_01`.PartSupp
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/loj-super-key_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/loj-super-key_02.plan
index b2ca8e1..528d0551 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/loj-super-key_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/loj-super-key_02.plan
@@ -1,31 +1,59 @@
+distribute result [$$45]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$45])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$45] <- [{"partsupp": $$ps, "li": $$43}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$43, $$ps])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- PRE_CLUSTERED_GROUP_BY[$$46, $$47]  |PARTITIONED|
-                    {
+            group by ([$$57 := $$46; $$58 := $$47]) decor ([$$ps]) {
+                      aggregate [$$43] <- [listify($$li)]
                       -- AGGREGATE  |LOCAL|
+                        select (not(is-missing($$56)))
                         -- STREAM_SELECT  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                    }
+                   }
+            -- PRE_CLUSTERED_GROUP_BY[$$46, $$47]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (ASC, $$46) (ASC, $$47)
                 -- STABLE_SORT [$$46(ASC), $$47(ASC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$ps, $$li, $$56, $$46, $$47])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        left outer join (and(eq($$50, $$51), eq($$48, $$46), eq($$54, $$47)))
                         -- HYBRID_HASH_JOIN [$$51, $$46, $$47][$$50, $$48, $$54]  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            assign [$$51] <- [$$ps.getField(3)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (`loj-super-key_02`.PartSupp)  |PARTITIONED|
+                                data-scan []<-[$$46, $$47, $$ps] <- `loj-super-key_02`.PartSupp
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- HASH_PARTITION_EXCHANGE [$$48, $$54]  |PARTITIONED|
+                            assign [$$56, $$54, $$50] <- [true, $$li.getField(2), $$li.getField(5)]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$48, $$li])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (`loj-super-key_02`.LineItems)  |PARTITIONED|
+                                  data-scan []<-[$$48, $$49, $$li] <- `loj-super-key_02`.LineItems
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/field_access_with_data_and_meta_1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/field_access_with_data_and_meta_1.plan
index cdbedfd..1e4367a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/field_access_with_data_and_meta_1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/field_access_with_data_and_meta_1.plan
@@ -1,14 +1,28 @@
+distribute result [$$34]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$34])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$34] <- [{"$1": $$37}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$37] <- [agg-global-sql-max($$38)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$38] <- [agg-local-sql-max($$32)]
             -- AGGREGATE  |PARTITIONED|
+              project ([$$32])
               -- STREAM_PROJECT  |PARTITIONED|
+                assign [$$32] <- [$$36.getField(0)]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$36])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (test.ds)  |PARTITIONED|
+                      data-scan []<-[$$35, $$ds, $$36] <- test.ds
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/field_access_with_data_and_meta_2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/field_access_with_data_and_meta_2.plan
index a23a25f..fa82b0b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/field_access_with_data_and_meta_2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/field_access_with_data_and_meta_2.plan
@@ -1,11 +1,22 @@
+distribute result [$$34]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$34])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$34] <- [{"$1": $$37}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$37] <- [agg-sql-sum($$39)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$39] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- BTREE_SEARCH (test.ds.primary_idx_ds)  |PARTITIONED|
+                unnest-map [$$35] <- index-search("primary_idx_ds", 0, "test", "ds", false, false, 0, 0, true, true, false)
+                -- BTREE_SEARCH  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/field_access_with_data_and_meta_3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/field_access_with_data_and_meta_3.plan
index a23a25f..3869a55 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/field_access_with_data_and_meta_3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/field_access_with_data_and_meta_3.plan
@@ -1,11 +1,22 @@
+distribute result [$$34]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$34])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$34] <- [{"$1": $$37}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$37] <- [agg-sql-sum($$38)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$38] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- BTREE_SEARCH (test.ds.primary_idx_ds)  |PARTITIONED|
+                unnest-map [$$35] <- index-search("primary_idx_ds", 0, "test", "ds", false, false, 0, 0, true, true, false)
+                -- BTREE_SEARCH  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/field_access_with_data_and_meta_4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/field_access_with_data_and_meta_4.plan
index cdbedfd..23a8e97 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/field_access_with_data_and_meta_4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/field_access_with_data_and_meta_4.plan
@@ -1,14 +1,28 @@
+distribute result [$$34]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$34])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$34] <- [{"$1": $$37}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$37] <- [agg-global-sql-max($$39)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$39] <- [agg-local-sql-max($$32)]
             -- AGGREGATE  |PARTITIONED|
+              project ([$$32])
               -- STREAM_PROJECT  |PARTITIONED|
+                assign [$$32] <- [$$ds.getField(0)]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$ds])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (test.ds)  |PARTITIONED|
+                      data-scan []<-[$$35, $$ds, $$36] <- test.ds
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_01.plan
index 2561ec6..b15b9b7 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_01.plan
@@ -1,10 +1,20 @@
+distribute result [$$15]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$15])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$15] <- [{"DS1": $$DS1}]
       -- ASSIGN  |PARTITIONED|
+        select (eq($$DS1.getField(0), "2"))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$DS1])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- DATASOURCE_SCAN (test.DS1)  |PARTITIONED|
+              data-scan []<-[$$16, $$DS1, $$17] <- test.DS1
+              -- DATASOURCE_SCAN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  empty-tuple-source
                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_02.plan
index dad3cdc..b3062ac 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_02.plan
@@ -1,10 +1,20 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"DS1": $$DS1}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$DS1])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- BTREE_SEARCH (test.DS1.DS1)  |PARTITIONED|
+            unnest-map [$$17, $$DS1, $$18] <- index-search("DS1", 0, "test", "DS1", false, false, 1, $$20, 1, $$21, true, true, true)
+            -- BTREE_SEARCH  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                assign [$$20, $$21] <- ["5", "5"]
                 -- ASSIGN  |PARTITIONED|
+                  empty-tuple-source
                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_03.plan
index 0d81837..b734790 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_03.plan
@@ -1,10 +1,20 @@
+distribute result [$$15]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$15])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$15] <- [{"DS2": $$DS2}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$DS2])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- BTREE_SEARCH (test.DS2.DS2)  |PARTITIONED|
+            unnest-map [$$16, $$DS2, $$17] <- index-search("DS2", 0, "test", "DS2", false, false, 1, $$19, 1, $$20, true, true, true)
+            -- BTREE_SEARCH  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                assign [$$19, $$20] <- ["2", "2"]
                 -- ASSIGN  |PARTITIONED|
+                  empty-tuple-source
                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_04.plan
index ef392eb..0e3902e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_04.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_04.plan
@@ -1,11 +1,22 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"DS2": $$DS2}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$DS2])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$18.getField(0), "5"))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$DS2, $$18])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.DS2)  |PARTITIONED|
+                data-scan []<-[$$17, $$DS2, $$18] <- test.DS2
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_05.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_05.plan
index b9b6128..2e04bd9 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_05.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_05.plan
@@ -1,24 +1,48 @@
+distribute result [$$27]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$27])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$27] <- [{"ds2": $$ds2, "ds1": $$ds1}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$ds2, $$ds1])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- SORT_MERGE_EXCHANGE [$$29(ASC) ]  |PARTITIONED|
+            order (ASC, $$29)
             -- STABLE_SORT [$$29(ASC)]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$ds2, $$ds1, $$29])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    join (eq($$29, $$34))
                     -- HYBRID_HASH_JOIN [$$29][$$34]  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$ds2, $$29])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (test.DS2)  |PARTITIONED|
+                            data-scan []<-[$$29, $$ds2, $$30] <- test.DS2
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      exchange
                       -- HASH_PARTITION_EXCHANGE [$$34]  |PARTITIONED|
+                        assign [$$34] <- [$$ds1.getField(0)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$ds1])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (test.DS1)  |PARTITIONED|
+                              data-scan []<-[$$31, $$ds1, $$32] <- test.DS1
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_06.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_06.plan
index 4929664..832c571 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_06.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_06.plan
@@ -1,17 +1,34 @@
+distribute result [$$30]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$30])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$30] <- [{"ds1_meta_id": $$35, "ds2": $$ds2, "ds1": $$ds1}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$35, $$ds2, $$ds1])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- SORT_MERGE_EXCHANGE [$$33(ASC) ]  |PARTITIONED|
+            order (ASC, $$33)
             -- STABLE_SORT [$$33(ASC)]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$35, $$ds2, $$ds1, $$33])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- BTREE_SEARCH (test.DS1.DS1)  |PARTITIONED|
+                    unnest-map [$$35, $$ds1, $$36] <- index-search("DS1", 0, "test", "DS1", true, true, 1, $$33, 1, $$33, true, true, true)
+                    -- BTREE_SEARCH  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$33, $$ds2])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (test.DS2)  |PARTITIONED|
+                            data-scan []<-[$$33, $$ds2, $$34] <- test.DS2
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_07.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_07.plan
index ee856a1..3bd77a6 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_07.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_07.plan
@@ -1,18 +1,36 @@
+distribute result [$$27]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$27])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$27] <- [{"ds1": $$ds1, "ds2": $$ds2}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$ds1, $$ds2])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- SORT_MERGE_EXCHANGE [$$31(ASC) ]  |PARTITIONED|
+            project ([$$ds1, $$ds2, $$31])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- BTREE_SEARCH (test.DS2.DS2)  |PARTITIONED|
+                unnest-map [$$31, $$ds2, $$32] <- index-search("DS2", 0, "test", "DS2", true, true, 1, $$33, 1, $$33, true, true, true)
+                -- BTREE_SEARCH  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    order (ASC, $$33)
                     -- STABLE_SORT [$$33(ASC)]  |PARTITIONED|
+                      exchange
                       -- HASH_PARTITION_EXCHANGE [$$33]  |PARTITIONED|
+                        assign [$$33] <- [$$ds1.getField(0)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$ds1])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (test.DS1)  |PARTITIONED|
+                              data-scan []<-[$$29, $$ds1, $$30] <- test.DS1
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_08.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_08.plan
index dc7178d..cc4c26f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_08.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_08.plan
@@ -1,17 +1,34 @@
+distribute result [$$15]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$15])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$15] <- [{"DS1": $$DS1}]
       -- ASSIGN  |PARTITIONED|
+        select (eq($$DS1.getField(0), "2"))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$DS1])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- BTREE_SEARCH (test.DS1.DS1)  |PARTITIONED|
+              unnest-map [$$16, $$DS1, $$17] <- index-search("DS1", 0, "test", "DS1", false, false, 1, $$22, 1, $$22, true, true, true)
+              -- BTREE_SEARCH  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  order (ASC, $$22)
                   -- STABLE_SORT [$$22(ASC)]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$22])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (test.DS1.id_sec_idx)  |PARTITIONED|
+                          unnest-map [$$21, $$22] <- index-search("id_sec_idx", 0, "test", "DS1", false, false, 1, $$19, 1, $$20, true, true, true)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              assign [$$19, $$20] <- ["2", "2"]
                               -- ASSIGN  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_09.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_09.plan
index dad3cdc..b3062ac 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_09.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_09.plan
@@ -1,10 +1,20 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"DS1": $$DS1}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$DS1])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- BTREE_SEARCH (test.DS1.DS1)  |PARTITIONED|
+            unnest-map [$$17, $$DS1, $$18] <- index-search("DS1", 0, "test", "DS1", false, false, 1, $$20, 1, $$21, true, true, true)
+            -- BTREE_SEARCH  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                assign [$$20, $$21] <- ["5", "5"]
                 -- ASSIGN  |PARTITIONED|
+                  empty-tuple-source
                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_10.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_10.plan
index 514628f..5ce8330 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_10.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_10.plan
@@ -1,24 +1,48 @@
+distribute result [$$27]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$27])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$27] <- [{"ds2": $$ds2, "ds1": $$ds1}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$ds2, $$ds1])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- SORT_MERGE_EXCHANGE [$$29(ASC) ]  |PARTITIONED|
+            order (ASC, $$29)
             -- STABLE_SORT [$$29(ASC)]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                select (eq($$29, $$ds1.getField(0)))
                 -- STREAM_SELECT  |PARTITIONED|
+                  project ([$$ds2, $$29, $$ds1])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (test.DS1.DS1)  |PARTITIONED|
+                      unnest-map [$$31, $$ds1, $$32] <- index-search("DS1", 0, "test", "DS1", true, false, 1, $$37, 1, $$37, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$37)
                           -- STABLE_SORT [$$37(ASC)]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$ds2, $$29, $$37])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.DS1.id_sec_idx)  |PARTITIONED|
+                                  unnest-map [$$36, $$37] <- index-search("id_sec_idx", 0, "test", "DS1", true, true, 1, $$29, 1, $$29, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                      project ([$$29, $$ds2])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.DS2)  |PARTITIONED|
+                                          data-scan []<-[$$29, $$ds2, $$30] <- test.DS2
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_11.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_11.plan
index 4929664..832c571 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_11.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/indexes_on_dataset_with_meta_11.plan
@@ -1,17 +1,34 @@
+distribute result [$$30]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$30])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$30] <- [{"ds1_meta_id": $$35, "ds2": $$ds2, "ds1": $$ds1}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$35, $$ds2, $$ds1])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- SORT_MERGE_EXCHANGE [$$33(ASC) ]  |PARTITIONED|
+            order (ASC, $$33)
             -- STABLE_SORT [$$33(ASC)]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$35, $$ds2, $$ds1, $$33])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- BTREE_SEARCH (test.DS1.DS1)  |PARTITIONED|
+                    unnest-map [$$35, $$ds1, $$36] <- index-search("DS1", 0, "test", "DS1", true, true, 1, $$33, 1, $$33, true, true, true)
+                    -- BTREE_SEARCH  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$33, $$ds2])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (test.DS2)  |PARTITIONED|
+                            data-scan []<-[$$33, $$ds2, $$34] <- test.DS2
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/with_clause_meta.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/with_clause_meta.plan
index d0bcfb4..6caecd2 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/with_clause_meta.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/meta/with_clause_meta.plan
@@ -1,44 +1,85 @@
+distribute result [$$110]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    limit 5
     -- STREAM_LIMIT  |UNPARTITIONED|
+      project ([$$110])
       -- STREAM_PROJECT  |PARTITIONED|
+        assign [$$110] <- [{"age": $$119, "aid": $#1, "total": $$116}]
         -- ASSIGN  |PARTITIONED|
+          exchange
           -- SORT_MERGE_EXCHANGE [$#1(ASC) ]  |PARTITIONED|
+            limit 5
             -- STREAM_LIMIT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (topK: 5) (ASC, $#1)
                 -- STABLE_SORT [topK: 5] [$#1(ASC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$119, $#1, $$116])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$119, $#1] <- [$$112.getField("age"), $$112.getField(0)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$116, $$112])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$112] <- [$$t2.getField(0)]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$116, $$t2])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              unnest $$t2 <- scan-collection($$102)
                               -- UNNEST  |PARTITIONED|
+                                project ([$$102, $$116])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- PRE_CLUSTERED_GROUP_BY[$$111]  |PARTITIONED|
-                                            {
+                                    group by ([$$series := $$111]) decor ([]) {
+                                              aggregate [$$102, $$116] <- [listify($$100), agg-sql-count($$100)]
                                               -- AGGREGATE  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                            }
+                                           }
+                                    -- PRE_CLUSTERED_GROUP_BY[$$111]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        order (ASC, $$111)
                                         -- STABLE_SORT [$$111(ASC)]  |PARTITIONED|
+                                          exchange
                                           -- HASH_PARTITION_EXCHANGE [$$111]  |PARTITIONED|
+                                            project ([$$100, $$111])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$100, $$111] <- [{"raw_data": $$98}, $$98.getField("series")]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$98])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$98] <- [{"aid": $$117, "age": $$118}]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$117, $$118])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        join (eq($$115, $$92))
                                                         -- HYBRID_HASH_JOIN [$$92][$$115]  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            project ([$$117, $$118, $$92])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$118, $$117, $$92] <- [$$a.getField("age"), $$114.getField(0), $$a.getField("hobby")]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                project ([$$a, $$114])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (test.ds)  |PARTITIONED|
+                                                                    data-scan []<-[$$113, $$a, $$114] <- test.ds
+                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        empty-tuple-source
                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                          exchange
                                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                            unnest $$115 <- scan-collection(array: [ "soccer", "reading", "hiking", "tennis" ])
                                                             -- UNNEST  |UNPARTITIONED|
+                                                              empty-tuple-source
                                                               -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/micro_external_sort/micro_external_sort.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/micro_external_sort/micro_external_sort.plan
index 4f8ff43..9d4491c 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/micro_external_sort/micro_external_sort.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/micro_external_sort/micro_external_sort.plan
@@ -1,27 +1,48 @@
+distribute result [$$153]
 -- DISTRIBUTE_RESULT  |LOCAL|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+    project ([$$153])
     -- STREAM_PROJECT  |LOCAL|
+      assign [$$153] <- [{"group": $$group, "sum_per_group": $$152}]
       -- ASSIGN  |LOCAL|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-          -- PRE_CLUSTERED_GROUP_BY[$$145]  |LOCAL|
-                  {
+          group by ([$$group := $$154]) decor ([]) {
+                    aggregate [$$152] <- [listify({"group_num": $$group_num, "sum": $$158})]
                     -- AGGREGATE  |LOCAL|
-                      -- MICRO_STABLE_SORT [$$149(ASC)]  |LOCAL|
-                        -- MICRO_PRE_CLUSTERED_GROUP_BY[$$146]  |LOCAL|
-                                {
+                      order (ASC, $$158)
+                      -- MICRO_STABLE_SORT [$$158(ASC)]  |LOCAL|
+                        group by ([$$group_num := $$155]) decor ([]) {
+                                  aggregate [$$158] <- [agg-global-sql-sum($$165)]
                                   -- AGGREGATE  |LOCAL|
+                                    aggregate [$$165] <- [agg-local-sql-sum($$148)]
                                     -- AGGREGATE  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                }
-                          -- MICRO_STABLE_SORT [$$146(ASC)]  |LOCAL|
+                               }
+                        -- MICRO_PRE_CLUSTERED_GROUP_BY[$$155]  |LOCAL|
+                          order (ASC, $$155)
+                          -- MICRO_STABLE_SORT [$$155(ASC)]  |LOCAL|
+                            assign [$$148] <- [$$134.getField(3)]
                             -- ASSIGN  |LOCAL|
+                              nested tuple source
                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- PRE_CLUSTERED_GROUP_BY[$$154]  |LOCAL|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-              -- STABLE_SORT [$$145(ASC)]  |LOCAL|
+              order (ASC, $$154)
+              -- STABLE_SORT [$$154(ASC)]  |LOCAL|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                  project ([$$155, $$134, $$154])
                   -- STREAM_PROJECT  |UNPARTITIONED|
+                    assign [$$154, $$155, $$134] <- [switch-case(true, eq(0, $$166), "one", eq(1, $$166), "two", eq(2, $$166), "three", null), switch-case(true, eq(0, $$167), "SUM_1s", eq(1, $$167), "SUM_2s", eq(2, $$167), "SUM_3s", null), {"id": $$i, "a": switch-case(true, eq(0, $$166), "one", eq(1, $$166), "two", eq(2, $$166), "three", null), "b": switch-case(true, eq(0, $$167), "SUM_1s", eq(1, $$167), "SUM_2s", eq(2, $$167), "SUM_3s", null), "c": switch-case(true, eq(0, $$167), 1, eq(1, $$167), 2, eq(2, $$167), 3, null)}]
                     -- ASSIGN  |UNPARTITIONED|
+                      assign [$$167, $$166] <- [numeric-mod(numeric-div($$i, 3), 3), numeric-mod($$i, 3)]
                       -- ASSIGN  |UNPARTITIONED|
+                        unnest $$i <- range(0, 89999)
                         -- UNNEST  |UNPARTITIONED|
-                          -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
\ No newline at end of file
+                          empty-tuple-source
+                          -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/multipart-dataverse/index/index-01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/multipart-dataverse/index/index-01.plan
index ddb70e2..e838f6a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/multipart-dataverse/index/index-01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/multipart-dataverse/index/index-01.plan
@@ -1,15 +1,30 @@
+distribute result [$$l]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (and(eq($$l.getField(1), "Julio"), eq($$l.getField(2), "Isa")))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$l])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (x.y.employee.employee)  |PARTITIONED|
+          unnest-map [$$17, $$l] <- index-search("employee", 0, "x/y", "employee", false, false, 1, $$26, 1, $$26, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$26)
               -- STABLE_SORT [$$26(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$26])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (x.y.employee.idx_employee_f_l_name)  |PARTITIONED|
+                      unnest-map [$$24, $$25, $$26] <- index-search("idx_employee_f_l_name", 0, "x/y", "employee", false, false, 2, $$20, $$21, 2, $$22, $$23, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$20, $$21, $$22, $$23] <- ["Julio", "Isa", "Julio", "Isa"]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/multipart-dataverse/index/index-02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/multipart-dataverse/index/index-02.plan
index ddb70e2..e838f6a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/multipart-dataverse/index/index-02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/multipart-dataverse/index/index-02.plan
@@ -1,15 +1,30 @@
+distribute result [$$l]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (and(eq($$l.getField(1), "Julio"), eq($$l.getField(2), "Isa")))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$l])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (x.y.employee.employee)  |PARTITIONED|
+          unnest-map [$$17, $$l] <- index-search("employee", 0, "x/y", "employee", false, false, 1, $$26, 1, $$26, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$26)
               -- STABLE_SORT [$$26(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$26])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (x.y.employee.idx_employee_f_l_name)  |PARTITIONED|
+                      unnest-map [$$24, $$25, $$26] <- index-search("idx_employee_f_l_name", 0, "x/y", "employee", false, false, 2, $$20, $$21, 2, $$22, $$23, true, true, true)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$20, $$21, $$22, $$23] <- ["Julio", "Isa", "Julio", "Isa"]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/btree-index-join/ASTERIXDB-2199.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/btree-index-join/ASTERIXDB-2199.plan
index 1df1923..878b693 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/btree-index-join/ASTERIXDB-2199.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/btree-index-join/ASTERIXDB-2199.plan
@@ -1,15 +1,30 @@
+distribute result [$$33]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$33])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$33] <- [{"first": $$first, "second": $$second}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$first, $$second])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$34, $$35))
             -- HYBRID_HASH_JOIN [$$34][$$35]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (Facebook.Friendship)  |PARTITIONED|
+                data-scan []<-[$$34, $$first] <- Facebook.Friendship
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (Facebook.Friendship)  |PARTITIONED|
+                data-scan []<-[$$35, $$second] <- Facebook.Friendship
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_ps.plan
index 8fd6f04..bb487e5 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_ps.plan
@@ -1,86 +1,166 @@
+distribute result [$$47]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$47])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$47] <- [{"tweetid1": $$50, "count1": $$56, "t2info": $$46}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$46, $$50, $$56])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            order (ASC, $$65)
             -- STABLE_SORT [$$65(ASC)]  |PARTITIONED|
+              exchange
               -- RANGE_PARTITION_EXCHANGE [$$65(ASC)]  |PARTITIONED|
+                forward: shared-variable = $$73
                 -- FORWARD  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- PRE_CLUSTERED_GROUP_BY[$$52]  |PARTITIONED|
-                                {
+                        group by ([$$65 := $$52]) decor ([$$50; $$56]) {
+                                  aggregate [$$46] <- [listify({"tweetid2": $$59, "count2": $$57})]
                                   -- AGGREGATE  |LOCAL|
+                                    select (not(is-missing($$53)))
                                     -- STREAM_SELECT  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                }
+                               }
+                        -- PRE_CLUSTERED_GROUP_BY[$$52]  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$52) (ASC, $$53)
                             -- STABLE_SORT [$$52(ASC), $$53(ASC)]  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$52]  |PARTITIONED|
+                                select (eq($$56, $$57)) retain-untrue ($$53 <- MISSING)
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  project ([$$50, $$56, $$52, $$53, $$59, $$57])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$59, $$57] <- [$$55.getField(0), $$55.getField(7)]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$50, $$56, $$52, $$53, $$55])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$55] <- [$$t2.getField(0)]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$50, $$56, $$52, $$53, $$t2])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                              left-outer-unnest-map [$$53, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$70, 1, $$70, true, true, true)
+                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  order (ASC, $$70)
                                                   -- STABLE_SORT [$$70(ASC)]  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      project ([$$50, $$56, $$52, $$70])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                                          left-outer-unnest-map [$$69, $$70] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$56, 1, $$56, true, true, true)
+                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                            exchange
                                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                              project ([$$52, $$56, $$50])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$56, $$50] <- [$$63.getField(6), $$63.getField(0)]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  project ([$$52, $$63])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    assign [$$63] <- [$$t1.getField(0)]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                        unnest-map [$$52, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$66, true, false, false)
+                                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            assign [$$66] <- [10]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              empty-tuple-source
                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    aggregate [$$73] <- [agg-range-map($$71, $$72)]
                     -- AGGREGATE  |UNPARTITIONED|
+                      exchange
                       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                        aggregate [$$71, $$72] <- [agg-local-sampling($$65), agg-null-writer($$65)]
                         -- AGGREGATE  |PARTITIONED|
+                          project ([$$65])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              replicate
                               -- REPLICATE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- PRE_CLUSTERED_GROUP_BY[$$52]  |PARTITIONED|
-                                          {
+                                  group by ([$$65 := $$52]) decor ([$$50; $$56]) {
+                                            aggregate [$$46] <- [listify({"tweetid2": $$59, "count2": $$57})]
                                             -- AGGREGATE  |LOCAL|
+                                              select (not(is-missing($$53)))
                                               -- STREAM_SELECT  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                         }
+                                  -- PRE_CLUSTERED_GROUP_BY[$$52]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$52) (ASC, $$53)
                                       -- STABLE_SORT [$$52(ASC), $$53(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$52]  |PARTITIONED|
+                                          select (eq($$56, $$57)) retain-untrue ($$53 <- MISSING)
                                           -- STREAM_SELECT  |PARTITIONED|
+                                            project ([$$50, $$56, $$52, $$53, $$59, $$57])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$59, $$57] <- [$$55.getField(0), $$55.getField(7)]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$50, $$56, $$52, $$53, $$55])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$55] <- [$$t2.getField(0)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$50, $$56, $$52, $$53, $$t2])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                        left-outer-unnest-map [$$53, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$70, 1, $$70, true, true, true)
+                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            order (ASC, $$70)
                                                             -- STABLE_SORT [$$70(ASC)]  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                project ([$$50, $$56, $$52, $$70])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                                                    left-outer-unnest-map [$$69, $$70] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$56, 1, $$56, true, true, true)
+                                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                                      exchange
                                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                        project ([$$52, $$56, $$50])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          assign [$$56, $$50] <- [$$63.getField(6), $$63.getField(0)]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            project ([$$52, $$63])
                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                              assign [$$63] <- [$$t1.getField(0)]
                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                  -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                                  unnest-map [$$52, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$66, true, false, false)
+                                                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                                                    exchange
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                      assign [$$66] <- [10]
                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                        empty-tuple-source
                                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_ps.plan
index 9857dae..993287f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_ps.plan
@@ -1,86 +1,166 @@
+distribute result [$$53]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$53])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$53] <- [{"tweetid1": $$65, "count1": $$71, "t2info": $$52}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$52, $$65, $$71])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            order (ASC, $$73)
             -- STABLE_SORT [$$73(ASC)]  |PARTITIONED|
+              exchange
               -- RANGE_PARTITION_EXCHANGE [$$73(ASC)]  |PARTITIONED|
+                forward: shared-variable = $$81
                 -- FORWARD  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- PRE_CLUSTERED_GROUP_BY[$$58]  |PARTITIONED|
-                                {
+                        group by ([$$73 := $$58]) decor ([$$65; $$71]) {
+                                  aggregate [$$52] <- [listify({"tweetid2": $$66, "count2": $$64})]
                                   -- AGGREGATE  |LOCAL|
+                                    select (not(is-missing($$59)))
                                     -- STREAM_SELECT  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                }
+                               }
+                        -- PRE_CLUSTERED_GROUP_BY[$$58]  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$58) (ASC, $$59)
                             -- STABLE_SORT [$$58(ASC), $$59(ASC)]  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$58]  |PARTITIONED|
+                                select (and(eq($$71, $$64), neq($$65, $$66))) retain-untrue ($$59 <- MISSING)
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  project ([$$65, $$71, $$58, $$59, $$66, $$64])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$66, $$64] <- [$$62.getField(0), $$62.getField(7)]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$65, $$71, $$58, $$59, $$62])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$62] <- [$$t2.getField(0)]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$65, $$71, $$58, $$59, $$t2])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                              left-outer-unnest-map [$$59, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$78, 1, $$78, true, true, true)
+                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  order (ASC, $$78)
                                                   -- STABLE_SORT [$$78(ASC)]  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      project ([$$65, $$71, $$58, $$78])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                                          left-outer-unnest-map [$$77, $$78] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$71, 1, $$71, true, true, true)
+                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                            exchange
                                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                              project ([$$58, $$71, $$65])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$71, $$65] <- [$$60.getField(6), $$60.getField(0)]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  project ([$$58, $$60])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    assign [$$60] <- [$$t1.getField(0)]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                        unnest-map [$$58, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$74, true, false, false)
+                                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            assign [$$74] <- [10]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              empty-tuple-source
                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    aggregate [$$81] <- [agg-range-map($$79, $$80)]
                     -- AGGREGATE  |UNPARTITIONED|
+                      exchange
                       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                        aggregate [$$79, $$80] <- [agg-local-sampling($$73), agg-null-writer($$73)]
                         -- AGGREGATE  |PARTITIONED|
+                          project ([$$73])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              replicate
                               -- REPLICATE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- PRE_CLUSTERED_GROUP_BY[$$58]  |PARTITIONED|
-                                          {
+                                  group by ([$$73 := $$58]) decor ([$$65; $$71]) {
+                                            aggregate [$$52] <- [listify({"tweetid2": $$66, "count2": $$64})]
                                             -- AGGREGATE  |LOCAL|
+                                              select (not(is-missing($$59)))
                                               -- STREAM_SELECT  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                         }
+                                  -- PRE_CLUSTERED_GROUP_BY[$$58]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$58) (ASC, $$59)
                                       -- STABLE_SORT [$$58(ASC), $$59(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$58]  |PARTITIONED|
+                                          select (and(eq($$71, $$64), neq($$65, $$66))) retain-untrue ($$59 <- MISSING)
                                           -- STREAM_SELECT  |PARTITIONED|
+                                            project ([$$65, $$71, $$58, $$59, $$66, $$64])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$66, $$64] <- [$$62.getField(0), $$62.getField(7)]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$65, $$71, $$58, $$59, $$62])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$62] <- [$$t2.getField(0)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$65, $$71, $$58, $$59, $$t2])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                        left-outer-unnest-map [$$59, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$78, 1, $$78, true, true, true)
+                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            order (ASC, $$78)
                                                             -- STABLE_SORT [$$78(ASC)]  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                project ([$$65, $$71, $$58, $$78])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                                                    left-outer-unnest-map [$$77, $$78] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$71, 1, $$71, true, true, true)
+                                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                                      exchange
                                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                        project ([$$58, $$71, $$65])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          assign [$$71, $$65] <- [$$60.getField(6), $$60.getField(0)]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            project ([$$58, $$60])
                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                              assign [$$60] <- [$$t1.getField(0)]
                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                  -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                                  unnest-map [$$58, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$74, true, false, false)
+                                                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                                                    exchange
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                      assign [$$74] <- [10]
                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                        empty-tuple-source
                                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/ngram-contains-panic_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/ngram-contains-panic_ps.plan
index 5a051c1..fd8b566 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/ngram-contains-panic_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/ngram-contains-panic_ps.plan
@@ -1,28 +1,56 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$o])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$17)
         -- STABLE_SORT [$$17(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$17(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$23
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (contains($$o.getField(0).getField(2), "Mu"))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                        data-scan []<-[$$17, $$o] <- test.DBLP
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$23] <- [agg-range-map($$21, $$22)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$21, $$22] <- [agg-local-sampling($$17), agg-null-writer($$17)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$17])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (contains($$o.getField(0).getField(2), "Mu"))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                  data-scan []<-[$$17, $$o] <- test.DBLP
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/ngram-contains_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/ngram-contains_ps.plan
index e0dd2e4..3e82f66 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/ngram-contains_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/ngram-contains_ps.plan
@@ -1,38 +1,76 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$o])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$17)
         -- STABLE_SORT [$$17(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$17(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$25
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (contains($$o.getField(0).getField(2), "Multimedia"))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                        unnest-map [$$17, $$o] <- index-search("DBLP", 0, "test", "DBLP", false, false, 1, $$22, 1, $$22, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$22)
                             -- STABLE_SORT [$$22(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                                unnest-map [$$22] <- index-search("ngram_index", 5, "test", "DBLP", false, false, 0, missing, 12, false, 1, $$21)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    assign [$$21] <- ["Multimedia"]
                                     -- ASSIGN  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$25] <- [agg-range-map($$23, $$24)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$23, $$24] <- [agg-local-sampling($$17), agg-null-writer($$17)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$17])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (contains($$o.getField(0).getField(2), "Multimedia"))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                                  unnest-map [$$17, $$o] <- index-search("DBLP", 0, "test", "DBLP", false, false, 1, $$22, 1, $$22, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$22)
                                       -- STABLE_SORT [$$22(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                                          unnest-map [$$22] <- index-search("ngram_index", 5, "test", "DBLP", false, false, 0, missing, 12, false, 1, $$21)
+                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$21] <- ["Multimedia"]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/olist-edit-distance-check-panic_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/olist-edit-distance-check-panic_ps.plan
index bd53553..9caa4be 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/olist-edit-distance-check-panic_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/olist-edit-distance-check-panic_ps.plan
@@ -1,28 +1,56 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$c])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$19)
         -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$19(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$25
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (get-item(edit-distance-check($$c.getField(0).getField(4), array: [ "computers", "wine", "walking" ], 3), 0))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                        data-scan []<-[$$19, $$c] <- test.Customers
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$25] <- [agg-range-map($$23, $$24)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$23, $$24] <- [agg-local-sampling($$19), agg-null-writer($$19)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$19])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (get-item(edit-distance-check($$c.getField(0).getField(4), array: [ "computers", "wine", "walking" ], 3), 0))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                  data-scan []<-[$$19, $$c] <- test.Customers
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/olist-edit-distance-check_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/olist-edit-distance-check_ps.plan
index 6e8c23d..8c6108f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/olist-edit-distance-check_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/olist-edit-distance-check_ps.plan
@@ -1,38 +1,76 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$c])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$19)
         -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$19(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$27
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (get-item(edit-distance-check($$c.getField(0).getField(4), array: [ "computers", "wine", "walking" ], 1), 0))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                        unnest-map [$$19, $$c] <- index-search("Customers", 0, "test", "Customers", false, false, 1, $$24, 1, $$24, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$24)
                             -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                unnest-map [$$24] <- index-search("interests_index", 4, "test", "Customers", false, false, 2, 1, 21, false, 1, $$23)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    assign [$$23] <- [array: [ "computers", "wine", "walking" ]]
                                     -- ASSIGN  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$27] <- [agg-range-map($$25, $$26)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$25, $$26] <- [agg-local-sampling($$19), agg-null-writer($$19)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$19])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (get-item(edit-distance-check($$c.getField(0).getField(4), array: [ "computers", "wine", "walking" ], 1), 0))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                                  unnest-map [$$19, $$c] <- index-search("Customers", 0, "test", "Customers", false, false, 1, $$24, 1, $$24, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$24)
                                       -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                          unnest-map [$$24] <- index-search("interests_index", 4, "test", "Customers", false, false, 2, 1, 21, false, 1, $$23)
+                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$23] <- [array: [ "computers", "wine", "walking" ]]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/olist-edit-distance-panic_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/olist-edit-distance-panic_ps.plan
index bd53553..9caa4be 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/olist-edit-distance-panic_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/olist-edit-distance-panic_ps.plan
@@ -1,28 +1,56 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$c])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$19)
         -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$19(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$25
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (get-item(edit-distance-check($$c.getField(0).getField(4), array: [ "computers", "wine", "walking" ], 3), 0))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                        data-scan []<-[$$19, $$c] <- test.Customers
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$25] <- [agg-range-map($$23, $$24)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$23, $$24] <- [agg-local-sampling($$19), agg-null-writer($$19)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$19])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (get-item(edit-distance-check($$c.getField(0).getField(4), array: [ "computers", "wine", "walking" ], 3), 0))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                  data-scan []<-[$$19, $$c] <- test.Customers
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/olist-edit-distance_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/olist-edit-distance_ps.plan
index 6e8c23d..8c6108f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/olist-edit-distance_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/olist-edit-distance_ps.plan
@@ -1,38 +1,76 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$c])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$19)
         -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$19(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$27
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (get-item(edit-distance-check($$c.getField(0).getField(4), array: [ "computers", "wine", "walking" ], 1), 0))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                        unnest-map [$$19, $$c] <- index-search("Customers", 0, "test", "Customers", false, false, 1, $$24, 1, $$24, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$24)
                             -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                unnest-map [$$24] <- index-search("interests_index", 4, "test", "Customers", false, false, 2, 1, 21, false, 1, $$23)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    assign [$$23] <- [array: [ "computers", "wine", "walking" ]]
                                     -- ASSIGN  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$27] <- [agg-range-map($$25, $$26)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$25, $$26] <- [agg-local-sampling($$19), agg-null-writer($$19)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$19])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (get-item(edit-distance-check($$c.getField(0).getField(4), array: [ "computers", "wine", "walking" ], 1), 0))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                                  unnest-map [$$19, $$c] <- index-search("Customers", 0, "test", "Customers", false, false, 1, $$24, 1, $$24, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$24)
                                       -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                          unnest-map [$$24] <- index-search("interests_index", 4, "test", "Customers", false, false, 2, 1, 21, false, 1, $$23)
+                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$23] <- [array: [ "computers", "wine", "walking" ]]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/olist-fuzzyeq-edit-distance_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/olist-fuzzyeq-edit-distance_ps.plan
index d2b7dc5..f91c2cd 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/olist-fuzzyeq-edit-distance_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/olist-fuzzyeq-edit-distance_ps.plan
@@ -1,38 +1,76 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$c])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$18)
         -- STABLE_SORT [$$18(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$18(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$26
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (get-item(edit-distance-check($$c.getField(0).getField(4), array: [ "computers", "wine", "walking" ], 1), 0))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                        unnest-map [$$18, $$c] <- index-search("Customers", 0, "test", "Customers", false, false, 1, $$23, 1, $$23, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$23)
                             -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                unnest-map [$$23] <- index-search("interests_index", 4, "test", "Customers", false, false, 2, 1, 21, false, 1, $$22)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    assign [$$22] <- [array: [ "computers", "wine", "walking" ]]
                                     -- ASSIGN  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$26] <- [agg-range-map($$24, $$25)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$24, $$25] <- [agg-local-sampling($$18), agg-null-writer($$18)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$18])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (get-item(edit-distance-check($$c.getField(0).getField(4), array: [ "computers", "wine", "walking" ], 1), 0))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                                  unnest-map [$$18, $$c] <- index-search("Customers", 0, "test", "Customers", false, false, 1, $$23, 1, $$23, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$23)
                                       -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                          unnest-map [$$23] <- index-search("interests_index", 4, "test", "Customers", false, false, 2, 1, 21, false, 1, $$22)
+                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$22] <- [array: [ "computers", "wine", "walking" ]]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/word-contains_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/word-contains_ps.plan
index 5a051c1..06cbf5e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/word-contains_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-basic/word-contains_ps.plan
@@ -1,28 +1,56 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$o])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$17)
         -- STABLE_SORT [$$17(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$17(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$23
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (contains($$o.getField(0).getField(2), "Multimedia"))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                        data-scan []<-[$$17, $$o] <- test.DBLP
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$23] <- [agg-range-map($$21, $$22)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$21, $$22] <- [agg-local-sampling($$17), agg-null-writer($$17)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$17])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (contains($$o.getField(0).getField(2), "Multimedia"))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                  data-scan []<-[$$17, $$o] <- test.DBLP
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-complex/olist-edit-distance-check-let-panic_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-complex/olist-edit-distance-check-let-panic_ps.plan
index b45a5fcb..0d125d8 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-complex/olist-edit-distance-check-let-panic_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-complex/olist-edit-distance-check-let-panic_ps.plan
@@ -1,28 +1,56 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$c])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$29)
         -- STABLE_SORT [$$29(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$29(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$35
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (get-item(edit-distance-check($$c.getField(0).getField(4), array: [ "computers", "wine", "walking" ], 3), 0))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                        data-scan []<-[$$29, $$c] <- test.Customers
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$35] <- [agg-range-map($$33, $$34)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$33, $$34] <- [agg-local-sampling($$29), agg-null-writer($$29)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$29])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (get-item(edit-distance-check($$c.getField(0).getField(4), array: [ "computers", "wine", "walking" ], 3), 0))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                  data-scan []<-[$$29, $$c] <- test.Customers
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-complex/olist-edit-distance-check-let_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-complex/olist-edit-distance-check-let_ps.plan
index 4dfcd7a..7476984 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-complex/olist-edit-distance-check-let_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-complex/olist-edit-distance-check-let_ps.plan
@@ -1,38 +1,76 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$c])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$29)
         -- STABLE_SORT [$$29(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$29(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$37
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (get-item(edit-distance-check($$c.getField(0).getField(4), array: [ "computers", "wine", "walking" ], 1), 0))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                        unnest-map [$$29, $$c] <- index-search("Customers", 0, "test", "Customers", false, false, 1, $$34, 1, $$34, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$34)
                             -- STABLE_SORT [$$34(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                unnest-map [$$34] <- index-search("interests_index", 4, "test", "Customers", false, false, 2, 1, 21, false, 1, $$33)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    assign [$$33] <- [array: [ "computers", "wine", "walking" ]]
                                     -- ASSIGN  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$37] <- [agg-range-map($$35, $$36)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$35, $$36] <- [agg-local-sampling($$29), agg-null-writer($$29)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$29])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (get-item(edit-distance-check($$c.getField(0).getField(4), array: [ "computers", "wine", "walking" ], 1), 0))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.Customers.Customers)  |PARTITIONED|
+                                  unnest-map [$$29, $$c] <- index-search("Customers", 0, "test", "Customers", false, false, 1, $$34, 1, $$34, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$34)
                                       -- STABLE_SORT [$$34(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.Customers.interests_index)  |PARTITIONED|
+                                          unnest-map [$$34] <- index-search("interests_index", 4, "test", "Customers", false, false, 2, 1, 21, false, 1, $$33)
+                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$33] <- [array: [ "computers", "wine", "walking" ]]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01_ps.plan
index 8b6b284..e0bc376 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01_ps.plan
@@ -1,190 +1,374 @@
+distribute result [$$66]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$66])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$66] <- [{"tweet": {"id": $$77, "topics": $$84}, "similar-tweets": $$65}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$65, $$84, $$77])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            order (ASC, $$86)
             -- STABLE_SORT [$$86(ASC)]  |PARTITIONED|
+              exchange
               -- RANGE_PARTITION_EXCHANGE [$$86(ASC)]  |PARTITIONED|
+                forward: shared-variable = $$107
                 -- FORWARD  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- PRE_CLUSTERED_GROUP_BY[$$71]  |PARTITIONED|
-                                {
+                        group by ([$$86 := $$71]) decor ([$$84; $$77]) {
+                                  aggregate [$$65] <- [listify({"id": $$76, "topics": $$79})]
                                   -- AGGREGATE  |LOCAL|
+                                    select (not(is-missing($$72)))
                                     -- STREAM_SELECT  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                }
+                               }
+                        -- PRE_CLUSTERED_GROUP_BY[$$71]  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$71) (ASC, $$72)
                             -- STABLE_SORT [$$71(ASC), $$72(ASC)]  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$71]  |PARTITIONED|
+                                project ([$$77, $$84, $$76, $$79, $$72, $$71])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    join (eq($$92, $$71))
                                     -- HYBRID_HASH_JOIN [$$92][$$71]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$77, $$92])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$77] <- [$$t1.getField(0).getField(0)]
                                           -- ASSIGN  |PARTITIONED|
+                                            project ([$$92, $$t1])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$92, $$t1] <- [$$71, $$95]
                                               -- ASSIGN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  replicate
                                                   -- REPLICATE  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                      unnest-map [$$71, $$95] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$96, 0, false, true, false)
+                                                      -- BTREE_SEARCH  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          assign [$$96] <- [240]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$71]  |PARTITIONED|
+                                        union ($$72, $$103, $$72) ($$79, $$99, $$79) ($$76, $$100, $$76) ($$71, $$71, $$71) ($$84, $$84, $$84)
                                         -- UNION_ALL  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$72, $$79, $$76, $$71, $$84])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              select (and(neq($$76, $$93), get-item(edit-distance-check($$84, $$79, 7), 0))) retain-untrue ($$72 <- MISSING)
                                               -- STREAM_SELECT  |PARTITIONED|
+                                                project ([$$71, $$84, $$93, $$72, $$79, $$76])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$79, $$76] <- [$$74.getField(5), $$74.getField(0)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$71, $$84, $$93, $$72, $$74])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      assign [$$74] <- [$$t2.getField(0)]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        project ([$$71, $$84, $$93, $$72, $$t2])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                            left-outer-unnest-map [$$72, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$104, 1, $$104, true, true, true)
+                                                            -- BTREE_SEARCH  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                order (ASC, $$104)
                                                                 -- STABLE_SORT [$$104(ASC)]  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.TweetMessages.msgNgramIx)  |PARTITIONED|
+                                                                    left-outer-unnest-map [$$104] <- index-search("msgNgramIx", 5, "test", "TweetMessages", true, true, 2, 7, 12, false, 1, $$84)
+                                                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                                                      exchange
                                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                        select (edit-distance-string-is-filterable($$84, 7, 3, true))
                                                                         -- STREAM_SELECT  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            replicate
                                                                             -- REPLICATE  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                project ([$$71, $$84, $$93])
                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                  assign [$$84, $$93] <- [$$94.getField(5), $$94.getField(0)]
                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                    project ([$$71, $$94])
                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                      assign [$$94] <- [$$95.getField(0)]
                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                        exchange
                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                          replicate
                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                            exchange
                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                              -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                                              unnest-map [$$71, $$95] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$96, 0, false, true, false)
+                                                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                                                exchange
                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                  assign [$$96] <- [240]
                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                    empty-tuple-source
                                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$103, $$99, $$100, $$71, $$84])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                left outer join (and(neq($$100, $$93), get-item(edit-distance-check($$84, $$99, 7), 0)))
                                                 -- NESTED_LOOP  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$$103, $$99, $$100])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      assign [$$99, $$100] <- [$$101.getField(5), $$101.getField(0)]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        project ([$$103, $$101])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$101] <- [$$102.getField(0)]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- DATASOURCE_SCAN (test.TweetMessages)  |PARTITIONED|
+                                                              data-scan []<-[$$103, $$102] <- test.TweetMessages
+                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  empty-tuple-source
                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                  exchange
                                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                    select (not(edit-distance-string-is-filterable($$84, 7, 3, true)))
                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        replicate
                                                         -- REPLICATE  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            project ([$$71, $$84, $$93])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$84, $$93] <- [$$94.getField(5), $$94.getField(0)]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                project ([$$71, $$94])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  assign [$$94] <- [$$95.getField(0)]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      replicate
                                                                       -- REPLICATE  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                          -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                          unnest-map [$$71, $$95] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$96, 0, false, true, false)
+                                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              assign [$$96] <- [240]
                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                empty-tuple-source
                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    aggregate [$$107] <- [agg-range-map($$105, $$106)]
                     -- AGGREGATE  |UNPARTITIONED|
+                      exchange
                       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                        aggregate [$$105, $$106] <- [agg-local-sampling($$86), agg-null-writer($$86)]
                         -- AGGREGATE  |PARTITIONED|
+                          project ([$$86])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              replicate
                               -- REPLICATE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- PRE_CLUSTERED_GROUP_BY[$$71]  |PARTITIONED|
-                                          {
+                                  group by ([$$86 := $$71]) decor ([$$84; $$77]) {
+                                            aggregate [$$65] <- [listify({"id": $$76, "topics": $$79})]
                                             -- AGGREGATE  |LOCAL|
+                                              select (not(is-missing($$72)))
                                               -- STREAM_SELECT  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                         }
+                                  -- PRE_CLUSTERED_GROUP_BY[$$71]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$71) (ASC, $$72)
                                       -- STABLE_SORT [$$71(ASC), $$72(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$71]  |PARTITIONED|
+                                          project ([$$77, $$84, $$76, $$79, $$72, $$71])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              join (eq($$92, $$71))
                                               -- HYBRID_HASH_JOIN [$$92][$$71]  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  project ([$$77, $$92])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    assign [$$77] <- [$$t1.getField(0).getField(0)]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      project ([$$92, $$t1])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$92, $$t1] <- [$$71, $$95]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            replicate
                                                             -- REPLICATE  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                unnest-map [$$71, $$95] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$96, 0, false, true, false)
+                                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    assign [$$96] <- [240]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      empty-tuple-source
                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$71]  |PARTITIONED|
+                                                  union ($$72, $$103, $$72) ($$79, $$99, $$79) ($$76, $$100, $$76) ($$71, $$71, $$71) ($$84, $$84, $$84)
                                                   -- UNION_ALL  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      project ([$$72, $$79, $$76, $$71, $$84])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        select (and(neq($$76, $$93), get-item(edit-distance-check($$84, $$79, 7), 0))) retain-untrue ($$72 <- MISSING)
                                                         -- STREAM_SELECT  |PARTITIONED|
+                                                          project ([$$71, $$84, $$93, $$72, $$79, $$76])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            assign [$$79, $$76] <- [$$74.getField(5), $$74.getField(0)]
                                                             -- ASSIGN  |PARTITIONED|
+                                                              project ([$$71, $$84, $$93, $$72, $$74])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$74] <- [$$t2.getField(0)]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  project ([$$71, $$84, $$93, $$72, $$t2])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                      left-outer-unnest-map [$$72, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$104, 1, $$104, true, true, true)
+                                                                      -- BTREE_SEARCH  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          order (ASC, $$104)
                                                                           -- STABLE_SORT [$$104(ASC)]  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                              -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.TweetMessages.msgNgramIx)  |PARTITIONED|
+                                                                              left-outer-unnest-map [$$104] <- index-search("msgNgramIx", 5, "test", "TweetMessages", true, true, 2, 7, 12, false, 1, $$84)
+                                                                              -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                                                                exchange
                                                                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                  select (edit-distance-string-is-filterable($$84, 7, 3, true))
                                                                                   -- STREAM_SELECT  |PARTITIONED|
+                                                                                    exchange
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                      replicate
                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                        exchange
                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                          project ([$$71, $$84, $$93])
                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                            assign [$$84, $$93] <- [$$94.getField(5), $$94.getField(0)]
                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                              project ([$$71, $$94])
                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                assign [$$94] <- [$$95.getField(0)]
                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                  exchange
                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                    replicate
                                                                                                     -- REPLICATE  |PARTITIONED|
+                                                                                                      exchange
                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                                                        unnest-map [$$71, $$95] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$96, 0, false, true, false)
+                                                                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                                                                          exchange
                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                            assign [$$96] <- [240]
                                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                                              empty-tuple-source
                                                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      project ([$$103, $$99, $$100, $$71, $$84])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          left outer join (and(neq($$100, $$93), get-item(edit-distance-check($$84, $$99, 7), 0)))
                                                           -- NESTED_LOOP  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              project ([$$103, $$99, $$100])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$99, $$100] <- [$$101.getField(5), $$101.getField(0)]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  project ([$$103, $$101])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    assign [$$101] <- [$$102.getField(0)]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                        -- DATASOURCE_SCAN (test.TweetMessages)  |PARTITIONED|
+                                                                        data-scan []<-[$$103, $$102] <- test.TweetMessages
+                                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            empty-tuple-source
                                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                            exchange
                                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                              select (not(edit-distance-string-is-filterable($$84, 7, 3, true)))
                                                               -- STREAM_SELECT  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  replicate
                                                                   -- REPLICATE  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      project ([$$71, $$84, $$93])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        assign [$$84, $$93] <- [$$94.getField(5), $$94.getField(0)]
                                                                         -- ASSIGN  |PARTITIONED|
+                                                                          project ([$$71, $$94])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            assign [$$94] <- [$$95.getField(0)]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                replicate
                                                                                 -- REPLICATE  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                    -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                                    unnest-map [$$71, $$95] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$96, 0, false, true, false)
+                                                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                        assign [$$96] <- [240]
                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                          empty-tuple-source
                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-join/leftouterjoin-probe-pidx-with-join-jaccard-check-idx_01_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-join/leftouterjoin-probe-pidx-with-join-jaccard-check-idx_01_ps.plan
index e6b48bb..9b4af75 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-join/leftouterjoin-probe-pidx-with-join-jaccard-check-idx_01_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/inverted-index-join/leftouterjoin-probe-pidx-with-join-jaccard-check-idx_01_ps.plan
@@ -1,120 +1,234 @@
+distribute result [$$66]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$66])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$66] <- [{"tweet": {"id": $$77, "topics": $$84}, "similar-tweets": $$65}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$65, $$84, $$77])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            order (ASC, $$86)
             -- STABLE_SORT [$$86(ASC)]  |PARTITIONED|
+              exchange
               -- RANGE_PARTITION_EXCHANGE [$$86(ASC)]  |PARTITIONED|
+                forward: shared-variable = $$101
                 -- FORWARD  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- PRE_CLUSTERED_GROUP_BY[$$71]  |PARTITIONED|
-                                {
+                        group by ([$$86 := $$71]) decor ([$$84; $$77]) {
+                                  aggregate [$$65] <- [listify({"id": $$76, "topics": $$79})]
                                   -- AGGREGATE  |LOCAL|
+                                    select (not(is-missing($$72)))
                                     -- STREAM_SELECT  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                }
+                               }
+                        -- PRE_CLUSTERED_GROUP_BY[$$71]  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$71) (ASC, $$72)
                             -- STABLE_SORT [$$71(ASC), $$72(ASC)]  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$71]  |PARTITIONED|
+                                project ([$$77, $$84, $$76, $$79, $$72, $$71])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    join (eq($$92, $$71))
                                     -- HYBRID_HASH_JOIN [$$92][$$71]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$77, $$92])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$77] <- [$$t1.getField(0).getField(0)]
                                           -- ASSIGN  |PARTITIONED|
+                                            project ([$$92, $$t1])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$92, $$t1] <- [$$71, $$95]
                                               -- ASSIGN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  replicate
                                                   -- REPLICATE  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                      unnest-map [$$71, $$95] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$96, 0, false, true, false)
+                                                      -- BTREE_SEARCH  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          assign [$$96] <- [240]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$71]  |PARTITIONED|
+                                        project ([$$84, $$76, $$79, $$72, $$71])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          select (and(neq($$76, $$93), get-item(similarity-jaccard-check($$84, $$79, 0.5), 0))) retain-untrue ($$72 <- MISSING)
                                           -- STREAM_SELECT  |PARTITIONED|
+                                            project ([$$71, $$84, $$93, $$72, $$79, $$76])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$79, $$76] <- [$$74.getField(4), $$74.getField(0)]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$71, $$84, $$93, $$72, $$74])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$74] <- [$$t2.getField(0)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$71, $$84, $$93, $$72, $$t2])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                        left-outer-unnest-map [$$72, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$98, 1, $$98, true, true, true)
+                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            order (ASC, $$98)
                                                             -- STABLE_SORT [$$98(ASC)]  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.TweetMessages.topicKeywordIx)  |PARTITIONED|
+                                                                left-outer-unnest-map [$$98] <- index-search("topicKeywordIx", 4, "test", "TweetMessages", true, true, 1, 0.5, 22, false, 1, $$84)
+                                                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                                                  exchange
                                                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                    project ([$$71, $$84, $$93])
                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                      assign [$$84, $$93] <- [$$94.getField(4), $$94.getField(0)]
                                                                       -- ASSIGN  |PARTITIONED|
+                                                                        project ([$$71, $$94])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          assign [$$94] <- [$$95.getField(0)]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              replicate
                                                                               -- REPLICATE  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                  -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                                  unnest-map [$$71, $$95] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$96, 0, false, true, false)
+                                                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                                                    exchange
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                      assign [$$96] <- [240]
                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                        empty-tuple-source
                                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    aggregate [$$101] <- [agg-range-map($$99, $$100)]
                     -- AGGREGATE  |UNPARTITIONED|
+                      exchange
                       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                        aggregate [$$99, $$100] <- [agg-local-sampling($$86), agg-null-writer($$86)]
                         -- AGGREGATE  |PARTITIONED|
+                          project ([$$86])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              replicate
                               -- REPLICATE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- PRE_CLUSTERED_GROUP_BY[$$71]  |PARTITIONED|
-                                          {
+                                  group by ([$$86 := $$71]) decor ([$$84; $$77]) {
+                                            aggregate [$$65] <- [listify({"id": $$76, "topics": $$79})]
                                             -- AGGREGATE  |LOCAL|
+                                              select (not(is-missing($$72)))
                                               -- STREAM_SELECT  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                         }
+                                  -- PRE_CLUSTERED_GROUP_BY[$$71]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$71) (ASC, $$72)
                                       -- STABLE_SORT [$$71(ASC), $$72(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$71]  |PARTITIONED|
+                                          project ([$$77, $$84, $$76, $$79, $$72, $$71])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              join (eq($$92, $$71))
                                               -- HYBRID_HASH_JOIN [$$92][$$71]  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  project ([$$77, $$92])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    assign [$$77] <- [$$t1.getField(0).getField(0)]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      project ([$$92, $$t1])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$92, $$t1] <- [$$71, $$95]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            replicate
                                                             -- REPLICATE  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                unnest-map [$$71, $$95] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$96, 0, false, true, false)
+                                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    assign [$$96] <- [240]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      empty-tuple-source
                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$71]  |PARTITIONED|
+                                                  project ([$$84, $$76, $$79, $$72, $$71])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    select (and(neq($$76, $$93), get-item(similarity-jaccard-check($$84, $$79, 0.5), 0))) retain-untrue ($$72 <- MISSING)
                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                      project ([$$71, $$84, $$93, $$72, $$79, $$76])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$79, $$76] <- [$$74.getField(4), $$74.getField(0)]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          project ([$$71, $$84, $$93, $$72, $$74])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            assign [$$74] <- [$$t2.getField(0)]
                                                             -- ASSIGN  |PARTITIONED|
+                                                              project ([$$71, $$84, $$93, $$72, $$t2])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                  left-outer-unnest-map [$$72, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$98, 1, $$98, true, true, true)
+                                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      order (ASC, $$98)
                                                                       -- STABLE_SORT [$$98(ASC)]  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.TweetMessages.topicKeywordIx)  |PARTITIONED|
+                                                                          left-outer-unnest-map [$$98] <- index-search("topicKeywordIx", 4, "test", "TweetMessages", true, true, 1, 0.5, 22, false, 1, $$84)
+                                                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                                                            exchange
                                                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                              project ([$$71, $$84, $$93])
                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                assign [$$84, $$93] <- [$$94.getField(4), $$94.getField(0)]
                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                  project ([$$71, $$94])
                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                    assign [$$94] <- [$$95.getField(0)]
                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                        replicate
                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                            -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                                            unnest-map [$$71, $$95] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$96, 0, false, true, false)
+                                                                                            -- BTREE_SEARCH  |PARTITIONED|
+                                                                                              exchange
                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                assign [$$96] <- [240]
                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                  empty-tuple-source
                                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01_ps.plan
index ee5703a..8231733 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01_ps.plan
@@ -1,92 +1,178 @@
+distribute result [$$57]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$57])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$57] <- [{"tweetid1": $$65, "loc1": $$66, "nearby-message": $$56}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$56, $$65, $$66])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            order (ASC, $$74)
             -- STABLE_SORT [$$74(ASC)]  |PARTITIONED|
+              exchange
               -- RANGE_PARTITION_EXCHANGE [$$74(ASC)]  |PARTITIONED|
+                forward: shared-variable = $$89
                 -- FORWARD  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- PRE_CLUSTERED_GROUP_BY[$$61]  |PARTITIONED|
-                                {
+                        group by ([$$74 := $$61]) decor ([$$65; $$66]) {
+                                  aggregate [$$56] <- [listify({"tweetid2": $$68, "loc2": $$64})]
                                   -- AGGREGATE  |LOCAL|
+                                    select (not(is-missing($$62)))
                                     -- STREAM_SELECT  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                }
+                               }
+                        -- PRE_CLUSTERED_GROUP_BY[$$61]  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$61) (ASC, $$67)
                             -- STABLE_SORT [$$61(ASC), $$67(ASC)]  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$61]  |PARTITIONED|
+                                project ([$$65, $$66, $$68, $$64, $$67, $$62, $$61])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  select (spatial-intersect($$64, $$n)) retain-untrue ($$62 <- MISSING)
                                   -- STREAM_SELECT  |PARTITIONED|
+                                    project ([$$65, $$66, $$61, $$n, $$62, $$67, $$68, $$64])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$68, $$64] <- [$$63.getField(0), $$63.getField(2)]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$65, $$66, $$61, $$n, $$62, $$63, $$67])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$63, $$67] <- [$$t2.getField(0), $$t2.getField("tweetid")]
                                           -- ASSIGN  |PARTITIONED|
+                                            project ([$$65, $$66, $$61, $$n, $$62, $$t2])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                left-outer-unnest-map [$$62, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$86, 1, $$86, true, true, true)
+                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    order (ASC, $$86)
                                                     -- STABLE_SORT [$$86(ASC)]  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        project ([$$65, $$66, $$61, $$n, $$86])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- RTREE_SEARCH (test.TweetMessages.twmSndLocIx)  |PARTITIONED|
+                                                            left-outer-unnest-map [$$82, $$83, $$84, $$85, $$86] <- index-search("twmSndLocIx", 1, "test", "TweetMessages", true, true, 4, $$78, $$79, $$80, $$81)
+                                                            -- RTREE_SEARCH  |PARTITIONED|
+                                                              exchange
                                                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                assign [$$78, $$79, $$80, $$81] <- [create-mbr($$n, 2, 0), create-mbr($$n, 2, 1), create-mbr($$n, 2, 2), create-mbr($$n, 2, 3)]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  assign [$$n] <- [create-circle($$66, 0.5)]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    project ([$$61, $$66, $$65])
                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                      assign [$$66, $$65] <- [$$60.getField(2), $$60.getField(0)]
                                                                       -- ASSIGN  |PARTITIONED|
+                                                                        project ([$$61, $$60])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          assign [$$60] <- [$$t1.getField(0)]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                              -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                              unnest-map [$$61, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$75, true, false, false)
+                                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  assign [$$75] <- [10]
                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                    empty-tuple-source
                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    aggregate [$$89] <- [agg-range-map($$87, $$88)]
                     -- AGGREGATE  |UNPARTITIONED|
+                      exchange
                       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                        aggregate [$$87, $$88] <- [agg-local-sampling($$74), agg-null-writer($$74)]
                         -- AGGREGATE  |PARTITIONED|
+                          project ([$$74])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              replicate
                               -- REPLICATE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- PRE_CLUSTERED_GROUP_BY[$$61]  |PARTITIONED|
-                                          {
+                                  group by ([$$74 := $$61]) decor ([$$65; $$66]) {
+                                            aggregate [$$56] <- [listify({"tweetid2": $$68, "loc2": $$64})]
                                             -- AGGREGATE  |LOCAL|
+                                              select (not(is-missing($$62)))
                                               -- STREAM_SELECT  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                         }
+                                  -- PRE_CLUSTERED_GROUP_BY[$$61]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$61) (ASC, $$67)
                                       -- STABLE_SORT [$$61(ASC), $$67(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$61]  |PARTITIONED|
+                                          project ([$$65, $$66, $$68, $$64, $$67, $$62, $$61])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            select (spatial-intersect($$64, $$n)) retain-untrue ($$62 <- MISSING)
                                             -- STREAM_SELECT  |PARTITIONED|
+                                              project ([$$65, $$66, $$61, $$n, $$62, $$67, $$68, $$64])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$68, $$64] <- [$$63.getField(0), $$63.getField(2)]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  project ([$$65, $$66, $$61, $$n, $$62, $$63, $$67])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    assign [$$63, $$67] <- [$$t2.getField(0), $$t2.getField("tweetid")]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      project ([$$65, $$66, $$61, $$n, $$62, $$t2])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                          left-outer-unnest-map [$$62, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$86, 1, $$86, true, true, true)
+                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              order (ASC, $$86)
                                                               -- STABLE_SORT [$$86(ASC)]  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  project ([$$65, $$66, $$61, $$n, $$86])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- RTREE_SEARCH (test.TweetMessages.twmSndLocIx)  |PARTITIONED|
+                                                                      left-outer-unnest-map [$$82, $$83, $$84, $$85, $$86] <- index-search("twmSndLocIx", 1, "test", "TweetMessages", true, true, 4, $$78, $$79, $$80, $$81)
+                                                                      -- RTREE_SEARCH  |PARTITIONED|
+                                                                        exchange
                                                                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                          assign [$$78, $$79, $$80, $$81] <- [create-mbr($$n, 2, 0), create-mbr($$n, 2, 1), create-mbr($$n, 2, 2), create-mbr($$n, 2, 3)]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            assign [$$n] <- [create-circle($$66, 0.5)]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              project ([$$61, $$66, $$65])
                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                assign [$$66, $$65] <- [$$60.getField(2), $$60.getField(0)]
                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                  project ([$$61, $$60])
                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                    assign [$$60] <- [$$t1.getField(0)]
                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                                        unnest-map [$$61, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$75, true, false, false)
+                                                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                            assign [$$75] <- [10]
                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                              empty-tuple-source
                                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02_ps.plan
index 7e70955..aac75d0 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-index/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02_ps.plan
@@ -1,92 +1,178 @@
+distribute result [$$64]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$64])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$64] <- [{"tweetid1": $$74, "loc1": $$75, "nearby-message": $$63}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$63, $$74, $$75])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            order (ASC, $$83)
             -- STABLE_SORT [$$83(ASC)]  |PARTITIONED|
+              exchange
               -- RANGE_PARTITION_EXCHANGE [$$83(ASC)]  |PARTITIONED|
+                forward: shared-variable = $$98
                 -- FORWARD  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- PRE_CLUSTERED_GROUP_BY[$$68]  |PARTITIONED|
-                                {
+                        group by ([$$83 := $$68]) decor ([$$74; $$75]) {
+                                  aggregate [$$63] <- [listify({"tweetid2": $$73, "loc2": $$71})]
                                   -- AGGREGATE  |LOCAL|
+                                    select (not(is-missing($$69)))
                                     -- STREAM_SELECT  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                }
+                               }
+                        -- PRE_CLUSTERED_GROUP_BY[$$68]  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$68) (ASC, $$69)
                             -- STABLE_SORT [$$68(ASC), $$69(ASC)]  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$68]  |PARTITIONED|
+                                project ([$$74, $$75, $$73, $$71, $$69, $$68])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  select (and(spatial-intersect($$71, $$n), neq($$68, $$73))) retain-untrue ($$69 <- MISSING)
                                   -- STREAM_SELECT  |PARTITIONED|
+                                    project ([$$74, $$75, $$68, $$n, $$69, $$73, $$71])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$73, $$71] <- [$$70.getField(0), $$70.getField(2)]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$74, $$75, $$68, $$n, $$69, $$70])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$70] <- [$$t2.getField(0)]
                                           -- ASSIGN  |PARTITIONED|
+                                            project ([$$74, $$75, $$68, $$n, $$69, $$t2])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                left-outer-unnest-map [$$69, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$95, 1, $$95, true, true, true)
+                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    order (ASC, $$95)
                                                     -- STABLE_SORT [$$95(ASC)]  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        project ([$$74, $$75, $$68, $$n, $$95])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- RTREE_SEARCH (test.TweetMessages.twmSndLocIx)  |PARTITIONED|
+                                                            left-outer-unnest-map [$$91, $$92, $$93, $$94, $$95] <- index-search("twmSndLocIx", 1, "test", "TweetMessages", true, true, 4, $$87, $$88, $$89, $$90)
+                                                            -- RTREE_SEARCH  |PARTITIONED|
+                                                              exchange
                                                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                assign [$$87, $$88, $$89, $$90] <- [create-mbr($$n, 2, 0), create-mbr($$n, 2, 1), create-mbr($$n, 2, 2), create-mbr($$n, 2, 3)]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  assign [$$n] <- [create-circle($$75, 0.5)]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    project ([$$68, $$75, $$74])
                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                      assign [$$75, $$74] <- [$$67.getField(2), $$67.getField(0)]
                                                                       -- ASSIGN  |PARTITIONED|
+                                                                        project ([$$68, $$67])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          assign [$$67] <- [$$t1.getField(0)]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                              -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                              unnest-map [$$68, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$84, true, false, false)
+                                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  assign [$$84] <- [10]
                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                    empty-tuple-source
                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    aggregate [$$98] <- [agg-range-map($$96, $$97)]
                     -- AGGREGATE  |UNPARTITIONED|
+                      exchange
                       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                        aggregate [$$96, $$97] <- [agg-local-sampling($$83), agg-null-writer($$83)]
                         -- AGGREGATE  |PARTITIONED|
+                          project ([$$83])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              replicate
                               -- REPLICATE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- PRE_CLUSTERED_GROUP_BY[$$68]  |PARTITIONED|
-                                          {
+                                  group by ([$$83 := $$68]) decor ([$$74; $$75]) {
+                                            aggregate [$$63] <- [listify({"tweetid2": $$73, "loc2": $$71})]
                                             -- AGGREGATE  |LOCAL|
+                                              select (not(is-missing($$69)))
                                               -- STREAM_SELECT  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                         }
+                                  -- PRE_CLUSTERED_GROUP_BY[$$68]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$68) (ASC, $$69)
                                       -- STABLE_SORT [$$68(ASC), $$69(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$68]  |PARTITIONED|
+                                          project ([$$74, $$75, $$73, $$71, $$69, $$68])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            select (and(spatial-intersect($$71, $$n), neq($$68, $$73))) retain-untrue ($$69 <- MISSING)
                                             -- STREAM_SELECT  |PARTITIONED|
+                                              project ([$$74, $$75, $$68, $$n, $$69, $$73, $$71])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$73, $$71] <- [$$70.getField(0), $$70.getField(2)]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  project ([$$74, $$75, $$68, $$n, $$69, $$70])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    assign [$$70] <- [$$t2.getField(0)]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      project ([$$74, $$75, $$68, $$n, $$69, $$t2])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                          left-outer-unnest-map [$$69, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$95, 1, $$95, true, true, true)
+                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              order (ASC, $$95)
                                                               -- STABLE_SORT [$$95(ASC)]  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  project ([$$74, $$75, $$68, $$n, $$95])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- RTREE_SEARCH (test.TweetMessages.twmSndLocIx)  |PARTITIONED|
+                                                                      left-outer-unnest-map [$$91, $$92, $$93, $$94, $$95] <- index-search("twmSndLocIx", 1, "test", "TweetMessages", true, true, 4, $$87, $$88, $$89, $$90)
+                                                                      -- RTREE_SEARCH  |PARTITIONED|
+                                                                        exchange
                                                                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                          assign [$$87, $$88, $$89, $$90] <- [create-mbr($$n, 2, 0), create-mbr($$n, 2, 1), create-mbr($$n, 2, 2), create-mbr($$n, 2, 3)]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            assign [$$n] <- [create-circle($$75, 0.5)]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              project ([$$68, $$75, $$74])
                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                assign [$$75, $$74] <- [$$67.getField(2), $$67.getField(0)]
                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                  project ([$$68, $$67])
                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                    assign [$$67] <- [$$t1.getField(0)]
                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                                        unnest-map [$$68, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$84, true, false, false)
+                                                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                            assign [$$84] <- [10]
                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                              empty-tuple-source
                                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_1_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_1_ps.plan
index 8fd6f04..be1ef63 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_1_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_1_ps.plan
@@ -1,86 +1,166 @@
+distribute result [$$47]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$47])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$47] <- [{"tweetid1": $$50, "count1": $$56, "t2info": $$46}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$46, $$50, $$56])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            order (ASC, $$65)
             -- STABLE_SORT [$$65(ASC)]  |PARTITIONED|
+              exchange
               -- RANGE_PARTITION_EXCHANGE [$$65(ASC)]  |PARTITIONED|
+                forward: shared-variable = $$73
                 -- FORWARD  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- PRE_CLUSTERED_GROUP_BY[$$52]  |PARTITIONED|
-                                {
+                        group by ([$$65 := $$52]) decor ([$$50; $$56]) {
+                                  aggregate [$$46] <- [listify({"tweetid2": $$59, "count2": $$57})]
                                   -- AGGREGATE  |LOCAL|
+                                    select (not(is-missing($$53)))
                                     -- STREAM_SELECT  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                }
+                               }
+                        -- PRE_CLUSTERED_GROUP_BY[$$52]  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$52) (ASC, $$53)
                             -- STABLE_SORT [$$52(ASC), $$53(ASC)]  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$52]  |PARTITIONED|
+                                select (eq($$56, $$57)) retain-untrue ($$53 <- MISSING)
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  project ([$$50, $$56, $$52, $$53, $$59, $$57])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$59, $$57] <- [$$55.getField(0), $$55.getField("countB")]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$50, $$56, $$52, $$53, $$55])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$55] <- [$$t2.getField(0)]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$50, $$56, $$52, $$53, $$t2])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                              left-outer-unnest-map [$$53, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$70, 1, $$70, true, true, true)
+                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  order (ASC, $$70)
                                                   -- STABLE_SORT [$$70(ASC)]  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      project ([$$50, $$56, $$52, $$70])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                                          left-outer-unnest-map [$$69, $$70] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$56, 1, $$56, true, true, true)
+                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                            exchange
                                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                              project ([$$52, $$56, $$50])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$56, $$50] <- [$$63.getField(6), $$63.getField(0)]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  project ([$$52, $$63])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    assign [$$63] <- [$$t1.getField(0)]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                        unnest-map [$$52, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$66, true, false, false)
+                                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            assign [$$66] <- [10]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              empty-tuple-source
                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    aggregate [$$73] <- [agg-range-map($$71, $$72)]
                     -- AGGREGATE  |UNPARTITIONED|
+                      exchange
                       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                        aggregate [$$71, $$72] <- [agg-local-sampling($$65), agg-null-writer($$65)]
                         -- AGGREGATE  |PARTITIONED|
+                          project ([$$65])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              replicate
                               -- REPLICATE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- PRE_CLUSTERED_GROUP_BY[$$52]  |PARTITIONED|
-                                          {
+                                  group by ([$$65 := $$52]) decor ([$$50; $$56]) {
+                                            aggregate [$$46] <- [listify({"tweetid2": $$59, "count2": $$57})]
                                             -- AGGREGATE  |LOCAL|
+                                              select (not(is-missing($$53)))
                                               -- STREAM_SELECT  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                         }
+                                  -- PRE_CLUSTERED_GROUP_BY[$$52]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$52) (ASC, $$53)
                                       -- STABLE_SORT [$$52(ASC), $$53(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$52]  |PARTITIONED|
+                                          select (eq($$56, $$57)) retain-untrue ($$53 <- MISSING)
                                           -- STREAM_SELECT  |PARTITIONED|
+                                            project ([$$50, $$56, $$52, $$53, $$59, $$57])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$59, $$57] <- [$$55.getField(0), $$55.getField("countB")]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$50, $$56, $$52, $$53, $$55])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$55] <- [$$t2.getField(0)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$50, $$56, $$52, $$53, $$t2])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                        left-outer-unnest-map [$$53, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$70, 1, $$70, true, true, true)
+                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            order (ASC, $$70)
                                                             -- STABLE_SORT [$$70(ASC)]  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                project ([$$50, $$56, $$52, $$70])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                                                    left-outer-unnest-map [$$69, $$70] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$56, 1, $$56, true, true, true)
+                                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                                      exchange
                                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                        project ([$$52, $$56, $$50])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          assign [$$56, $$50] <- [$$63.getField(6), $$63.getField(0)]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            project ([$$52, $$63])
                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                              assign [$$63] <- [$$t1.getField(0)]
                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                  -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                                  unnest-map [$$52, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$66, true, false, false)
+                                                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                                                    exchange
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                      assign [$$66] <- [10]
                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                        empty-tuple-source
                                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_2_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_2_ps.plan
index 8fd6f04..f311035 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_2_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_2_ps.plan
@@ -1,86 +1,166 @@
+distribute result [$$47]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$47])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$47] <- [{"tweetid1": $$50, "count1": $$56, "t2info": $$46}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$46, $$50, $$56])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            order (ASC, $$65)
             -- STABLE_SORT [$$65(ASC)]  |PARTITIONED|
+              exchange
               -- RANGE_PARTITION_EXCHANGE [$$65(ASC)]  |PARTITIONED|
+                forward: shared-variable = $$73
                 -- FORWARD  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- PRE_CLUSTERED_GROUP_BY[$$52]  |PARTITIONED|
-                                {
+                        group by ([$$65 := $$52]) decor ([$$50; $$56]) {
+                                  aggregate [$$46] <- [listify({"tweetid2": $$59, "count2": $$57})]
                                   -- AGGREGATE  |LOCAL|
+                                    select (not(is-missing($$53)))
                                     -- STREAM_SELECT  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                }
+                               }
+                        -- PRE_CLUSTERED_GROUP_BY[$$52]  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$52) (ASC, $$53)
                             -- STABLE_SORT [$$52(ASC), $$53(ASC)]  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$52]  |PARTITIONED|
+                                select (eq($$56, $$57)) retain-untrue ($$53 <- MISSING)
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  project ([$$50, $$56, $$52, $$53, $$59, $$57])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$59, $$57] <- [$$55.getField(0), $$55.getField("countB")]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$50, $$56, $$52, $$53, $$55])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$55] <- [$$t2.getField(0)]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$50, $$56, $$52, $$53, $$t2])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                              left-outer-unnest-map [$$53, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$70, 1, $$70, true, true, true)
+                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  order (ASC, $$70)
                                                   -- STABLE_SORT [$$70(ASC)]  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      project ([$$50, $$56, $$52, $$70])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                                          left-outer-unnest-map [$$69, $$70] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$56, 1, $$56, true, true, true)
+                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                            exchange
                                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                              project ([$$52, $$56, $$50])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$56, $$50] <- [$$63.getField("countA"), $$63.getField(0)]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  project ([$$52, $$63])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    assign [$$63] <- [$$t1.getField(0)]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                        unnest-map [$$52, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$66, true, false, false)
+                                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            assign [$$66] <- [10]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              empty-tuple-source
                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    aggregate [$$73] <- [agg-range-map($$71, $$72)]
                     -- AGGREGATE  |UNPARTITIONED|
+                      exchange
                       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                        aggregate [$$71, $$72] <- [agg-local-sampling($$65), agg-null-writer($$65)]
                         -- AGGREGATE  |PARTITIONED|
+                          project ([$$65])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              replicate
                               -- REPLICATE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- PRE_CLUSTERED_GROUP_BY[$$52]  |PARTITIONED|
-                                          {
+                                  group by ([$$65 := $$52]) decor ([$$50; $$56]) {
+                                            aggregate [$$46] <- [listify({"tweetid2": $$59, "count2": $$57})]
                                             -- AGGREGATE  |LOCAL|
+                                              select (not(is-missing($$53)))
                                               -- STREAM_SELECT  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                         }
+                                  -- PRE_CLUSTERED_GROUP_BY[$$52]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$52) (ASC, $$53)
                                       -- STABLE_SORT [$$52(ASC), $$53(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$52]  |PARTITIONED|
+                                          select (eq($$56, $$57)) retain-untrue ($$53 <- MISSING)
                                           -- STREAM_SELECT  |PARTITIONED|
+                                            project ([$$50, $$56, $$52, $$53, $$59, $$57])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$59, $$57] <- [$$55.getField(0), $$55.getField("countB")]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$50, $$56, $$52, $$53, $$55])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$55] <- [$$t2.getField(0)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$50, $$56, $$52, $$53, $$t2])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                        left-outer-unnest-map [$$53, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$70, 1, $$70, true, true, true)
+                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            order (ASC, $$70)
                                                             -- STABLE_SORT [$$70(ASC)]  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                project ([$$50, $$56, $$52, $$70])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                                                    left-outer-unnest-map [$$69, $$70] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$56, 1, $$56, true, true, true)
+                                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                                      exchange
                                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                        project ([$$52, $$56, $$50])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          assign [$$56, $$50] <- [$$63.getField("countA"), $$63.getField(0)]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            project ([$$52, $$63])
                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                              assign [$$63] <- [$$t1.getField(0)]
                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                  -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                                  unnest-map [$$52, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$66, true, false, false)
+                                                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                                                    exchange
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                      assign [$$66] <- [10]
                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                        empty-tuple-source
                                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_1_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_1_ps.plan
index 9857dae..78b384a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_1_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_1_ps.plan
@@ -1,86 +1,166 @@
+distribute result [$$53]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$53])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$53] <- [{"tweetid1": $$65, "count1": $$71, "t2info": $$52}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$52, $$65, $$71])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            order (ASC, $$73)
             -- STABLE_SORT [$$73(ASC)]  |PARTITIONED|
+              exchange
               -- RANGE_PARTITION_EXCHANGE [$$73(ASC)]  |PARTITIONED|
+                forward: shared-variable = $$81
                 -- FORWARD  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- PRE_CLUSTERED_GROUP_BY[$$58]  |PARTITIONED|
-                                {
+                        group by ([$$73 := $$58]) decor ([$$65; $$71]) {
+                                  aggregate [$$52] <- [listify({"tweetid2": $$66, "count2": $$64})]
                                   -- AGGREGATE  |LOCAL|
+                                    select (not(is-missing($$59)))
                                     -- STREAM_SELECT  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                }
+                               }
+                        -- PRE_CLUSTERED_GROUP_BY[$$58]  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$58) (ASC, $$59)
                             -- STABLE_SORT [$$58(ASC), $$59(ASC)]  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$58]  |PARTITIONED|
+                                select (and(eq($$71, $$64), neq($$65, $$66))) retain-untrue ($$59 <- MISSING)
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  project ([$$65, $$71, $$58, $$59, $$66, $$64])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$66, $$64] <- [$$62.getField(0), $$62.getField("countB")]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$65, $$71, $$58, $$59, $$62])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$62] <- [$$t2.getField(0)]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$65, $$71, $$58, $$59, $$t2])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                              left-outer-unnest-map [$$59, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$78, 1, $$78, true, true, true)
+                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  order (ASC, $$78)
                                                   -- STABLE_SORT [$$78(ASC)]  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      project ([$$65, $$71, $$58, $$78])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                                          left-outer-unnest-map [$$77, $$78] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$71, 1, $$71, true, true, true)
+                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                            exchange
                                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                              project ([$$58, $$71, $$65])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$71, $$65] <- [$$60.getField(6), $$60.getField(0)]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  project ([$$58, $$60])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    assign [$$60] <- [$$t1.getField(0)]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                        unnest-map [$$58, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$74, true, false, false)
+                                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            assign [$$74] <- [10]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              empty-tuple-source
                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    aggregate [$$81] <- [agg-range-map($$79, $$80)]
                     -- AGGREGATE  |UNPARTITIONED|
+                      exchange
                       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                        aggregate [$$79, $$80] <- [agg-local-sampling($$73), agg-null-writer($$73)]
                         -- AGGREGATE  |PARTITIONED|
+                          project ([$$73])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              replicate
                               -- REPLICATE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- PRE_CLUSTERED_GROUP_BY[$$58]  |PARTITIONED|
-                                          {
+                                  group by ([$$73 := $$58]) decor ([$$65; $$71]) {
+                                            aggregate [$$52] <- [listify({"tweetid2": $$66, "count2": $$64})]
                                             -- AGGREGATE  |LOCAL|
+                                              select (not(is-missing($$59)))
                                               -- STREAM_SELECT  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                         }
+                                  -- PRE_CLUSTERED_GROUP_BY[$$58]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$58) (ASC, $$59)
                                       -- STABLE_SORT [$$58(ASC), $$59(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$58]  |PARTITIONED|
+                                          select (and(eq($$71, $$64), neq($$65, $$66))) retain-untrue ($$59 <- MISSING)
                                           -- STREAM_SELECT  |PARTITIONED|
+                                            project ([$$65, $$71, $$58, $$59, $$66, $$64])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$66, $$64] <- [$$62.getField(0), $$62.getField("countB")]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$65, $$71, $$58, $$59, $$62])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$62] <- [$$t2.getField(0)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$65, $$71, $$58, $$59, $$t2])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                        left-outer-unnest-map [$$59, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$78, 1, $$78, true, true, true)
+                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            order (ASC, $$78)
                                                             -- STABLE_SORT [$$78(ASC)]  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                project ([$$65, $$71, $$58, $$78])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                                                    left-outer-unnest-map [$$77, $$78] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$71, 1, $$71, true, true, true)
+                                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                                      exchange
                                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                        project ([$$58, $$71, $$65])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          assign [$$71, $$65] <- [$$60.getField(6), $$60.getField(0)]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            project ([$$58, $$60])
                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                              assign [$$60] <- [$$t1.getField(0)]
                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                  -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                                  unnest-map [$$58, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$74, true, false, false)
+                                                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                                                    exchange
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                      assign [$$74] <- [10]
                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                        empty-tuple-source
                                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_2_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_2_ps.plan
index 9857dae..65c871c 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_2_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_2_ps.plan
@@ -1,86 +1,166 @@
+distribute result [$$53]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$53])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$53] <- [{"tweetid1": $$65, "count1": $$71, "t2info": $$52}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$52, $$65, $$71])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            order (ASC, $$73)
             -- STABLE_SORT [$$73(ASC)]  |PARTITIONED|
+              exchange
               -- RANGE_PARTITION_EXCHANGE [$$73(ASC)]  |PARTITIONED|
+                forward: shared-variable = $$81
                 -- FORWARD  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- PRE_CLUSTERED_GROUP_BY[$$58]  |PARTITIONED|
-                                {
+                        group by ([$$73 := $$58]) decor ([$$65; $$71]) {
+                                  aggregate [$$52] <- [listify({"tweetid2": $$66, "count2": $$64})]
                                   -- AGGREGATE  |LOCAL|
+                                    select (not(is-missing($$59)))
                                     -- STREAM_SELECT  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                }
+                               }
+                        -- PRE_CLUSTERED_GROUP_BY[$$58]  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$58) (ASC, $$59)
                             -- STABLE_SORT [$$58(ASC), $$59(ASC)]  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$58]  |PARTITIONED|
+                                select (and(eq($$71, $$64), neq($$65, $$66))) retain-untrue ($$59 <- MISSING)
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  project ([$$65, $$71, $$58, $$59, $$66, $$64])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$66, $$64] <- [$$62.getField(0), $$62.getField("countB")]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$65, $$71, $$58, $$59, $$62])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$62] <- [$$t2.getField(0)]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$65, $$71, $$58, $$59, $$t2])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                              left-outer-unnest-map [$$59, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$78, 1, $$78, true, true, true)
+                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  order (ASC, $$78)
                                                   -- STABLE_SORT [$$78(ASC)]  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      project ([$$65, $$71, $$58, $$78])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                                          left-outer-unnest-map [$$77, $$78] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$71, 1, $$71, true, true, true)
+                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                            exchange
                                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                              project ([$$58, $$71, $$65])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$71, $$65] <- [$$60.getField("countA"), $$60.getField(0)]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  project ([$$58, $$60])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    assign [$$60] <- [$$t1.getField(0)]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                        unnest-map [$$58, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$74, true, false, false)
+                                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            assign [$$74] <- [10]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              empty-tuple-source
                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    aggregate [$$81] <- [agg-range-map($$79, $$80)]
                     -- AGGREGATE  |UNPARTITIONED|
+                      exchange
                       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                        aggregate [$$79, $$80] <- [agg-local-sampling($$73), agg-null-writer($$73)]
                         -- AGGREGATE  |PARTITIONED|
+                          project ([$$73])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              replicate
                               -- REPLICATE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- PRE_CLUSTERED_GROUP_BY[$$58]  |PARTITIONED|
-                                          {
+                                  group by ([$$73 := $$58]) decor ([$$65; $$71]) {
+                                            aggregate [$$52] <- [listify({"tweetid2": $$66, "count2": $$64})]
                                             -- AGGREGATE  |LOCAL|
+                                              select (not(is-missing($$59)))
                                               -- STREAM_SELECT  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                         }
+                                  -- PRE_CLUSTERED_GROUP_BY[$$58]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$58) (ASC, $$59)
                                       -- STABLE_SORT [$$58(ASC), $$59(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$58]  |PARTITIONED|
+                                          select (and(eq($$71, $$64), neq($$65, $$66))) retain-untrue ($$59 <- MISSING)
                                           -- STREAM_SELECT  |PARTITIONED|
+                                            project ([$$65, $$71, $$58, $$59, $$66, $$64])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$66, $$64] <- [$$62.getField(0), $$62.getField("countB")]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$65, $$71, $$58, $$59, $$62])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$62] <- [$$t2.getField(0)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$65, $$71, $$58, $$59, $$t2])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                        left-outer-unnest-map [$$59, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$78, 1, $$78, true, true, true)
+                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            order (ASC, $$78)
                                                             -- STABLE_SORT [$$78(ASC)]  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                project ([$$65, $$71, $$58, $$78])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                                                    left-outer-unnest-map [$$77, $$78] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$71, 1, $$71, true, true, true)
+                                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                                      exchange
                                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                        project ([$$58, $$71, $$65])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          assign [$$71, $$65] <- [$$60.getField("countA"), $$60.getField(0)]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            project ([$$58, $$60])
                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                              assign [$$60] <- [$$t1.getField(0)]
                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                  -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                                  unnest-map [$$58, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$74, true, false, false)
+                                                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                                                    exchange
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                      assign [$$74] <- [10]
                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                        empty-tuple-source
                                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/01.plan
index a33f232..5da6933 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/01.plan
@@ -1,22 +1,44 @@
+distribute result [$$30]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$30])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$30] <- [{"a": $$a, "b": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$33, $$b.getField("nested").getField("fname")))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$a, $$33, $$b])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- BTREE_SEARCH (test.ds2.ds2)  |PARTITIONED|
+                unnest-map [$$32, $$b] <- index-search("ds2", 0, "test", "ds2", true, false, 1, $$40, 1, $$40, true, true, true)
+                -- BTREE_SEARCH  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    order (ASC, $$40)
                     -- STABLE_SORT [$$40(ASC)]  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$a, $$33, $$40])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.ds2.idx)  |PARTITIONED|
+                            unnest-map [$$38, $$39, $$40] <- index-search("idx", 0, "test", "ds2", true, true, 1, $$33, 1, $$33, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                assign [$$33] <- [to-string($$a.getField("nested").getField("fname"))]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$a])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.ds1)  |PARTITIONED|
+                                      data-scan []<-[$$31, $$a] <- test.ds1
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/02.plan
index 347599b..73aff77 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/02.plan
@@ -1,22 +1,44 @@
+distribute result [$$30]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$30])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$30] <- [{"a": $$a, "b": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$33, $$b.getField("nested").getField("fname")))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$a, $$33, $$b])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- BTREE_SEARCH (test.ds2.ds2)  |PARTITIONED|
+                unnest-map [$$32, $$b] <- index-search("ds2", 0, "test", "ds2", true, false, 1, $$41, 1, $$41, true, true, true)
+                -- BTREE_SEARCH  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    order (ASC, $$41)
                     -- STABLE_SORT [$$41(ASC)]  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$a, $$33, $$41])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.ds2.idx)  |PARTITIONED|
+                            unnest-map [$$38, $$39, $$40, $$41] <- index-search("idx", 0, "test", "ds2", true, true, 1, $$33, 1, $$33, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                assign [$$33] <- [to-string($$a.getField("nested").getField("fname"))]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$a])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.ds1)  |PARTITIONED|
+                                      data-scan []<-[$$31, $$a] <- test.ds1
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/03.plan
index 04e6d71..a23c398 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/03.plan
@@ -1,30 +1,60 @@
+distribute result [$$33]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$33])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$33] <- [{"c1": $$44, "c2": $$45}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$44(ASC), $$45(ASC) ]  |PARTITIONED|
+          order (ASC, $$44) (ASC, $$45)
           -- STABLE_SORT [$$44(ASC), $$45(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$44, $$45])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  join (eq($$42, $$43))
                   -- HYBRID_HASH_JOIN [$$42][$$43]  |PARTITIONED|
+                    exchange
                     -- HASH_PARTITION_EXCHANGE [$$42]  |PARTITIONED|
+                      project ([$$44, $$42])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$44, $$42] <- [$$48.getField("c_x"), $$48.getField("c_s")]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$48])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$48] <- [$$t1.getField("nested")]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$t1])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.TestOpen1)  |PARTITIONED|
+                                  data-scan []<-[$$40, $$t1] <- test.TestOpen1
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                    exchange
                     -- HASH_PARTITION_EXCHANGE [$$43]  |PARTITIONED|
+                      project ([$$45, $$43])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$45, $$43] <- [$$49.getField("c_x"), $$49.getField("c_s")]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$49])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$49] <- [$$t2.getField("nested")]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$t2])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.TestOpen2)  |PARTITIONED|
+                                  data-scan []<-[$$41, $$t2] <- test.TestOpen2
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/04.plan
index 04e6d71..a23c398 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/04.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/04.plan
@@ -1,30 +1,60 @@
+distribute result [$$33]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$33])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$33] <- [{"c1": $$44, "c2": $$45}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$44(ASC), $$45(ASC) ]  |PARTITIONED|
+          order (ASC, $$44) (ASC, $$45)
           -- STABLE_SORT [$$44(ASC), $$45(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$44, $$45])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  join (eq($$42, $$43))
                   -- HYBRID_HASH_JOIN [$$42][$$43]  |PARTITIONED|
+                    exchange
                     -- HASH_PARTITION_EXCHANGE [$$42]  |PARTITIONED|
+                      project ([$$44, $$42])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$44, $$42] <- [$$48.getField("c_x"), $$48.getField("c_s")]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$48])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$48] <- [$$t1.getField("nested")]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$t1])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.TestOpen1)  |PARTITIONED|
+                                  data-scan []<-[$$40, $$t1] <- test.TestOpen1
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                    exchange
                     -- HASH_PARTITION_EXCHANGE [$$43]  |PARTITIONED|
+                      project ([$$45, $$43])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$45, $$43] <- [$$49.getField("c_x"), $$49.getField("c_s")]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$49])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$49] <- [$$t2.getField("nested")]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$t2])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.TestOpen2)  |PARTITIONED|
+                                  data-scan []<-[$$41, $$t2] <- test.TestOpen2
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/05.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/05.plan
index 97401bb..26e854a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/05.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/05.plan
@@ -1,30 +1,60 @@
+distribute result [$$34]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$34])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$34] <- [{"c1": $$46, "c2": $$47}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$46(ASC), $$47(ASC) ]  |PARTITIONED|
+          order (ASC, $$46) (ASC, $$47)
           -- STABLE_SORT [$$46(ASC), $$47(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$46, $$47])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  join (eq($$43, $$44))
                   -- HYBRID_HASH_JOIN [$$43][$$44]  |PARTITIONED|
+                    exchange
                     -- HASH_PARTITION_EXCHANGE [$$43]  |PARTITIONED|
+                      project ([$$46, $$43])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$43, $$46] <- [to-string($$50.getField("c_s")), $$50.getField("c_x")]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$50])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$50] <- [$$t1.getField("nested")]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$t1])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.TestOpen1)  |PARTITIONED|
+                                  data-scan []<-[$$41, $$t1] <- test.TestOpen1
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                    exchange
                     -- HASH_PARTITION_EXCHANGE [$$44]  |PARTITIONED|
+                      project ([$$47, $$44])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$47, $$44] <- [$$51.getField("c_x"), $$51.getField("c_s")]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$51])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$51] <- [$$t2.getField("nested")]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$t2])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.TestOpen2)  |PARTITIONED|
+                                  data-scan []<-[$$42, $$t2] <- test.TestOpen2
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/06.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/06.plan
index 4eb7b4f..51a3735 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/06.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/06.plan
@@ -1,31 +1,62 @@
+distribute result [$$34]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$34])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$34] <- [{"c1": $$46, "c2": $$47}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$46(ASC), $$47(ASC) ]  |PARTITIONED|
+          order (ASC, $$46) (ASC, $$47)
           -- STABLE_SORT [$$46(ASC), $$47(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$46, $$47])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (eq($$43, $$51.getField("c_s")))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$47] <- [$$51.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$46, $$43, $$51])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$51] <- [$$t2.getField("nested")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$46, $$43, $$t2])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.TestOpen2.TestOpen2)  |PARTITIONED|
+                            unnest-map [$$42, $$t2] <- index-search("TestOpen2", 0, "test", "TestOpen2", true, false, 1, $$54, 1, $$54, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$54)
                                 -- STABLE_SORT [$$54(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$46, $$43, $$54])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.TestOpen2.idx_t2_s)  |PARTITIONED|
+                                        unnest-map [$$52, $$53, $$54] <- index-search("idx_t2_s", 0, "test", "TestOpen2", true, true, 1, $$43, 1, $$43, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                            project ([$$43, $$46])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$43, $$46] <- [to-string($$50.getField("c_s")), $$50.getField("c_x")]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$50])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$50] <- [$$t1.getField("nested")]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$t1])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.TestOpen1)  |PARTITIONED|
+                                                        data-scan []<-[$$41, $$t1] <- test.TestOpen1
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/07.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/07.plan
index 6ecffbf..b884a87 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/07.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/07.plan
@@ -1,31 +1,62 @@
+distribute result [$$34]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$34])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$34] <- [{"c1": $$46, "c2": $$47}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$46(ASC), $$47(ASC) ]  |PARTITIONED|
+          order (ASC, $$46) (ASC, $$47)
           -- STABLE_SORT [$$46(ASC), $$47(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$46, $$47])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (eq($$43, $$51.getField("c_i64")))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$47] <- [$$51.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$46, $$43, $$51])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$51] <- [$$t2.getField("nested")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$46, $$43, $$t2])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.TestOpen2.TestOpen2)  |PARTITIONED|
+                            unnest-map [$$42, $$t2] <- index-search("TestOpen2", 0, "test", "TestOpen2", true, false, 1, $$54, 1, $$54, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$54)
                                 -- STABLE_SORT [$$54(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$46, $$43, $$54])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.TestOpen2.idx_t2_i64)  |PARTITIONED|
+                                        unnest-map [$$52, $$53, $$54] <- index-search("idx_t2_i64", 0, "test", "TestOpen2", true, true, 1, $$43, 1, $$43, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                            project ([$$43, $$46])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$43, $$46] <- [to-bigint($$50.getField("c_i64")), $$50.getField("c_x")]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$50])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$50] <- [$$t1.getField("nested")]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$t1])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.TestOpen1)  |PARTITIONED|
+                                                        data-scan []<-[$$41, $$t1] <- test.TestOpen1
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/01.plan
index 2ac8171..3444d2b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/01.plan
@@ -1,15 +1,30 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (gt($$emp.getField("nested").getField("fname"), "Roger"))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+          unnest-map [$$15, $$emp] <- index-search("testdst", 0, "test", "testdst", false, false, 1, $$21, 1, $$21, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$21)
               -- STABLE_SORT [$$21(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$21])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                      unnest-map [$$19, $$20, $$21] <- index-search("sec_Idx", 0, "test", "testdst", false, false, 1, $$18, 0, false, true, false)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$18] <- ["Roger"]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/02.plan
index 0746bd8..92eb1f7 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/02.plan
@@ -1,15 +1,30 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (gt($$emp.getField("nested").getField("address").getField("zip"), "97777"))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+          unnest-map [$$16, $$emp] <- index-search("testdst", 0, "test", "testdst", false, false, 1, $$24, 1, $$24, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$24)
               -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$24])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                      unnest-map [$$21, $$22, $$23, $$24] <- index-search("sec_Idx", 0, "test", "testdst", false, false, 1, $$20, 0, false, true, false)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$20] <- ["97777"]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/03.plan
index 13f9dcf..081fc97 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/03.plan
@@ -1,22 +1,44 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$17] <- [{"res": $$21}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$21(ASC) ]  |PARTITIONED|
+          order (ASC, $$21)
           -- STABLE_SORT [$$21(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$21])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (eq($$t.getField("nested").getField("c_i64"), 2))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$21] <- [$$t.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$t])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                        unnest-map [$$19, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$28, 1, $$28, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$28)
                             -- STABLE_SORT [$$28(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$28])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- BTREE_SEARCH (test.TestOpen.idx_i64)  |PARTITIONED|
+                                    unnest-map [$$26, $$27, $$28] <- index-search("idx_i64", 0, "test", "TestOpen", false, false, 1, $$24, 1, $$25, true, true, true)
+                                    -- BTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        assign [$$24, $$25] <- [2, 2]
                                         -- ASSIGN  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/04.plan
index ceb8921..9fec9eb 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/04.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/04.plan
@@ -1,24 +1,48 @@
+distribute result [$$18]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$18])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$18] <- [{"res": $$24}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$24(ASC) ]  |PARTITIONED|
+          order (ASC, $$24)
           -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$24])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (eq($$26.getField("c_s"), "world"))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$24] <- [$$26.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$26])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$26] <- [$$t.getField("nested")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$t])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                            unnest-map [$$22, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$31, 1, $$31, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$31)
                                 -- STABLE_SORT [$$31(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$31])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.TestOpen.idx_s)  |PARTITIONED|
+                                        unnest-map [$$29, $$30, $$31] <- index-search("idx_s", 0, "test", "TestOpen", false, false, 1, $$27, 1, $$28, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            assign [$$27, $$28] <- ["world", "world"]
                                             -- ASSIGN  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/05.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/05.plan
index 2cf4812..eb5c0c0 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/05.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/05.plan
@@ -1,24 +1,48 @@
+distribute result [$$18]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$18])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$18] <- [{"res": $$24}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$24(ASC) ]  |PARTITIONED|
+          order (ASC, $$24)
           -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$24])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (eq($$26.getField("c_i64"), 2))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$24] <- [$$26.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$26])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$26] <- [$$t.getField("nested")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$t])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                            unnest-map [$$22, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$31, 1, $$31, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$31)
                                 -- STABLE_SORT [$$31(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$31])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.TestOpen.idx_i64)  |PARTITIONED|
+                                        unnest-map [$$29, $$30, $$31] <- index-search("idx_i64", 0, "test", "TestOpen", false, false, 1, $$27, 1, $$28, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            assign [$$27, $$28] <- [2, 2]
                                             -- ASSIGN  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/06.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/06.plan
index a63d87f..1e86283 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/06.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/06.plan
@@ -1,24 +1,48 @@
+distribute result [$$18]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$18])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$18] <- [{"res": $$24}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$24(ASC) ]  |PARTITIONED|
+          order (ASC, $$24)
           -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$24])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (gt($$26.getField("c_i64"), 2))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$24] <- [$$26.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$26])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$26] <- [$$t.getField("nested")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$t])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                            unnest-map [$$22, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$30, 1, $$30, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$30)
                                 -- STABLE_SORT [$$30(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$30])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.TestOpen.idx_i64)  |PARTITIONED|
+                                        unnest-map [$$28, $$29, $$30] <- index-search("idx_i64", 0, "test", "TestOpen", false, false, 1, $$27, 0, true, true, false)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            assign [$$27] <- [2]
                                             -- ASSIGN  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/07.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/07.plan
index a63d87f..6cbe345 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/07.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/07.plan
@@ -1,24 +1,48 @@
+distribute result [$$18]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$18])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$18] <- [{"res": $$24}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$24(ASC) ]  |PARTITIONED|
+          order (ASC, $$24)
           -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$24])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (gt($$26.getField("c_i64"), 2.0))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$24] <- [$$26.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$26])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$26] <- [$$t.getField("nested")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$t])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                            unnest-map [$$22, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$30, 1, $$30, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$30)
                                 -- STABLE_SORT [$$30(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$30])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.TestOpen.idx_i64)  |PARTITIONED|
+                                        unnest-map [$$28, $$29, $$30] <- index-search("idx_i64", 0, "test", "TestOpen", false, false, 1, $$27, 0, true, true, false)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            assign [$$27] <- [2]
                                             -- ASSIGN  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/08.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/08.plan
index ef289a4..1a16d23 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/08.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/08.plan
@@ -1,24 +1,48 @@
+distribute result [$$18]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$18])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$18] <- [{"res": $$24}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$24(ASC) ]  |PARTITIONED|
+          order (ASC, $$24)
           -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$24])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (gt($$26.getField("c_i8"), 2))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$24] <- [$$26.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$26])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$26] <- [$$t.getField("nested")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$t])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                            unnest-map [$$22, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$30, 1, $$30, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$30)
                                 -- STABLE_SORT [$$30(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$30])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.TestOpen.idx_i8)  |PARTITIONED|
+                                        unnest-map [$$28, $$29, $$30] <- index-search("idx_i8", 0, "test", "TestOpen", false, false, 1, $$27, 0, true, true, false)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            assign [$$27] <- [2]
                                             -- ASSIGN  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/09.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/09.plan
index ef289a4..ccd8760 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/09.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/09.plan
@@ -1,24 +1,48 @@
+distribute result [$$18]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$18])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$18] <- [{"res": $$24}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$24(ASC) ]  |PARTITIONED|
+          order (ASC, $$24)
           -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$24])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (gt($$26.getField("c_i8"), 2.5))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$24] <- [$$26.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$26])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$26] <- [$$t.getField("nested")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$t])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                            unnest-map [$$22, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$30, 1, $$30, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$30)
                                 -- STABLE_SORT [$$30(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$30])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.TestOpen.idx_i8)  |PARTITIONED|
+                                        unnest-map [$$28, $$29, $$30] <- index-search("idx_i8", 0, "test", "TestOpen", false, false, 1, $$27, 0, true, true, false)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            assign [$$27] <- [2]
                                             -- ASSIGN  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/10.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/10.plan
index c3e596b..b79fbb1 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/10.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/10.plan
@@ -1,24 +1,48 @@
+distribute result [$$18]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$18])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$18] <- [{"res": $$24}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$24(ASC) ]  |PARTITIONED|
+          order (ASC, $$24)
           -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$24])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (ge($$26.getField("c_d"), 3.25))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$24] <- [$$26.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$26])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$26] <- [$$t.getField("nested")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$t])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                            unnest-map [$$22, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$30, 1, $$30, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$30)
                                 -- STABLE_SORT [$$30(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$30])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.TestOpen.idx_d)  |PARTITIONED|
+                                        unnest-map [$$28, $$29, $$30] <- index-search("idx_d", 0, "test", "TestOpen", false, false, 1, $$27, 0, true, true, false)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            assign [$$27] <- [3.25]
                                             -- ASSIGN  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/11.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/11.plan
index 7fb98d3..8ec528a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/11.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/11.plan
@@ -1,25 +1,50 @@
+distribute result [$$22]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$22])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$22] <- [{"res": $$29}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$29(ASC) ]  |PARTITIONED|
+          order (ASC, $$29)
           -- STABLE_SORT [$$29(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$29])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (and(gt($$25, 499), lt($$25, 99999)))
                 -- STREAM_SELECT  |PARTITIONED|
+                  project ([$$29, $$25])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$29, $$25] <- [$$31.getField("c_x"), $$31.getField("c_i8")]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$31])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$31] <- [$$t.getField("nested")]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$t])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                              unnest-map [$$27, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$36, 1, $$36, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  order (ASC, $$36)
                                   -- STABLE_SORT [$$36(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$36])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (test.TestOpen.idx_i8)  |PARTITIONED|
+                                          unnest-map [$$34, $$35, $$36] <- index-search("idx_i8", 0, "test", "TestOpen", false, false, 1, $$32, 1, $$33, true, true, false)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$32, $$33] <- [127, 127]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/12.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/12.plan
index fcc0784..f69d31e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/12.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/btree-index/non-enforced-composite-key/12.plan
@@ -1,35 +1,70 @@
+distribute result [$$22]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$22])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$22] <- [{"res": $$29}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$29(ASC) ]  |PARTITIONED|
+          order (ASC, $$29)
           -- STABLE_SORT [$$29(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$29])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (and(gt($$31.getField("c_i8"), 2), lt($$31.getField("c_i64"), 3)))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$29] <- [$$31.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$31])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$31] <- [$$t.getField("nested")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$t])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                            unnest-map [$$26, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$40, 1, $$40, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                intersect [$$40] <- [[$$35], [$$39]]
                                 -- INTERSECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$35)
                                     -- STABLE_SORT [$$35(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$35])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (test.TestOpen.idx_3)  |PARTITIONED|
+                                            unnest-map [$$33, $$34, $$35] <- index-search("idx_3", 0, "test", "TestOpen", false, false, 0, 1, $$32, true, true, false)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$32] <- [3]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$39)
                                     -- STABLE_SORT [$$39(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$39])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (test.TestOpen.idx_4)  |PARTITIONED|
+                                            unnest-map [$$37, $$38, $$39] <- index-search("idx_4", 0, "test", "TestOpen", false, false, 1, $$36, 0, true, true, false)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$36] <- [2]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-basic/ngram-contains-panic_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-basic/ngram-contains-panic_ps.plan
index 5a051c1..94594ff 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-basic/ngram-contains-panic_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-basic/ngram-contains-panic_ps.plan
@@ -1,28 +1,56 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$o])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$17)
         -- STABLE_SORT [$$17(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$17(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$23
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (contains($$o.getField(0).getField("title"), "Mu"))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                        data-scan []<-[$$17, $$o] <- test.DBLP
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$23] <- [agg-range-map($$21, $$22)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$21, $$22] <- [agg-local-sampling($$17), agg-null-writer($$17)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$17])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (contains($$o.getField(0).getField("title"), "Mu"))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                  data-scan []<-[$$17, $$o] <- test.DBLP
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-basic/ngram-contains_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-basic/ngram-contains_ps.plan
index e0dd2e4..65bbe6e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-basic/ngram-contains_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-basic/ngram-contains_ps.plan
@@ -1,38 +1,76 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$o])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$17)
         -- STABLE_SORT [$$17(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$17(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$25
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (contains($$o.getField(0).getField("title"), "Multimedia"))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                        unnest-map [$$17, $$o] <- index-search("DBLP", 0, "test", "DBLP", false, false, 1, $$22, 1, $$22, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$22)
                             -- STABLE_SORT [$$22(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                                unnest-map [$$22] <- index-search("ngram_index", 5, "test", "DBLP", false, false, 0, missing, 12, false, 1, $$21)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    assign [$$21] <- ["Multimedia"]
                                     -- ASSIGN  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$25] <- [agg-range-map($$23, $$24)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$23, $$24] <- [agg-local-sampling($$17), agg-null-writer($$17)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$17])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (contains($$o.getField(0).getField("title"), "Multimedia"))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                                  unnest-map [$$17, $$o] <- index-search("DBLP", 0, "test", "DBLP", false, false, 1, $$22, 1, $$22, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$22)
                                       -- STABLE_SORT [$$22(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                                          unnest-map [$$22] <- index-search("ngram_index", 5, "test", "DBLP", false, false, 0, missing, 12, false, 1, $$21)
+                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$21] <- ["Multimedia"]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-basic/word-contains_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-basic/word-contains_ps.plan
index 5a051c1..36c0dff 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-basic/word-contains_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-basic/word-contains_ps.plan
@@ -1,28 +1,56 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$o])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$17)
         -- STABLE_SORT [$$17(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$17(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$23
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (contains($$o.getField(0).getField("title"), "Multimedia"))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                        data-scan []<-[$$17, $$o] <- test.DBLP
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$23] <- [agg-range-map($$21, $$22)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$21, $$22] <- [agg-local-sampling($$17), agg-null-writer($$17)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$17])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (contains($$o.getField(0).getField("title"), "Multimedia"))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                  data-scan []<-[$$17, $$o] <- test.DBLP
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01_ps.plan
index 8b6b284..5130d4d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01_ps.plan
@@ -1,190 +1,374 @@
+distribute result [$$66]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$66])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$66] <- [{"tweet": {"id": $$77, "topics": $$84}, "similar-tweets": $$65}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$65, $$84, $$77])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            order (ASC, $$86)
             -- STABLE_SORT [$$86(ASC)]  |PARTITIONED|
+              exchange
               -- RANGE_PARTITION_EXCHANGE [$$86(ASC)]  |PARTITIONED|
+                forward: shared-variable = $$107
                 -- FORWARD  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- PRE_CLUSTERED_GROUP_BY[$$71]  |PARTITIONED|
-                                {
+                        group by ([$$86 := $$71]) decor ([$$84; $$77]) {
+                                  aggregate [$$65] <- [listify({"id": $$76, "topics": $$79})]
                                   -- AGGREGATE  |LOCAL|
+                                    select (not(is-missing($$72)))
                                     -- STREAM_SELECT  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                }
+                               }
+                        -- PRE_CLUSTERED_GROUP_BY[$$71]  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$71) (ASC, $$72)
                             -- STABLE_SORT [$$71(ASC), $$72(ASC)]  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$71]  |PARTITIONED|
+                                project ([$$77, $$84, $$76, $$79, $$72, $$71])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    join (eq($$92, $$71))
                                     -- HYBRID_HASH_JOIN [$$92][$$71]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$77, $$92])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$77] <- [$$t1.getField(0).getField(0)]
                                           -- ASSIGN  |PARTITIONED|
+                                            project ([$$92, $$t1])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$92, $$t1] <- [$$71, $$95]
                                               -- ASSIGN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  replicate
                                                   -- REPLICATE  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                      unnest-map [$$71, $$95] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$96, 0, false, true, false)
+                                                      -- BTREE_SEARCH  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          assign [$$96] <- [240]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$71]  |PARTITIONED|
+                                        union ($$72, $$103, $$72) ($$79, $$99, $$79) ($$76, $$100, $$76) ($$71, $$71, $$71) ($$84, $$84, $$84)
                                         -- UNION_ALL  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$72, $$79, $$76, $$71, $$84])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              select (and(neq($$76, $$93), get-item(edit-distance-check($$84, $$79, 7), 0))) retain-untrue ($$72 <- MISSING)
                                               -- STREAM_SELECT  |PARTITIONED|
+                                                project ([$$71, $$84, $$93, $$72, $$79, $$76])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$79, $$76] <- [$$74.getField("message-text"), $$74.getField(0)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$71, $$84, $$93, $$72, $$74])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      assign [$$74] <- [$$t2.getField(0)]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        project ([$$71, $$84, $$93, $$72, $$t2])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                            left-outer-unnest-map [$$72, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$104, 1, $$104, true, true, true)
+                                                            -- BTREE_SEARCH  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                order (ASC, $$104)
                                                                 -- STABLE_SORT [$$104(ASC)]  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.TweetMessages.msgNgramIx)  |PARTITIONED|
+                                                                    left-outer-unnest-map [$$104] <- index-search("msgNgramIx", 5, "test", "TweetMessages", true, true, 2, 7, 12, false, 1, $$84)
+                                                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                                                      exchange
                                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                        select (edit-distance-string-is-filterable($$84, 7, 3, true))
                                                                         -- STREAM_SELECT  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            replicate
                                                                             -- REPLICATE  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                project ([$$71, $$84, $$93])
                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                  assign [$$84, $$93] <- [$$94.getField("message-text"), $$94.getField(0)]
                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                    project ([$$71, $$94])
                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                      assign [$$94] <- [$$95.getField(0)]
                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                        exchange
                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                          replicate
                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                            exchange
                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                              -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                                              unnest-map [$$71, $$95] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$96, 0, false, true, false)
+                                                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                                                exchange
                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                  assign [$$96] <- [240]
                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                    empty-tuple-source
                                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$103, $$99, $$100, $$71, $$84])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                left outer join (and(neq($$100, $$93), get-item(edit-distance-check($$84, $$99, 7), 0)))
                                                 -- NESTED_LOOP  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$$103, $$99, $$100])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      assign [$$99, $$100] <- [$$101.getField("message-text"), $$101.getField(0)]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        project ([$$103, $$101])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$101] <- [$$102.getField(0)]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- DATASOURCE_SCAN (test.TweetMessages)  |PARTITIONED|
+                                                              data-scan []<-[$$103, $$102] <- test.TweetMessages
+                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  empty-tuple-source
                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                  exchange
                                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                    select (not(edit-distance-string-is-filterable($$84, 7, 3, true)))
                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        replicate
                                                         -- REPLICATE  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            project ([$$71, $$84, $$93])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$84, $$93] <- [$$94.getField("message-text"), $$94.getField(0)]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                project ([$$71, $$94])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  assign [$$94] <- [$$95.getField(0)]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      replicate
                                                                       -- REPLICATE  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                          -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                          unnest-map [$$71, $$95] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$96, 0, false, true, false)
+                                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              assign [$$96] <- [240]
                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                empty-tuple-source
                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    aggregate [$$107] <- [agg-range-map($$105, $$106)]
                     -- AGGREGATE  |UNPARTITIONED|
+                      exchange
                       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                        aggregate [$$105, $$106] <- [agg-local-sampling($$86), agg-null-writer($$86)]
                         -- AGGREGATE  |PARTITIONED|
+                          project ([$$86])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              replicate
                               -- REPLICATE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- PRE_CLUSTERED_GROUP_BY[$$71]  |PARTITIONED|
-                                          {
+                                  group by ([$$86 := $$71]) decor ([$$84; $$77]) {
+                                            aggregate [$$65] <- [listify({"id": $$76, "topics": $$79})]
                                             -- AGGREGATE  |LOCAL|
+                                              select (not(is-missing($$72)))
                                               -- STREAM_SELECT  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                         }
+                                  -- PRE_CLUSTERED_GROUP_BY[$$71]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$71) (ASC, $$72)
                                       -- STABLE_SORT [$$71(ASC), $$72(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$71]  |PARTITIONED|
+                                          project ([$$77, $$84, $$76, $$79, $$72, $$71])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              join (eq($$92, $$71))
                                               -- HYBRID_HASH_JOIN [$$92][$$71]  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  project ([$$77, $$92])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    assign [$$77] <- [$$t1.getField(0).getField(0)]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      project ([$$92, $$t1])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$92, $$t1] <- [$$71, $$95]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            replicate
                                                             -- REPLICATE  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                unnest-map [$$71, $$95] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$96, 0, false, true, false)
+                                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    assign [$$96] <- [240]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      empty-tuple-source
                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$71]  |PARTITIONED|
+                                                  union ($$72, $$103, $$72) ($$79, $$99, $$79) ($$76, $$100, $$76) ($$71, $$71, $$71) ($$84, $$84, $$84)
                                                   -- UNION_ALL  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      project ([$$72, $$79, $$76, $$71, $$84])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        select (and(neq($$76, $$93), get-item(edit-distance-check($$84, $$79, 7), 0))) retain-untrue ($$72 <- MISSING)
                                                         -- STREAM_SELECT  |PARTITIONED|
+                                                          project ([$$71, $$84, $$93, $$72, $$79, $$76])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            assign [$$79, $$76] <- [$$74.getField("message-text"), $$74.getField(0)]
                                                             -- ASSIGN  |PARTITIONED|
+                                                              project ([$$71, $$84, $$93, $$72, $$74])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$74] <- [$$t2.getField(0)]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  project ([$$71, $$84, $$93, $$72, $$t2])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                      left-outer-unnest-map [$$72, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$104, 1, $$104, true, true, true)
+                                                                      -- BTREE_SEARCH  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          order (ASC, $$104)
                                                                           -- STABLE_SORT [$$104(ASC)]  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                              -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.TweetMessages.msgNgramIx)  |PARTITIONED|
+                                                                              left-outer-unnest-map [$$104] <- index-search("msgNgramIx", 5, "test", "TweetMessages", true, true, 2, 7, 12, false, 1, $$84)
+                                                                              -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                                                                exchange
                                                                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                  select (edit-distance-string-is-filterable($$84, 7, 3, true))
                                                                                   -- STREAM_SELECT  |PARTITIONED|
+                                                                                    exchange
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                      replicate
                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                        exchange
                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                          project ([$$71, $$84, $$93])
                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                            assign [$$84, $$93] <- [$$94.getField("message-text"), $$94.getField(0)]
                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                              project ([$$71, $$94])
                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                assign [$$94] <- [$$95.getField(0)]
                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                  exchange
                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                    replicate
                                                                                                     -- REPLICATE  |PARTITIONED|
+                                                                                                      exchange
                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                                                        unnest-map [$$71, $$95] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$96, 0, false, true, false)
+                                                                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                                                                          exchange
                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                            assign [$$96] <- [240]
                                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                                              empty-tuple-source
                                                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      project ([$$103, $$99, $$100, $$71, $$84])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          left outer join (and(neq($$100, $$93), get-item(edit-distance-check($$84, $$99, 7), 0)))
                                                           -- NESTED_LOOP  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              project ([$$103, $$99, $$100])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$99, $$100] <- [$$101.getField("message-text"), $$101.getField(0)]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  project ([$$103, $$101])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    assign [$$101] <- [$$102.getField(0)]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                        -- DATASOURCE_SCAN (test.TweetMessages)  |PARTITIONED|
+                                                                        data-scan []<-[$$103, $$102] <- test.TweetMessages
+                                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            empty-tuple-source
                                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                            exchange
                                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                              select (not(edit-distance-string-is-filterable($$84, 7, 3, true)))
                                                               -- STREAM_SELECT  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  replicate
                                                                   -- REPLICATE  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      project ([$$71, $$84, $$93])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        assign [$$84, $$93] <- [$$94.getField("message-text"), $$94.getField(0)]
                                                                         -- ASSIGN  |PARTITIONED|
+                                                                          project ([$$71, $$94])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            assign [$$94] <- [$$95.getField(0)]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                replicate
                                                                                 -- REPLICATE  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                    -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                                    unnest-map [$$71, $$95] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$96, 0, false, true, false)
+                                                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                        assign [$$96] <- [240]
                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                          empty-tuple-source
                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-join/ngram-contains_01_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-join/ngram-contains_01_ps.plan
index fa450a0..00fd7c9 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-join/ngram-contains_01_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-join/ngram-contains_01_ps.plan
@@ -1,50 +1,100 @@
+distribute result [$$33]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$33])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$33] <- [{"title1": $$36, "title2": $$37}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$36, $$37])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            order (ASC, $$38) (ASC, $$39)
             -- STABLE_SORT [$$38(ASC), $$39(ASC)]  |PARTITIONED|
+              exchange
               -- RANGE_PARTITION_EXCHANGE [$$38(ASC), $$39(ASC)]  |PARTITIONED|
+                forward: shared-variable = $$47
                 -- FORWARD  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        join (and(contains($$36, $$37), lt($$38, $$39)))
                         -- NESTED_LOOP  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$36, $$38])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$36] <- [$$o1.getField("title")]
                               -- ASSIGN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                  data-scan []<-[$$38, $$o1] <- test.DBLP
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                            project ([$$37, $$39])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$37] <- [$$o2.getField(2)]
                               -- ASSIGN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.CSX)  |PARTITIONED|
+                                  data-scan []<-[$$39, $$o2] <- test.CSX
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    aggregate [$$47] <- [agg-range-map($$44, $$45, $$46)]
                     -- AGGREGATE  |UNPARTITIONED|
+                      exchange
                       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                        aggregate [$$44, $$45, $$46] <- [agg-local-sampling($$38, $$39), agg-null-writer($$38), agg-null-writer($$39)]
                         -- AGGREGATE  |PARTITIONED|
+                          project ([$$38, $$39])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              replicate
                               -- REPLICATE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  join (and(contains($$36, $$37), lt($$38, $$39)))
                                   -- NESTED_LOOP  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$36, $$38])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$36] <- [$$o1.getField("title")]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                            data-scan []<-[$$38, $$o1] <- test.DBLP
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                      project ([$$37, $$39])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$37] <- [$$o2.getField(2)]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (test.CSX)  |PARTITIONED|
+                                            data-scan []<-[$$39, $$o2] <- test.CSX
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-join/ngram-contains_02_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-join/ngram-contains_02_ps.plan
index 95adac0..f7c8eb2 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-join/ngram-contains_02_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-join/ngram-contains_02_ps.plan
@@ -1,50 +1,100 @@
+distribute result [$$33]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$33])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$33] <- [{"title1": $$36, "title2": $$37}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$36, $$37])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            order (ASC, $$38) (ASC, $$39)
             -- STABLE_SORT [$$38(ASC), $$39(ASC)]  |PARTITIONED|
+              exchange
               -- RANGE_PARTITION_EXCHANGE [$$38(ASC), $$39(ASC)]  |PARTITIONED|
+                forward: shared-variable = $$47
                 -- FORWARD  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        join (and(contains($$36, $$37), lt($$38, $$39)))
                         -- NESTED_LOOP  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$36, $$38])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$36] <- [$$o1.getField("title")]
                               -- ASSIGN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.CSX)  |PARTITIONED|
+                                  data-scan []<-[$$38, $$o1] <- test.CSX
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                            project ([$$37, $$39])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$37] <- [$$o2.getField(2)]
                               -- ASSIGN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                  data-scan []<-[$$39, $$o2] <- test.DBLP
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    aggregate [$$47] <- [agg-range-map($$44, $$45, $$46)]
                     -- AGGREGATE  |UNPARTITIONED|
+                      exchange
                       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                        aggregate [$$44, $$45, $$46] <- [agg-local-sampling($$38, $$39), agg-null-writer($$38), agg-null-writer($$39)]
                         -- AGGREGATE  |PARTITIONED|
+                          project ([$$38, $$39])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              replicate
                               -- REPLICATE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  join (and(contains($$36, $$37), lt($$38, $$39)))
                                   -- NESTED_LOOP  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$36, $$38])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$36] <- [$$o1.getField("title")]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (test.CSX)  |PARTITIONED|
+                                            data-scan []<-[$$38, $$o1] <- test.CSX
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                      project ([$$37, $$39])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$37] <- [$$o2.getField(2)]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                            data-scan []<-[$$39, $$o2] <- test.DBLP
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-join/ngram-contains_03_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-join/ngram-contains_03_ps.plan
index b7351a2..ba9b3ac 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-join/ngram-contains_03_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-join/ngram-contains_03_ps.plan
@@ -1,54 +1,108 @@
+distribute result [$$33]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$33])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$33] <- [{"title1": $$36, "title2": $$37}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$36, $$37])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            order (ASC, $$38) (ASC, $$39)
             -- STABLE_SORT [$$38(ASC), $$39(ASC)]  |PARTITIONED|
+              exchange
               -- RANGE_PARTITION_EXCHANGE [$$38(ASC), $$39(ASC)]  |PARTITIONED|
+                forward: shared-variable = $$52
                 -- FORWARD  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        select (and(contains($$36, $$37), lt($$38, $$39)))
                         -- STREAM_SELECT  |PARTITIONED|
+                          project ([$$38, $$36, $$39, $$37])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$37] <- [$$o2.getField("title")]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$38, $$36, $$39, $$o2])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                                  unnest-map [$$39, $$o2] <- index-search("DBLP", 0, "test", "DBLP", true, false, 1, $$48, 1, $$48, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$48)
                                       -- STABLE_SORT [$$48(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                                          unnest-map [$$48] <- index-search("ngram_index", 5, "test", "DBLP", true, true, 0, missing, 12, false, 1, $$36)
+                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                              project ([$$38, $$36])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$36] <- [$$47.getField("title")]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                                    data-scan []<-[$$38, $$47] <- test.DBLP
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    aggregate [$$52] <- [agg-range-map($$49, $$50, $$51)]
                     -- AGGREGATE  |UNPARTITIONED|
+                      exchange
                       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                        aggregate [$$49, $$50, $$51] <- [agg-local-sampling($$38, $$39), agg-null-writer($$38), agg-null-writer($$39)]
                         -- AGGREGATE  |PARTITIONED|
+                          project ([$$38, $$39])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              replicate
                               -- REPLICATE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  select (and(contains($$36, $$37), lt($$38, $$39)))
                                   -- STREAM_SELECT  |PARTITIONED|
+                                    project ([$$38, $$36, $$39, $$37])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$37] <- [$$o2.getField("title")]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$38, $$36, $$39, $$o2])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                                            unnest-map [$$39, $$o2] <- index-search("DBLP", 0, "test", "DBLP", true, false, 1, $$48, 1, $$48, true, true, true)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                order (ASC, $$48)
                                                 -- STABLE_SORT [$$48(ASC)]  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                                                    unnest-map [$$48] <- index-search("ngram_index", 5, "test", "DBLP", true, true, 0, missing, 12, false, 1, $$36)
+                                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                        project ([$$38, $$36])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$36] <- [$$47.getField("title")]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                                              data-scan []<-[$$38, $$47] <- test.DBLP
+                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  empty-tuple-source
                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-join/ngram-contains_04_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-join/ngram-contains_04_ps.plan
index 79aeeb4..d000e2f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-join/ngram-contains_04_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/inverted-index-join/ngram-contains_04_ps.plan
@@ -1,54 +1,108 @@
+distribute result [$$33]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$33])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$33] <- [{"title1": $$36, "title2": $$37}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$36, $$37])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            order (ASC, $$38) (ASC, $$39)
             -- STABLE_SORT [$$38(ASC), $$39(ASC)]  |PARTITIONED|
+              exchange
               -- RANGE_PARTITION_EXCHANGE [$$38(ASC), $$39(ASC)]  |PARTITIONED|
+                forward: shared-variable = $$52
                 -- FORWARD  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        select (and(contains($$36, $$37), lt($$38, $$39)))
                         -- STREAM_SELECT  |PARTITIONED|
+                          project ([$$38, $$36, $$39, $$37])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$37] <- [$$o2.getField("title")]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$38, $$36, $$39, $$o2])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.CSX.CSX)  |PARTITIONED|
+                                  unnest-map [$$39, $$o2] <- index-search("CSX", 0, "test", "CSX", true, false, 1, $$48, 1, $$48, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$48)
                                       -- STABLE_SORT [$$48(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.CSX.ngram_index_CSX)  |PARTITIONED|
+                                          unnest-map [$$48] <- index-search("ngram_index_CSX", 5, "test", "CSX", true, true, 0, missing, 12, false, 1, $$36)
+                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                              project ([$$38, $$36])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$36] <- [$$47.getField("title")]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                                    data-scan []<-[$$38, $$47] <- test.DBLP
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    aggregate [$$52] <- [agg-range-map($$49, $$50, $$51)]
                     -- AGGREGATE  |UNPARTITIONED|
+                      exchange
                       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                        aggregate [$$49, $$50, $$51] <- [agg-local-sampling($$38, $$39), agg-null-writer($$38), agg-null-writer($$39)]
                         -- AGGREGATE  |PARTITIONED|
+                          project ([$$38, $$39])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              replicate
                               -- REPLICATE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  select (and(contains($$36, $$37), lt($$38, $$39)))
                                   -- STREAM_SELECT  |PARTITIONED|
+                                    project ([$$38, $$36, $$39, $$37])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$37] <- [$$o2.getField("title")]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$38, $$36, $$39, $$o2])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (test.CSX.CSX)  |PARTITIONED|
+                                            unnest-map [$$39, $$o2] <- index-search("CSX", 0, "test", "CSX", true, false, 1, $$48, 1, $$48, true, true, true)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                order (ASC, $$48)
                                                 -- STABLE_SORT [$$48(ASC)]  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.CSX.ngram_index_CSX)  |PARTITIONED|
+                                                    unnest-map [$$48] <- index-search("ngram_index_CSX", 5, "test", "CSX", true, true, 0, missing, 12, false, 1, $$36)
+                                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                        project ([$$38, $$36])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$36] <- [$$47.getField("title")]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                                              data-scan []<-[$$38, $$47] <- test.DBLP
+                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  empty-tuple-source
                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01_ps.plan
index ee5703a..d39d784 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01_ps.plan
@@ -1,92 +1,178 @@
+distribute result [$$57]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$57])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$57] <- [{"tweetid1": $$65, "loc1": $$66, "nearby-message": $$56}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$56, $$65, $$66])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            order (ASC, $$74)
             -- STABLE_SORT [$$74(ASC)]  |PARTITIONED|
+              exchange
               -- RANGE_PARTITION_EXCHANGE [$$74(ASC)]  |PARTITIONED|
+                forward: shared-variable = $$89
                 -- FORWARD  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- PRE_CLUSTERED_GROUP_BY[$$61]  |PARTITIONED|
-                                {
+                        group by ([$$74 := $$61]) decor ([$$65; $$66]) {
+                                  aggregate [$$56] <- [listify({"tweetid2": $$68, "loc2": $$64})]
                                   -- AGGREGATE  |LOCAL|
+                                    select (not(is-missing($$62)))
                                     -- STREAM_SELECT  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                }
+                               }
+                        -- PRE_CLUSTERED_GROUP_BY[$$61]  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$61) (ASC, $$67)
                             -- STABLE_SORT [$$61(ASC), $$67(ASC)]  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$61]  |PARTITIONED|
+                                project ([$$65, $$66, $$68, $$64, $$67, $$62, $$61])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  select (spatial-intersect($$64, $$n)) retain-untrue ($$62 <- MISSING)
                                   -- STREAM_SELECT  |PARTITIONED|
+                                    project ([$$65, $$66, $$61, $$n, $$62, $$67, $$68, $$64])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$68, $$64] <- [$$63.getField(0), $$63.getField("sender-location")]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$65, $$66, $$61, $$n, $$62, $$63, $$67])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$63, $$67] <- [$$t2.getField(0), $$t2.getField("tweetid")]
                                           -- ASSIGN  |PARTITIONED|
+                                            project ([$$65, $$66, $$61, $$n, $$62, $$t2])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                left-outer-unnest-map [$$62, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$86, 1, $$86, true, true, true)
+                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    order (ASC, $$86)
                                                     -- STABLE_SORT [$$86(ASC)]  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        project ([$$65, $$66, $$61, $$n, $$86])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- RTREE_SEARCH (test.TweetMessages.twmSndLocIx)  |PARTITIONED|
+                                                            left-outer-unnest-map [$$82, $$83, $$84, $$85, $$86] <- index-search("twmSndLocIx", 1, "test", "TweetMessages", true, true, 4, $$78, $$79, $$80, $$81)
+                                                            -- RTREE_SEARCH  |PARTITIONED|
+                                                              exchange
                                                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                assign [$$78, $$79, $$80, $$81] <- [create-mbr($$n, 2, 0), create-mbr($$n, 2, 1), create-mbr($$n, 2, 2), create-mbr($$n, 2, 3)]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  assign [$$n] <- [create-circle($$66, 0.5)]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    project ([$$61, $$66, $$65])
                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                      assign [$$66, $$65] <- [$$60.getField("sender-location"), $$60.getField(0)]
                                                                       -- ASSIGN  |PARTITIONED|
+                                                                        project ([$$61, $$60])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          assign [$$60] <- [$$t1.getField(0)]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                              -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                              unnest-map [$$61, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$75, true, false, false)
+                                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  assign [$$75] <- [10]
                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                    empty-tuple-source
                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    aggregate [$$89] <- [agg-range-map($$87, $$88)]
                     -- AGGREGATE  |UNPARTITIONED|
+                      exchange
                       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                        aggregate [$$87, $$88] <- [agg-local-sampling($$74), agg-null-writer($$74)]
                         -- AGGREGATE  |PARTITIONED|
+                          project ([$$74])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              replicate
                               -- REPLICATE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- PRE_CLUSTERED_GROUP_BY[$$61]  |PARTITIONED|
-                                          {
+                                  group by ([$$74 := $$61]) decor ([$$65; $$66]) {
+                                            aggregate [$$56] <- [listify({"tweetid2": $$68, "loc2": $$64})]
                                             -- AGGREGATE  |LOCAL|
+                                              select (not(is-missing($$62)))
                                               -- STREAM_SELECT  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                         }
+                                  -- PRE_CLUSTERED_GROUP_BY[$$61]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$61) (ASC, $$67)
                                       -- STABLE_SORT [$$61(ASC), $$67(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$61]  |PARTITIONED|
+                                          project ([$$65, $$66, $$68, $$64, $$67, $$62, $$61])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            select (spatial-intersect($$64, $$n)) retain-untrue ($$62 <- MISSING)
                                             -- STREAM_SELECT  |PARTITIONED|
+                                              project ([$$65, $$66, $$61, $$n, $$62, $$67, $$68, $$64])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$68, $$64] <- [$$63.getField(0), $$63.getField("sender-location")]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  project ([$$65, $$66, $$61, $$n, $$62, $$63, $$67])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    assign [$$63, $$67] <- [$$t2.getField(0), $$t2.getField("tweetid")]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      project ([$$65, $$66, $$61, $$n, $$62, $$t2])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                          left-outer-unnest-map [$$62, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$86, 1, $$86, true, true, true)
+                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              order (ASC, $$86)
                                                               -- STABLE_SORT [$$86(ASC)]  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  project ([$$65, $$66, $$61, $$n, $$86])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- RTREE_SEARCH (test.TweetMessages.twmSndLocIx)  |PARTITIONED|
+                                                                      left-outer-unnest-map [$$82, $$83, $$84, $$85, $$86] <- index-search("twmSndLocIx", 1, "test", "TweetMessages", true, true, 4, $$78, $$79, $$80, $$81)
+                                                                      -- RTREE_SEARCH  |PARTITIONED|
+                                                                        exchange
                                                                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                          assign [$$78, $$79, $$80, $$81] <- [create-mbr($$n, 2, 0), create-mbr($$n, 2, 1), create-mbr($$n, 2, 2), create-mbr($$n, 2, 3)]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            assign [$$n] <- [create-circle($$66, 0.5)]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              project ([$$61, $$66, $$65])
                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                assign [$$66, $$65] <- [$$60.getField("sender-location"), $$60.getField(0)]
                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                  project ([$$61, $$60])
                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                    assign [$$60] <- [$$t1.getField(0)]
                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                                        unnest-map [$$61, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$75, true, false, false)
+                                                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                            assign [$$75] <- [10]
                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                              empty-tuple-source
                                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02_ps.plan
index 7e70955..2d014c2 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested-open-index/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02_ps.plan
@@ -1,92 +1,178 @@
+distribute result [$$64]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$64])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$64] <- [{"tweetid1": $$74, "loc1": $$75, "nearby-message": $$63}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$63, $$74, $$75])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            order (ASC, $$83)
             -- STABLE_SORT [$$83(ASC)]  |PARTITIONED|
+              exchange
               -- RANGE_PARTITION_EXCHANGE [$$83(ASC)]  |PARTITIONED|
+                forward: shared-variable = $$98
                 -- FORWARD  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- PRE_CLUSTERED_GROUP_BY[$$68]  |PARTITIONED|
-                                {
+                        group by ([$$83 := $$68]) decor ([$$74; $$75]) {
+                                  aggregate [$$63] <- [listify({"tweetid2": $$73, "loc2": $$71})]
                                   -- AGGREGATE  |LOCAL|
+                                    select (not(is-missing($$69)))
                                     -- STREAM_SELECT  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                }
+                               }
+                        -- PRE_CLUSTERED_GROUP_BY[$$68]  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$68) (ASC, $$69)
                             -- STABLE_SORT [$$68(ASC), $$69(ASC)]  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$68]  |PARTITIONED|
+                                project ([$$74, $$75, $$73, $$71, $$69, $$68])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  select (and(spatial-intersect($$71, $$n), neq($$68, $$73))) retain-untrue ($$69 <- MISSING)
                                   -- STREAM_SELECT  |PARTITIONED|
+                                    project ([$$74, $$75, $$68, $$n, $$69, $$73, $$71])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$73, $$71] <- [$$70.getField(0), $$70.getField("sender-location")]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$74, $$75, $$68, $$n, $$69, $$70])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$70] <- [$$t2.getField(0)]
                                           -- ASSIGN  |PARTITIONED|
+                                            project ([$$74, $$75, $$68, $$n, $$69, $$t2])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                left-outer-unnest-map [$$69, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$95, 1, $$95, true, true, true)
+                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    order (ASC, $$95)
                                                     -- STABLE_SORT [$$95(ASC)]  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        project ([$$74, $$75, $$68, $$n, $$95])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- RTREE_SEARCH (test.TweetMessages.twmSndLocIx)  |PARTITIONED|
+                                                            left-outer-unnest-map [$$91, $$92, $$93, $$94, $$95] <- index-search("twmSndLocIx", 1, "test", "TweetMessages", true, true, 4, $$87, $$88, $$89, $$90)
+                                                            -- RTREE_SEARCH  |PARTITIONED|
+                                                              exchange
                                                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                assign [$$87, $$88, $$89, $$90] <- [create-mbr($$n, 2, 0), create-mbr($$n, 2, 1), create-mbr($$n, 2, 2), create-mbr($$n, 2, 3)]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  assign [$$n] <- [create-circle($$75, 0.5)]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    project ([$$68, $$75, $$74])
                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                      assign [$$75, $$74] <- [$$67.getField("sender-location"), $$67.getField(0)]
                                                                       -- ASSIGN  |PARTITIONED|
+                                                                        project ([$$68, $$67])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          assign [$$67] <- [$$t1.getField(0)]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                              -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                              unnest-map [$$68, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$84, true, false, false)
+                                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  assign [$$84] <- [10]
                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                    empty-tuple-source
                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    aggregate [$$98] <- [agg-range-map($$96, $$97)]
                     -- AGGREGATE  |UNPARTITIONED|
+                      exchange
                       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                        aggregate [$$96, $$97] <- [agg-local-sampling($$83), agg-null-writer($$83)]
                         -- AGGREGATE  |PARTITIONED|
+                          project ([$$83])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              replicate
                               -- REPLICATE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- PRE_CLUSTERED_GROUP_BY[$$68]  |PARTITIONED|
-                                          {
+                                  group by ([$$83 := $$68]) decor ([$$74; $$75]) {
+                                            aggregate [$$63] <- [listify({"tweetid2": $$73, "loc2": $$71})]
                                             -- AGGREGATE  |LOCAL|
+                                              select (not(is-missing($$69)))
                                               -- STREAM_SELECT  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                         }
+                                  -- PRE_CLUSTERED_GROUP_BY[$$68]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$68) (ASC, $$69)
                                       -- STABLE_SORT [$$68(ASC), $$69(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$68]  |PARTITIONED|
+                                          project ([$$74, $$75, $$73, $$71, $$69, $$68])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            select (and(spatial-intersect($$71, $$n), neq($$68, $$73))) retain-untrue ($$69 <- MISSING)
                                             -- STREAM_SELECT  |PARTITIONED|
+                                              project ([$$74, $$75, $$68, $$n, $$69, $$73, $$71])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$73, $$71] <- [$$70.getField(0), $$70.getField("sender-location")]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  project ([$$74, $$75, $$68, $$n, $$69, $$70])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    assign [$$70] <- [$$t2.getField(0)]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      project ([$$74, $$75, $$68, $$n, $$69, $$t2])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                          left-outer-unnest-map [$$69, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$95, 1, $$95, true, true, true)
+                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              order (ASC, $$95)
                                                               -- STABLE_SORT [$$95(ASC)]  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  project ([$$74, $$75, $$68, $$n, $$95])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- RTREE_SEARCH (test.TweetMessages.twmSndLocIx)  |PARTITIONED|
+                                                                      left-outer-unnest-map [$$91, $$92, $$93, $$94, $$95] <- index-search("twmSndLocIx", 1, "test", "TweetMessages", true, true, 4, $$87, $$88, $$89, $$90)
+                                                                      -- RTREE_SEARCH  |PARTITIONED|
+                                                                        exchange
                                                                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                          assign [$$87, $$88, $$89, $$90] <- [create-mbr($$n, 2, 0), create-mbr($$n, 2, 1), create-mbr($$n, 2, 2), create-mbr($$n, 2, 3)]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            assign [$$n] <- [create-circle($$75, 0.5)]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              project ([$$68, $$75, $$74])
                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                assign [$$75, $$74] <- [$$67.getField("sender-location"), $$67.getField(0)]
                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                  project ([$$68, $$67])
                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                    assign [$$67] <- [$$t1.getField(0)]
                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                                        unnest-map [$$68, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$84, true, false, false)
+                                                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                            assign [$$84] <- [10]
                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                              empty-tuple-source
                                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested_loj2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested_loj2.plan
index 0cee768..ad260fd 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested_loj2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/nested_loj2.plan
@@ -1,43 +1,80 @@
+distribute result [$$65]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$65])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$65] <- [{"cust": $$c, "orders": $$63}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$63, $$c])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- PRE_CLUSTERED_GROUP_BY[$$66]  |PARTITIONED|
-                    {
+            group by ([$$77 := $$66]) decor ([$$c]) {
+                      aggregate [$$63] <- [listify({"order": $$o, "items": $$57})]
                       -- AGGREGATE  |LOCAL|
-                        -- MICRO_PRE_CLUSTERED_GROUP_BY[$$67]  |LOCAL|
-                                {
+                        group by ([$$75 := $$67]) decor ([$$66; $$70; $$c; $$o]) {
+                                  aggregate [$$57] <- [listify($$l)]
                                   -- AGGREGATE  |LOCAL|
+                                    select (not(is-missing($$74)))
                                     -- STREAM_SELECT  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                }
+                               }
+                        -- MICRO_PRE_CLUSTERED_GROUP_BY[$$67]  |LOCAL|
+                          select (not(is-missing($$76)))
                           -- STREAM_SELECT  |LOCAL|
+                            nested tuple source
                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                    }
+                   }
+            -- PRE_CLUSTERED_GROUP_BY[$$66]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (ASC, $$66) (ASC, $$67)
                 -- STABLE_SORT [$$66(ASC), $$67(ASC)]  |PARTITIONED|
+                  exchange
                   -- HASH_PARTITION_EXCHANGE [$$66]  |PARTITIONED|
+                    project ([$$c, $$o, $$l, $$74, $$67, $$66, $$70, $$76])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        left outer join (eq($$68, $$67))
                         -- HYBRID_HASH_JOIN [$$67][$$68]  |PARTITIONED|
+                          exchange
                           -- HASH_PARTITION_EXCHANGE [$$67]  |PARTITIONED|
+                            left outer join (eq($$70, $$66))
                             -- HYBRID_HASH_JOIN [$$66][$$70]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (tpch.Customers)  |PARTITIONED|
+                                data-scan []<-[$$66, $$c] <- tpch.Customers
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$70]  |PARTITIONED|
+                                assign [$$76, $$70] <- [true, $$o.getField(1)]
                                 -- ASSIGN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                                    data-scan []<-[$$67, $$o] <- tpch.Orders
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- HASH_PARTITION_EXCHANGE [$$68]  |PARTITIONED|
+                            assign [$$74] <- [true]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$68, $$l])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (tpch.LineItems)  |PARTITIONED|
+                                  data-scan []<-[$$68, $$69, $$l] <- tpch.LineItems
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_1_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_1_ps.plan
index 899f737..cace889 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_1_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_1_ps.plan
@@ -1,77 +1,148 @@
+distribute result [$$39]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$39])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$39] <- [{"tweetid1": $$51, "count1": $$45, "t2info": $$38}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$51)
           -- STABLE_SORT [$$51(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$51(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$59
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- PRE_CLUSTERED_GROUP_BY[$$42]  |PARTITIONED|
-                              {
+                      group by ([$$51 := $$42]) decor ([$$45]) {
+                                aggregate [$$38] <- [listify({"tweetid2": $$43, "count2": $$44})]
                                 -- AGGREGATE  |LOCAL|
+                                  select (not(is-missing($$43)))
                                   -- STREAM_SELECT  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- PRE_CLUSTERED_GROUP_BY[$$42]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$42) (ASC, $$43)
                           -- STABLE_SORT [$$42(ASC), $$43(ASC)]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$42]  |PARTITIONED|
+                              select (eq($$45, $$44)) retain-untrue ($$43 <- MISSING)
                               -- STREAM_SELECT  |PARTITIONED|
+                                project ([$$45, $$42, $$43, $$44])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  assign [$$44] <- [$$t2.getField("countB")]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$45, $$42, $$43, $$t2])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                        left-outer-unnest-map [$$43, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$56, 1, $$56, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            order (ASC, $$56)
                                             -- STABLE_SORT [$$56(ASC)]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$45, $$42, $$56])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                                    left-outer-unnest-map [$$55, $$56] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$45, 1, $$45, true, true, true)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                        project ([$$42, $$45])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$45] <- [$$t1.getField(6)]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                              unnest-map [$$42, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$52, true, false, false)
+                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  assign [$$52] <- [10]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    empty-tuple-source
                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$59] <- [agg-range-map($$57, $$58)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$57, $$58] <- [agg-local-sampling($$51), agg-null-writer($$51)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$51])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- PRE_CLUSTERED_GROUP_BY[$$42]  |PARTITIONED|
-                                        {
+                                group by ([$$51 := $$42]) decor ([$$45]) {
+                                          aggregate [$$38] <- [listify({"tweetid2": $$43, "count2": $$44})]
                                           -- AGGREGATE  |LOCAL|
+                                            select (not(is-missing($$43)))
                                             -- STREAM_SELECT  |LOCAL|
+                                              nested tuple source
                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- PRE_CLUSTERED_GROUP_BY[$$42]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$42) (ASC, $$43)
                                     -- STABLE_SORT [$$42(ASC), $$43(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$42]  |PARTITIONED|
+                                        select (eq($$45, $$44)) retain-untrue ($$43 <- MISSING)
                                         -- STREAM_SELECT  |PARTITIONED|
+                                          project ([$$45, $$42, $$43, $$44])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$44] <- [$$t2.getField("countB")]
                                             -- ASSIGN  |PARTITIONED|
+                                              project ([$$45, $$42, $$43, $$t2])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                  left-outer-unnest-map [$$43, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$56, 1, $$56, true, true, true)
+                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      order (ASC, $$56)
                                                       -- STABLE_SORT [$$56(ASC)]  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          project ([$$45, $$42, $$56])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                                              left-outer-unnest-map [$$55, $$56] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$45, 1, $$45, true, true, true)
+                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                exchange
                                                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                  project ([$$42, $$45])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    assign [$$45] <- [$$t1.getField(6)]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                        unnest-map [$$42, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$52, true, false, false)
+                                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            assign [$$52] <- [10]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              empty-tuple-source
                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_2_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_2_ps.plan
index 899f737..acdd17d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_2_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_01_2_ps.plan
@@ -1,77 +1,148 @@
+distribute result [$$39]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$39])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$39] <- [{"tweetid1": $$51, "count1": $$45, "t2info": $$38}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$51)
           -- STABLE_SORT [$$51(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$51(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$59
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- PRE_CLUSTERED_GROUP_BY[$$42]  |PARTITIONED|
-                              {
+                      group by ([$$51 := $$42]) decor ([$$45]) {
+                                aggregate [$$38] <- [listify({"tweetid2": $$43, "count2": $$44})]
                                 -- AGGREGATE  |LOCAL|
+                                  select (not(is-missing($$43)))
                                   -- STREAM_SELECT  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- PRE_CLUSTERED_GROUP_BY[$$42]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$42) (ASC, $$43)
                           -- STABLE_SORT [$$42(ASC), $$43(ASC)]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$42]  |PARTITIONED|
+                              select (eq($$45, $$44)) retain-untrue ($$43 <- MISSING)
                               -- STREAM_SELECT  |PARTITIONED|
+                                project ([$$45, $$42, $$43, $$44])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  assign [$$44] <- [$$t2.getField("countB")]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$45, $$42, $$43, $$t2])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                        left-outer-unnest-map [$$43, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$56, 1, $$56, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            order (ASC, $$56)
                                             -- STABLE_SORT [$$56(ASC)]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$45, $$42, $$56])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                                    left-outer-unnest-map [$$55, $$56] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$45, 1, $$45, true, true, true)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                        project ([$$42, $$45])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$45] <- [$$t1.getField("countA")]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                              unnest-map [$$42, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$52, true, false, false)
+                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  assign [$$52] <- [10]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    empty-tuple-source
                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$59] <- [agg-range-map($$57, $$58)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$57, $$58] <- [agg-local-sampling($$51), agg-null-writer($$51)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$51])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- PRE_CLUSTERED_GROUP_BY[$$42]  |PARTITIONED|
-                                        {
+                                group by ([$$51 := $$42]) decor ([$$45]) {
+                                          aggregate [$$38] <- [listify({"tweetid2": $$43, "count2": $$44})]
                                           -- AGGREGATE  |LOCAL|
+                                            select (not(is-missing($$43)))
                                             -- STREAM_SELECT  |LOCAL|
+                                              nested tuple source
                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- PRE_CLUSTERED_GROUP_BY[$$42]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$42) (ASC, $$43)
                                     -- STABLE_SORT [$$42(ASC), $$43(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$42]  |PARTITIONED|
+                                        select (eq($$45, $$44)) retain-untrue ($$43 <- MISSING)
                                         -- STREAM_SELECT  |PARTITIONED|
+                                          project ([$$45, $$42, $$43, $$44])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$44] <- [$$t2.getField("countB")]
                                             -- ASSIGN  |PARTITIONED|
+                                              project ([$$45, $$42, $$43, $$t2])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                  left-outer-unnest-map [$$43, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$56, 1, $$56, true, true, true)
+                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      order (ASC, $$56)
                                                       -- STABLE_SORT [$$56(ASC)]  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          project ([$$45, $$42, $$56])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                                              left-outer-unnest-map [$$55, $$56] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$45, 1, $$45, true, true, true)
+                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                exchange
                                                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                  project ([$$42, $$45])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    assign [$$45] <- [$$t1.getField("countA")]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                        unnest-map [$$42, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$52, true, false, false)
+                                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            assign [$$52] <- [10]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              empty-tuple-source
                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_1_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_1_ps.plan
index ef866c9..021de6e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_1_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_1_ps.plan
@@ -1,77 +1,148 @@
+distribute result [$$43]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$43])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$43] <- [{"tweetid1": $$56, "count1": $$50, "t2info": $$42}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$56)
           -- STABLE_SORT [$$56(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$56(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$64
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- PRE_CLUSTERED_GROUP_BY[$$46]  |PARTITIONED|
-                              {
+                      group by ([$$56 := $$46]) decor ([$$50]) {
+                                aggregate [$$42] <- [listify({"tweetid2": $$47, "count2": $$49})]
                                 -- AGGREGATE  |LOCAL|
+                                  select (not(is-missing($$47)))
                                   -- STREAM_SELECT  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- PRE_CLUSTERED_GROUP_BY[$$46]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$46) (ASC, $$47)
                           -- STABLE_SORT [$$46(ASC), $$47(ASC)]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$46]  |PARTITIONED|
+                              select (and(eq($$50, $$49), neq($$46, $$47))) retain-untrue ($$47 <- MISSING)
                               -- STREAM_SELECT  |PARTITIONED|
+                                project ([$$50, $$46, $$47, $$49])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  assign [$$49] <- [$$t2.getField("countB")]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$50, $$46, $$47, $$t2])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                        left-outer-unnest-map [$$47, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$61, 1, $$61, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            order (ASC, $$61)
                                             -- STABLE_SORT [$$61(ASC)]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$50, $$46, $$61])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                                    left-outer-unnest-map [$$60, $$61] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$50, 1, $$50, true, true, true)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                        project ([$$46, $$50])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$50] <- [$$t1.getField(6)]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                              unnest-map [$$46, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$57, true, false, false)
+                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  assign [$$57] <- [10]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    empty-tuple-source
                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$64] <- [agg-range-map($$62, $$63)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$62, $$63] <- [agg-local-sampling($$56), agg-null-writer($$56)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$56])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- PRE_CLUSTERED_GROUP_BY[$$46]  |PARTITIONED|
-                                        {
+                                group by ([$$56 := $$46]) decor ([$$50]) {
+                                          aggregate [$$42] <- [listify({"tweetid2": $$47, "count2": $$49})]
                                           -- AGGREGATE  |LOCAL|
+                                            select (not(is-missing($$47)))
                                             -- STREAM_SELECT  |LOCAL|
+                                              nested tuple source
                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- PRE_CLUSTERED_GROUP_BY[$$46]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$46) (ASC, $$47)
                                     -- STABLE_SORT [$$46(ASC), $$47(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$46]  |PARTITIONED|
+                                        select (and(eq($$50, $$49), neq($$46, $$47))) retain-untrue ($$47 <- MISSING)
                                         -- STREAM_SELECT  |PARTITIONED|
+                                          project ([$$50, $$46, $$47, $$49])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$49] <- [$$t2.getField("countB")]
                                             -- ASSIGN  |PARTITIONED|
+                                              project ([$$50, $$46, $$47, $$t2])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                  left-outer-unnest-map [$$47, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$61, 1, $$61, true, true, true)
+                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      order (ASC, $$61)
                                                       -- STABLE_SORT [$$61(ASC)]  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          project ([$$50, $$46, $$61])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                                              left-outer-unnest-map [$$60, $$61] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$50, 1, $$50, true, true, true)
+                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                exchange
                                                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                  project ([$$46, $$50])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    assign [$$50] <- [$$t1.getField(6)]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                        unnest-map [$$46, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$57, true, false, false)
+                                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            assign [$$57] <- [10]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              empty-tuple-source
                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_2_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_2_ps.plan
index ef866c9..f08f422 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_2_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/btree-index-join/leftouterjoin-probe-pidx-with-join-btree-sidx_02_2_ps.plan
@@ -1,77 +1,148 @@
+distribute result [$$43]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$43])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$43] <- [{"tweetid1": $$56, "count1": $$50, "t2info": $$42}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$56)
           -- STABLE_SORT [$$56(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$56(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$64
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- PRE_CLUSTERED_GROUP_BY[$$46]  |PARTITIONED|
-                              {
+                      group by ([$$56 := $$46]) decor ([$$50]) {
+                                aggregate [$$42] <- [listify({"tweetid2": $$47, "count2": $$49})]
                                 -- AGGREGATE  |LOCAL|
+                                  select (not(is-missing($$47)))
                                   -- STREAM_SELECT  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- PRE_CLUSTERED_GROUP_BY[$$46]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$46) (ASC, $$47)
                           -- STABLE_SORT [$$46(ASC), $$47(ASC)]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$46]  |PARTITIONED|
+                              select (and(eq($$50, $$49), neq($$46, $$47))) retain-untrue ($$47 <- MISSING)
                               -- STREAM_SELECT  |PARTITIONED|
+                                project ([$$50, $$46, $$47, $$49])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  assign [$$49] <- [$$t2.getField("countB")]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$50, $$46, $$47, $$t2])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                        left-outer-unnest-map [$$47, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$61, 1, $$61, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            order (ASC, $$61)
                                             -- STABLE_SORT [$$61(ASC)]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$50, $$46, $$61])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                                    left-outer-unnest-map [$$60, $$61] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$50, 1, $$50, true, true, true)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                        project ([$$46, $$50])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$50] <- [$$t1.getField("countA")]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                              unnest-map [$$46, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$57, true, false, false)
+                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  assign [$$57] <- [10]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    empty-tuple-source
                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$64] <- [agg-range-map($$62, $$63)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$62, $$63] <- [agg-local-sampling($$56), agg-null-writer($$56)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$56])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- PRE_CLUSTERED_GROUP_BY[$$46]  |PARTITIONED|
-                                        {
+                                group by ([$$56 := $$46]) decor ([$$50]) {
+                                          aggregate [$$42] <- [listify({"tweetid2": $$47, "count2": $$49})]
                                           -- AGGREGATE  |LOCAL|
+                                            select (not(is-missing($$47)))
                                             -- STREAM_SELECT  |LOCAL|
+                                              nested tuple source
                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- PRE_CLUSTERED_GROUP_BY[$$46]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$46) (ASC, $$47)
                                     -- STABLE_SORT [$$46(ASC), $$47(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$46]  |PARTITIONED|
+                                        select (and(eq($$50, $$49), neq($$46, $$47))) retain-untrue ($$47 <- MISSING)
                                         -- STREAM_SELECT  |PARTITIONED|
+                                          project ([$$50, $$46, $$47, $$49])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$49] <- [$$t2.getField("countB")]
                                             -- ASSIGN  |PARTITIONED|
+                                              project ([$$50, $$46, $$47, $$t2])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                  left-outer-unnest-map [$$47, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$61, 1, $$61, true, true, true)
+                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      order (ASC, $$61)
                                                       -- STABLE_SORT [$$61(ASC)]  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          project ([$$50, $$46, $$61])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- BTREE_SEARCH (test.TweetMessages.msgCountBIx)  |PARTITIONED|
+                                                              left-outer-unnest-map [$$60, $$61] <- index-search("msgCountBIx", 0, "test", "TweetMessages", true, true, 1, $$50, 1, $$50, true, true, true)
+                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                exchange
                                                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                  project ([$$46, $$50])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    assign [$$50] <- [$$t1.getField("countA")]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                        unnest-map [$$46, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$57, true, false, false)
+                                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            assign [$$57] <- [10]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              empty-tuple-source
                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-basic/ngram-contains-panic_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-basic/ngram-contains-panic_ps.plan
index 93ca5bd..d10bcbe 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-basic/ngram-contains-panic_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-basic/ngram-contains-panic_ps.plan
@@ -1,28 +1,56 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$o])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$15)
         -- STABLE_SORT [$$15(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$15(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$20
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (contains($$o.getField("title"), "Mu"))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                        data-scan []<-[$$15, $$o] <- test.DBLP
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$20] <- [agg-range-map($$18, $$19)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$18, $$19] <- [agg-local-sampling($$15), agg-null-writer($$15)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$15])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (contains($$o.getField("title"), "Mu"))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                  data-scan []<-[$$15, $$o] <- test.DBLP
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-basic/ngram-contains_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-basic/ngram-contains_ps.plan
index ed6a9c5..c1dc2a9 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-basic/ngram-contains_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-basic/ngram-contains_ps.plan
@@ -1,38 +1,76 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$o])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$15)
         -- STABLE_SORT [$$15(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$15(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$22
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (contains($$o.getField("title"), "Multimedia"))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                        unnest-map [$$15, $$o] <- index-search("DBLP", 0, "test", "DBLP", false, false, 1, $$19, 1, $$19, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$19)
                             -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                                unnest-map [$$19] <- index-search("ngram_index", 5, "test", "DBLP", false, false, 0, missing, 12, false, 1, $$18)
+                                -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    assign [$$18] <- ["Multimedia"]
                                     -- ASSIGN  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$22] <- [agg-range-map($$20, $$21)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$20, $$21] <- [agg-local-sampling($$15), agg-null-writer($$15)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$15])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (contains($$o.getField("title"), "Multimedia"))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                                  unnest-map [$$15, $$o] <- index-search("DBLP", 0, "test", "DBLP", false, false, 1, $$19, 1, $$19, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$19)
                                       -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                                          unnest-map [$$19] <- index-search("ngram_index", 5, "test", "DBLP", false, false, 0, missing, 12, false, 1, $$18)
+                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$18] <- ["Multimedia"]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-basic/word-contains_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-basic/word-contains_ps.plan
index 93ca5bd..f138fa5 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-basic/word-contains_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-basic/word-contains_ps.plan
@@ -1,28 +1,56 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$o])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$15)
         -- STABLE_SORT [$$15(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$15(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$20
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (contains($$o.getField("title"), "Multimedia"))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                        data-scan []<-[$$15, $$o] <- test.DBLP
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$20] <- [agg-range-map($$18, $$19)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$18, $$19] <- [agg-local-sampling($$15), agg-null-writer($$15)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$15])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (contains($$o.getField("title"), "Multimedia"))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                  data-scan []<-[$$15, $$o] <- test.DBLP
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01_ps.plan
index acca388..16b0bbb 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-join/leftouterjoin-probe-pidx-with-join-edit-distance-check-idx_01_ps.plan
@@ -1,165 +1,324 @@
+distribute result [$$56]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$56])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$56] <- [{"tweet": {"id": $$69, "topics": $$64}, "similar-tweets": $$55}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$69)
           -- STABLE_SORT [$$69(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$69(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$86
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- PRE_CLUSTERED_GROUP_BY[$$59]  |PARTITIONED|
-                              {
+                      group by ([$$69 := $$59]) decor ([$$64]) {
+                                aggregate [$$55] <- [listify({"id": $$60, "topics": $$62})]
                                 -- AGGREGATE  |LOCAL|
+                                  select (not(is-missing($$60)))
                                   -- STREAM_SELECT  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- PRE_CLUSTERED_GROUP_BY[$$59]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$59) (ASC, $$60)
                           -- STABLE_SORT [$$59(ASC), $$60(ASC)]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$59]  |PARTITIONED|
+                              project ([$$64, $$60, $$62, $$59])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  join (eq($$75, $$59))
                                   -- HYBRID_HASH_JOIN [$$75][$$59]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$75])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$75, $$t1] <- [$$59, $$76]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                unnest-map [$$59, $$76] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$77, 0, false, true, false)
+                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    assign [$$77] <- [240]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$59]  |PARTITIONED|
+                                      union ($$60, $$82, $$60) ($$62, $$80, $$62) ($$59, $$59, $$59) ($$64, $$64, $$64)
                                       -- UNION_ALL  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$60, $$62, $$59, $$64])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            select (and(neq($$60, $$59), get-item(edit-distance-check($$64, $$62, 7), 0))) retain-untrue ($$60 <- MISSING)
                                             -- STREAM_SELECT  |PARTITIONED|
+                                              project ([$$59, $$64, $$60, $$62])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$62] <- [$$t2.getField("message-text")]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  project ([$$59, $$64, $$60, $$t2])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                      left-outer-unnest-map [$$60, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$83, 1, $$83, true, true, true)
+                                                      -- BTREE_SEARCH  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          order (ASC, $$83)
                                                           -- STABLE_SORT [$$83(ASC)]  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.TweetMessages.msgNgramIx)  |PARTITIONED|
+                                                              left-outer-unnest-map [$$83] <- index-search("msgNgramIx", 5, "test", "TweetMessages", true, true, 2, 7, 12, false, 1, $$64)
+                                                              -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                                                exchange
                                                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                  select (edit-distance-string-is-filterable($$64, 7, 3, true))
                                                                   -- STREAM_SELECT  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      replicate
                                                                       -- REPLICATE  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          project ([$$59, $$64])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            assign [$$64] <- [$$76.getField("message-text")]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                replicate
                                                                                 -- REPLICATE  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                    -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                                    unnest-map [$$59, $$76] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$77, 0, false, true, false)
+                                                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                        assign [$$77] <- [240]
                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                          empty-tuple-source
                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          left outer join (and(neq($$82, $$59), get-item(edit-distance-check($$64, $$80, 7), 0)))
                                           -- NESTED_LOOP  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$82, $$80])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$80] <- [$$81.getField("message-text")]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (test.TweetMessages)  |PARTITIONED|
+                                                    data-scan []<-[$$82, $$81] <- test.TweetMessages
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                            exchange
                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                              select (not(edit-distance-string-is-filterable($$64, 7, 3, true)))
                                               -- STREAM_SELECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  replicate
                                                   -- REPLICATE  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      project ([$$59, $$64])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$64] <- [$$76.getField("message-text")]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            replicate
                                                             -- REPLICATE  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                unnest-map [$$59, $$76] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$77, 0, false, true, false)
+                                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    assign [$$77] <- [240]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      empty-tuple-source
                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$86] <- [agg-range-map($$84, $$85)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$84, $$85] <- [agg-local-sampling($$69), agg-null-writer($$69)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$69])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- PRE_CLUSTERED_GROUP_BY[$$59]  |PARTITIONED|
-                                        {
+                                group by ([$$69 := $$59]) decor ([$$64]) {
+                                          aggregate [$$55] <- [listify({"id": $$60, "topics": $$62})]
                                           -- AGGREGATE  |LOCAL|
+                                            select (not(is-missing($$60)))
                                             -- STREAM_SELECT  |LOCAL|
+                                              nested tuple source
                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- PRE_CLUSTERED_GROUP_BY[$$59]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$59) (ASC, $$60)
                                     -- STABLE_SORT [$$59(ASC), $$60(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$59]  |PARTITIONED|
+                                        project ([$$64, $$60, $$62, $$59])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            join (eq($$75, $$59))
                                             -- HYBRID_HASH_JOIN [$$75][$$59]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$75])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$75, $$t1] <- [$$59, $$76]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      replicate
                                                       -- REPLICATE  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                          unnest-map [$$59, $$76] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$77, 0, false, true, false)
+                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              assign [$$77] <- [240]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                empty-tuple-source
                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                              exchange
                                               -- HASH_PARTITION_EXCHANGE [$$59]  |PARTITIONED|
+                                                union ($$60, $$82, $$60) ($$62, $$80, $$62) ($$59, $$59, $$59) ($$64, $$64, $$64)
                                                 -- UNION_ALL  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$$60, $$62, $$59, $$64])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      select (and(neq($$60, $$59), get-item(edit-distance-check($$64, $$62, 7), 0))) retain-untrue ($$60 <- MISSING)
                                                       -- STREAM_SELECT  |PARTITIONED|
+                                                        project ([$$59, $$64, $$60, $$62])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$62] <- [$$t2.getField("message-text")]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            project ([$$59, $$64, $$60, $$t2])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                left-outer-unnest-map [$$60, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$83, 1, $$83, true, true, true)
+                                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    order (ASC, $$83)
                                                                     -- STABLE_SORT [$$83(ASC)]  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                        -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.TweetMessages.msgNgramIx)  |PARTITIONED|
+                                                                        left-outer-unnest-map [$$83] <- index-search("msgNgramIx", 5, "test", "TweetMessages", true, true, 2, 7, 12, false, 1, $$64)
+                                                                        -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                                                          exchange
                                                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                            select (edit-distance-string-is-filterable($$64, 7, 3, true))
                                                                             -- STREAM_SELECT  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                replicate
                                                                                 -- REPLICATE  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    project ([$$59, $$64])
                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                      assign [$$64] <- [$$76.getField("message-text")]
                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                        exchange
                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                          replicate
                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                            exchange
                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                              -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                                              unnest-map [$$59, $$76] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$77, 0, false, true, false)
+                                                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                                                exchange
                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                  assign [$$77] <- [240]
                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                    empty-tuple-source
                                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    left outer join (and(neq($$82, $$59), get-item(edit-distance-check($$64, $$80, 7), 0)))
                                                     -- NESTED_LOOP  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        project ([$$82, $$80])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$80] <- [$$81.getField("message-text")]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- DATASOURCE_SCAN (test.TweetMessages)  |PARTITIONED|
+                                                              data-scan []<-[$$82, $$81] <- test.TweetMessages
+                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  empty-tuple-source
                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                      exchange
                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                        select (not(edit-distance-string-is-filterable($$64, 7, 3, true)))
                                                         -- STREAM_SELECT  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            replicate
                                                             -- REPLICATE  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                project ([$$59, $$64])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  assign [$$64] <- [$$76.getField("message-text")]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      replicate
                                                                       -- REPLICATE  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                          -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                          unnest-map [$$59, $$76] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 1, $$77, 0, false, true, false)
+                                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              assign [$$77] <- [240]
                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                empty-tuple-source
                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-join/ngram-contains_01_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-join/ngram-contains_01_ps.plan
index fa450a0..00fd7c9 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-join/ngram-contains_01_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-join/ngram-contains_01_ps.plan
@@ -1,50 +1,100 @@
+distribute result [$$33]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$33])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$33] <- [{"title1": $$36, "title2": $$37}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$36, $$37])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            order (ASC, $$38) (ASC, $$39)
             -- STABLE_SORT [$$38(ASC), $$39(ASC)]  |PARTITIONED|
+              exchange
               -- RANGE_PARTITION_EXCHANGE [$$38(ASC), $$39(ASC)]  |PARTITIONED|
+                forward: shared-variable = $$47
                 -- FORWARD  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        join (and(contains($$36, $$37), lt($$38, $$39)))
                         -- NESTED_LOOP  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$36, $$38])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$36] <- [$$o1.getField("title")]
                               -- ASSIGN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                  data-scan []<-[$$38, $$o1] <- test.DBLP
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                            project ([$$37, $$39])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$37] <- [$$o2.getField(2)]
                               -- ASSIGN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.CSX)  |PARTITIONED|
+                                  data-scan []<-[$$39, $$o2] <- test.CSX
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    aggregate [$$47] <- [agg-range-map($$44, $$45, $$46)]
                     -- AGGREGATE  |UNPARTITIONED|
+                      exchange
                       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                        aggregate [$$44, $$45, $$46] <- [agg-local-sampling($$38, $$39), agg-null-writer($$38), agg-null-writer($$39)]
                         -- AGGREGATE  |PARTITIONED|
+                          project ([$$38, $$39])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              replicate
                               -- REPLICATE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  join (and(contains($$36, $$37), lt($$38, $$39)))
                                   -- NESTED_LOOP  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$36, $$38])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$36] <- [$$o1.getField("title")]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                            data-scan []<-[$$38, $$o1] <- test.DBLP
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                      project ([$$37, $$39])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$37] <- [$$o2.getField(2)]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (test.CSX)  |PARTITIONED|
+                                            data-scan []<-[$$39, $$o2] <- test.CSX
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-join/ngram-contains_02_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-join/ngram-contains_02_ps.plan
index ef37179..709a1a4 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-join/ngram-contains_02_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-join/ngram-contains_02_ps.plan
@@ -1,54 +1,108 @@
+distribute result [$$33]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$33])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$33] <- [{"title1": $$36, "title2": $$37}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$36, $$37])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            order (ASC, $$38) (ASC, $$39)
             -- STABLE_SORT [$$38(ASC), $$39(ASC)]  |PARTITIONED|
+              exchange
               -- RANGE_PARTITION_EXCHANGE [$$38(ASC), $$39(ASC)]  |PARTITIONED|
+                forward: shared-variable = $$52
                 -- FORWARD  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        select (and(contains($$36, $$37), lt($$38, $$39)))
                         -- STREAM_SELECT  |PARTITIONED|
+                          project ([$$38, $$36, $$39, $$37])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$37] <- [$$o2.getField("title")]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$38, $$36, $$39, $$o2])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.CSX.CSX)  |PARTITIONED|
+                                  unnest-map [$$39, $$o2] <- index-search("CSX", 0, "test", "CSX", true, false, 1, $$48, 1, $$48, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$48)
                                       -- STABLE_SORT [$$48(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.CSX.ngram_index)  |PARTITIONED|
+                                          unnest-map [$$48] <- index-search("ngram_index", 5, "test", "CSX", true, true, 0, missing, 12, false, 1, $$36)
+                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                              project ([$$38, $$36])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$36] <- [$$47.getField(2)]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                                    data-scan []<-[$$38, $$47] <- test.DBLP
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    aggregate [$$52] <- [agg-range-map($$49, $$50, $$51)]
                     -- AGGREGATE  |UNPARTITIONED|
+                      exchange
                       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                        aggregate [$$49, $$50, $$51] <- [agg-local-sampling($$38, $$39), agg-null-writer($$38), agg-null-writer($$39)]
                         -- AGGREGATE  |PARTITIONED|
+                          project ([$$38, $$39])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              replicate
                               -- REPLICATE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  select (and(contains($$36, $$37), lt($$38, $$39)))
                                   -- STREAM_SELECT  |PARTITIONED|
+                                    project ([$$38, $$36, $$39, $$37])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$37] <- [$$o2.getField("title")]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$38, $$36, $$39, $$o2])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (test.CSX.CSX)  |PARTITIONED|
+                                            unnest-map [$$39, $$o2] <- index-search("CSX", 0, "test", "CSX", true, false, 1, $$48, 1, $$48, true, true, true)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                order (ASC, $$48)
                                                 -- STABLE_SORT [$$48(ASC)]  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.CSX.ngram_index)  |PARTITIONED|
+                                                    unnest-map [$$48] <- index-search("ngram_index", 5, "test", "CSX", true, true, 0, missing, 12, false, 1, $$36)
+                                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                        project ([$$38, $$36])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$36] <- [$$47.getField(2)]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                                              data-scan []<-[$$38, $$47] <- test.DBLP
+                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  empty-tuple-source
                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-join/ngram-contains_03_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-join/ngram-contains_03_ps.plan
index b7351a2..ba9b3ac 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-join/ngram-contains_03_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-join/ngram-contains_03_ps.plan
@@ -1,54 +1,108 @@
+distribute result [$$33]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$33])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$33] <- [{"title1": $$36, "title2": $$37}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$36, $$37])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            order (ASC, $$38) (ASC, $$39)
             -- STABLE_SORT [$$38(ASC), $$39(ASC)]  |PARTITIONED|
+              exchange
               -- RANGE_PARTITION_EXCHANGE [$$38(ASC), $$39(ASC)]  |PARTITIONED|
+                forward: shared-variable = $$52
                 -- FORWARD  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        select (and(contains($$36, $$37), lt($$38, $$39)))
                         -- STREAM_SELECT  |PARTITIONED|
+                          project ([$$38, $$36, $$39, $$37])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$37] <- [$$o2.getField("title")]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$38, $$36, $$39, $$o2])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                                  unnest-map [$$39, $$o2] <- index-search("DBLP", 0, "test", "DBLP", true, false, 1, $$48, 1, $$48, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$48)
                                       -- STABLE_SORT [$$48(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                                          unnest-map [$$48] <- index-search("ngram_index", 5, "test", "DBLP", true, true, 0, missing, 12, false, 1, $$36)
+                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                              project ([$$38, $$36])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$36] <- [$$47.getField("title")]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                                    data-scan []<-[$$38, $$47] <- test.DBLP
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    aggregate [$$52] <- [agg-range-map($$49, $$50, $$51)]
                     -- AGGREGATE  |UNPARTITIONED|
+                      exchange
                       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                        aggregate [$$49, $$50, $$51] <- [agg-local-sampling($$38, $$39), agg-null-writer($$38), agg-null-writer($$39)]
                         -- AGGREGATE  |PARTITIONED|
+                          project ([$$38, $$39])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              replicate
                               -- REPLICATE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  select (and(contains($$36, $$37), lt($$38, $$39)))
                                   -- STREAM_SELECT  |PARTITIONED|
+                                    project ([$$38, $$36, $$39, $$37])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$37] <- [$$o2.getField("title")]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$38, $$36, $$39, $$o2])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                                            unnest-map [$$39, $$o2] <- index-search("DBLP", 0, "test", "DBLP", true, false, 1, $$48, 1, $$48, true, true, true)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                order (ASC, $$48)
                                                 -- STABLE_SORT [$$48(ASC)]  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.DBLP.ngram_index)  |PARTITIONED|
+                                                    unnest-map [$$48] <- index-search("ngram_index", 5, "test", "DBLP", true, true, 0, missing, 12, false, 1, $$36)
+                                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                        project ([$$38, $$36])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$36] <- [$$47.getField("title")]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                                              data-scan []<-[$$38, $$47] <- test.DBLP
+                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  empty-tuple-source
                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-join/ngram-contains_04_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-join/ngram-contains_04_ps.plan
index 79aeeb4..d000e2f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-join/ngram-contains_04_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/inverted-index-join/ngram-contains_04_ps.plan
@@ -1,54 +1,108 @@
+distribute result [$$33]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$33])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$33] <- [{"title1": $$36, "title2": $$37}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$36, $$37])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            order (ASC, $$38) (ASC, $$39)
             -- STABLE_SORT [$$38(ASC), $$39(ASC)]  |PARTITIONED|
+              exchange
               -- RANGE_PARTITION_EXCHANGE [$$38(ASC), $$39(ASC)]  |PARTITIONED|
+                forward: shared-variable = $$52
                 -- FORWARD  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        select (and(contains($$36, $$37), lt($$38, $$39)))
                         -- STREAM_SELECT  |PARTITIONED|
+                          project ([$$38, $$36, $$39, $$37])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$37] <- [$$o2.getField("title")]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$38, $$36, $$39, $$o2])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.CSX.CSX)  |PARTITIONED|
+                                  unnest-map [$$39, $$o2] <- index-search("CSX", 0, "test", "CSX", true, false, 1, $$48, 1, $$48, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$48)
                                       -- STABLE_SORT [$$48(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.CSX.ngram_index_CSX)  |PARTITIONED|
+                                          unnest-map [$$48] <- index-search("ngram_index_CSX", 5, "test", "CSX", true, true, 0, missing, 12, false, 1, $$36)
+                                          -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                              project ([$$38, $$36])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$36] <- [$$47.getField("title")]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                                    data-scan []<-[$$38, $$47] <- test.DBLP
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    aggregate [$$52] <- [agg-range-map($$49, $$50, $$51)]
                     -- AGGREGATE  |UNPARTITIONED|
+                      exchange
                       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                        aggregate [$$49, $$50, $$51] <- [agg-local-sampling($$38, $$39), agg-null-writer($$38), agg-null-writer($$39)]
                         -- AGGREGATE  |PARTITIONED|
+                          project ([$$38, $$39])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              replicate
                               -- REPLICATE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  select (and(contains($$36, $$37), lt($$38, $$39)))
                                   -- STREAM_SELECT  |PARTITIONED|
+                                    project ([$$38, $$36, $$39, $$37])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$37] <- [$$o2.getField("title")]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$38, $$36, $$39, $$o2])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (test.CSX.CSX)  |PARTITIONED|
+                                            unnest-map [$$39, $$o2] <- index-search("CSX", 0, "test", "CSX", true, false, 1, $$48, 1, $$48, true, true, true)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                order (ASC, $$48)
                                                 -- STABLE_SORT [$$48(ASC)]  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH (test.CSX.ngram_index_CSX)  |PARTITIONED|
+                                                    unnest-map [$$48] <- index-search("ngram_index_CSX", 5, "test", "CSX", true, true, 0, missing, 12, false, 1, $$36)
+                                                    -- LENGTH_PARTITIONED_INVERTED_INDEX_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                        project ([$$38, $$36])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$36] <- [$$47.getField("title")]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                                              data-scan []<-[$$38, $$47] <- test.DBLP
+                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  empty-tuple-source
                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01_ps.plan
index 3066ed0..594b8a8 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01_ps.plan
@@ -1,83 +1,160 @@
+distribute result [$$50]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$50])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$50] <- [{"tweetid1": $$61, "loc1": $$53, "nearby-message": $$49}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$61)
           -- STABLE_SORT [$$61(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$61(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$76
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- PRE_CLUSTERED_GROUP_BY[$$54]  |PARTITIONED|
-                              {
+                      group by ([$$61 := $$54]) decor ([$$53]) {
+                                aggregate [$$49] <- [listify({"tweetid2": $$55, "loc2": $$56})]
                                 -- AGGREGATE  |LOCAL|
+                                  select (not(is-missing($$55)))
                                   -- STREAM_SELECT  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- PRE_CLUSTERED_GROUP_BY[$$54]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$54) (ASC, $$55)
                           -- STABLE_SORT [$$54(ASC), $$55(ASC)]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$54]  |PARTITIONED|
+                              project ([$$53, $$55, $$56, $$54])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                select (spatial-intersect($$56, $$n)) retain-untrue ($$55 <- MISSING)
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  project ([$$53, $$54, $$n, $$55, $$56])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$56] <- [$$t2.getField("sender-location")]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$53, $$54, $$n, $$55, $$t2])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                          left-outer-unnest-map [$$55, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$73, 1, $$73, true, true, true)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              order (ASC, $$73)
                                               -- STABLE_SORT [$$73(ASC)]  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  project ([$$53, $$54, $$n, $$73])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- RTREE_SEARCH (test.TweetMessages.twmSndLocIx)  |PARTITIONED|
+                                                      left-outer-unnest-map [$$69, $$70, $$71, $$72, $$73] <- index-search("twmSndLocIx", 1, "test", "TweetMessages", true, true, 4, $$65, $$66, $$67, $$68)
+                                                      -- RTREE_SEARCH  |PARTITIONED|
+                                                        exchange
                                                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                          assign [$$65, $$66, $$67, $$68] <- [create-mbr($$n, 2, 0), create-mbr($$n, 2, 1), create-mbr($$n, 2, 2), create-mbr($$n, 2, 3)]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            assign [$$n] <- [create-circle($$53, 0.5)]
                                                             -- ASSIGN  |PARTITIONED|
+                                                              project ([$$54, $$53])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$53] <- [$$t1.getField("sender-location")]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                    unnest-map [$$54, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$62, true, false, false)
+                                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        assign [$$62] <- [10]
                                                                         -- ASSIGN  |PARTITIONED|
+                                                                          empty-tuple-source
                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$76] <- [agg-range-map($$74, $$75)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$74, $$75] <- [agg-local-sampling($$61), agg-null-writer($$61)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$61])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- PRE_CLUSTERED_GROUP_BY[$$54]  |PARTITIONED|
-                                        {
+                                group by ([$$61 := $$54]) decor ([$$53]) {
+                                          aggregate [$$49] <- [listify({"tweetid2": $$55, "loc2": $$56})]
                                           -- AGGREGATE  |LOCAL|
+                                            select (not(is-missing($$55)))
                                             -- STREAM_SELECT  |LOCAL|
+                                              nested tuple source
                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- PRE_CLUSTERED_GROUP_BY[$$54]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$54) (ASC, $$55)
                                     -- STABLE_SORT [$$54(ASC), $$55(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$54]  |PARTITIONED|
+                                        project ([$$53, $$55, $$56, $$54])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          select (spatial-intersect($$56, $$n)) retain-untrue ($$55 <- MISSING)
                                           -- STREAM_SELECT  |PARTITIONED|
+                                            project ([$$53, $$54, $$n, $$55, $$56])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$56] <- [$$t2.getField("sender-location")]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$53, $$54, $$n, $$55, $$t2])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                    left-outer-unnest-map [$$55, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$73, 1, $$73, true, true, true)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        order (ASC, $$73)
                                                         -- STABLE_SORT [$$73(ASC)]  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            project ([$$53, $$54, $$n, $$73])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- RTREE_SEARCH (test.TweetMessages.twmSndLocIx)  |PARTITIONED|
+                                                                left-outer-unnest-map [$$69, $$70, $$71, $$72, $$73] <- index-search("twmSndLocIx", 1, "test", "TweetMessages", true, true, 4, $$65, $$66, $$67, $$68)
+                                                                -- RTREE_SEARCH  |PARTITIONED|
+                                                                  exchange
                                                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                    assign [$$65, $$66, $$67, $$68] <- [create-mbr($$n, 2, 0), create-mbr($$n, 2, 1), create-mbr($$n, 2, 2), create-mbr($$n, 2, 3)]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      assign [$$n] <- [create-circle($$53, 0.5)]
                                                                       -- ASSIGN  |PARTITIONED|
+                                                                        project ([$$54, $$53])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          assign [$$53] <- [$$t1.getField("sender-location")]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                              -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                              unnest-map [$$54, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$62, true, false, false)
+                                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  assign [$$62] <- [10]
                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                    empty-tuple-source
                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02_ps.plan
index e183f09..d75672a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-enforced/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02_ps.plan
@@ -1,83 +1,160 @@
+distribute result [$$54]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$54])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$54] <- [{"tweetid1": $$66, "loc1": $$57, "nearby-message": $$53}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$66)
           -- STABLE_SORT [$$66(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$66(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$81
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- PRE_CLUSTERED_GROUP_BY[$$58]  |PARTITIONED|
-                              {
+                      group by ([$$66 := $$58]) decor ([$$57]) {
+                                aggregate [$$53] <- [listify({"tweetid2": $$59, "loc2": $$61})]
                                 -- AGGREGATE  |LOCAL|
+                                  select (not(is-missing($$59)))
                                   -- STREAM_SELECT  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- PRE_CLUSTERED_GROUP_BY[$$58]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$58) (ASC, $$59)
                           -- STABLE_SORT [$$58(ASC), $$59(ASC)]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$58]  |PARTITIONED|
+                              project ([$$57, $$59, $$61, $$58])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                select (and(spatial-intersect($$61, $$n), neq($$58, $$59))) retain-untrue ($$59 <- MISSING)
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  project ([$$57, $$58, $$n, $$59, $$61])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$61] <- [$$t2.getField("sender-location")]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$57, $$58, $$n, $$59, $$t2])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                          left-outer-unnest-map [$$59, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$78, 1, $$78, true, true, true)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              order (ASC, $$78)
                                               -- STABLE_SORT [$$78(ASC)]  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  project ([$$57, $$58, $$n, $$78])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- RTREE_SEARCH (test.TweetMessages.twmSndLocIx)  |PARTITIONED|
+                                                      left-outer-unnest-map [$$74, $$75, $$76, $$77, $$78] <- index-search("twmSndLocIx", 1, "test", "TweetMessages", true, true, 4, $$70, $$71, $$72, $$73)
+                                                      -- RTREE_SEARCH  |PARTITIONED|
+                                                        exchange
                                                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                          assign [$$70, $$71, $$72, $$73] <- [create-mbr($$n, 2, 0), create-mbr($$n, 2, 1), create-mbr($$n, 2, 2), create-mbr($$n, 2, 3)]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            assign [$$n] <- [create-circle($$57, 0.5)]
                                                             -- ASSIGN  |PARTITIONED|
+                                                              project ([$$58, $$57])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$57] <- [$$t1.getField("sender-location")]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                    unnest-map [$$58, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$67, true, false, false)
+                                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        assign [$$67] <- [10]
                                                                         -- ASSIGN  |PARTITIONED|
+                                                                          empty-tuple-source
                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$81] <- [agg-range-map($$79, $$80)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$79, $$80] <- [agg-local-sampling($$66), agg-null-writer($$66)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$66])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- PRE_CLUSTERED_GROUP_BY[$$58]  |PARTITIONED|
-                                        {
+                                group by ([$$66 := $$58]) decor ([$$57]) {
+                                          aggregate [$$53] <- [listify({"tweetid2": $$59, "loc2": $$61})]
                                           -- AGGREGATE  |LOCAL|
+                                            select (not(is-missing($$59)))
                                             -- STREAM_SELECT  |LOCAL|
+                                              nested tuple source
                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- PRE_CLUSTERED_GROUP_BY[$$58]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$58) (ASC, $$59)
                                     -- STABLE_SORT [$$58(ASC), $$59(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$58]  |PARTITIONED|
+                                        project ([$$57, $$59, $$61, $$58])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          select (and(spatial-intersect($$61, $$n), neq($$58, $$59))) retain-untrue ($$59 <- MISSING)
                                           -- STREAM_SELECT  |PARTITIONED|
+                                            project ([$$57, $$58, $$n, $$59, $$61])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$61] <- [$$t2.getField("sender-location")]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$57, $$58, $$n, $$59, $$t2])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                    left-outer-unnest-map [$$59, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$78, 1, $$78, true, true, true)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        order (ASC, $$78)
                                                         -- STABLE_SORT [$$78(ASC)]  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            project ([$$57, $$58, $$n, $$78])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- RTREE_SEARCH (test.TweetMessages.twmSndLocIx)  |PARTITIONED|
+                                                                left-outer-unnest-map [$$74, $$75, $$76, $$77, $$78] <- index-search("twmSndLocIx", 1, "test", "TweetMessages", true, true, 4, $$70, $$71, $$72, $$73)
+                                                                -- RTREE_SEARCH  |PARTITIONED|
+                                                                  exchange
                                                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                    assign [$$70, $$71, $$72, $$73] <- [create-mbr($$n, 2, 0), create-mbr($$n, 2, 1), create-mbr($$n, 2, 2), create-mbr($$n, 2, 3)]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      assign [$$n] <- [create-circle($$57, 0.5)]
                                                                       -- ASSIGN  |PARTITIONED|
+                                                                        project ([$$58, $$57])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          assign [$$57] <- [$$t1.getField("sender-location")]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                              -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                              unnest-map [$$58, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$67, true, false, false)
+                                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  assign [$$67] <- [10]
                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                    empty-tuple-source
                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-composite-key-non-enforced/btree-composite-key-non-enforced-03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-composite-key-non-enforced/btree-composite-key-non-enforced-03.plan
index b266aa8..f592552 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-composite-key-non-enforced/btree-composite-key-non-enforced-03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-composite-key-non-enforced/btree-composite-key-non-enforced-03.plan
@@ -1,17 +1,34 @@
+distribute result [$$18]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$18])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (and(eq($$t.getField("c_x"), "x2"), eq($$t.getField("c_z"), "z2")))
       -- STREAM_SELECT  |PARTITIONED|
+        assign [$$18] <- [$$t.getField("c_value")]
         -- ASSIGN  |PARTITIONED|
+          project ([$$t])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+              unnest-map [$$19, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$27, 1, $$27, true, true, true)
+              -- BTREE_SEARCH  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  order (ASC, $$27)
                   -- STABLE_SORT [$$27(ASC)]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$27])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (test.TestOpen.idx_xyz)  |PARTITIONED|
+                          unnest-map [$$24, $$25, $$26, $$27] <- index-search("idx_xyz", 0, "test", "TestOpen", false, false, 1, $$22, 1, $$23, true, true, true)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              assign [$$22, $$23] <- ["x2", "x2"]
                               -- ASSIGN  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-composite-key-non-enforced/btree-composite-key-non-enforced-04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-composite-key-non-enforced/btree-composite-key-non-enforced-04.plan
index f88176b..ffddfa3 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-composite-key-non-enforced/btree-composite-key-non-enforced-04.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-composite-key-non-enforced/btree-composite-key-non-enforced-04.plan
@@ -1,17 +1,34 @@
+distribute result [$$20]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$20])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (and(eq($$t.getField("c_x"), "x2"), gt($$t.getField("c_y"), 1), eq($$t.getField("c_z"), "z2")))
       -- STREAM_SELECT  |PARTITIONED|
+        assign [$$20] <- [$$t.getField("c_value")]
         -- ASSIGN  |PARTITIONED|
+          project ([$$t])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+              unnest-map [$$21, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$30, 1, $$30, true, true, true)
+              -- BTREE_SEARCH  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  order (ASC, $$30)
                   -- STABLE_SORT [$$30(ASC)]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$30])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (test.TestOpen.idx_xyz)  |PARTITIONED|
+                          unnest-map [$$27, $$28, $$29, $$30] <- index-search("idx_xyz", 0, "test", "TestOpen", false, false, 1, $$25, 1, $$26, true, true, true)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              assign [$$25, $$26] <- ["x2", "x2"]
                               -- ASSIGN  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-05.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-05.plan
index ea60aab..a9b1087 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-05.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-05.plan
@@ -1,26 +1,52 @@
+distribute result [$$29]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$29])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$29] <- [{"c1": $$36, "c2": $$37}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$36(ASC), $$37(ASC) ]  |PARTITIONED|
+          order (ASC, $$36) (ASC, $$37)
           -- STABLE_SORT [$$36(ASC), $$37(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$36, $$37])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  join (eq($$34, $$35))
                   -- HYBRID_HASH_JOIN [$$34][$$35]  |PARTITIONED|
+                    exchange
                     -- HASH_PARTITION_EXCHANGE [$$34]  |PARTITIONED|
+                      project ([$$36, $$34])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$36, $$34] <- [$$t1.getField("c_x"), $$t1.getField("c_s")]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$t1])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (test.TestOpen1)  |PARTITIONED|
+                              data-scan []<-[$$32, $$t1] <- test.TestOpen1
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                    exchange
                     -- HASH_PARTITION_EXCHANGE [$$35]  |PARTITIONED|
+                      project ([$$37, $$35])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$37, $$35] <- [$$t2.getField("c_x"), $$t2.getField("c_s")]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$t2])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (test.TestOpen2)  |PARTITIONED|
+                              data-scan []<-[$$33, $$t2] <- test.TestOpen2
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-05_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-05_ps.plan
index 45133f4..a4b78ba 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-05_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-05_ps.plan
@@ -1,56 +1,112 @@
+distribute result [$$29]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$29])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$29] <- [{"c1": $$36, "c2": $$37}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$36) (ASC, $$37)
           -- STABLE_SORT [$$36(ASC), $$37(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$36(ASC), $$37(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$43
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$36, $$37])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          join (eq($$34, $$35))
                           -- HYBRID_HASH_JOIN [$$34][$$35]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$34]  |PARTITIONED|
+                              project ([$$36, $$34])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$36, $$34] <- [$$t1.getField("c_x"), $$t1.getField("c_s")]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$t1])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.TestOpen1)  |PARTITIONED|
+                                      data-scan []<-[$$32, $$t1] <- test.TestOpen1
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$35]  |PARTITIONED|
+                              project ([$$37, $$35])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$37, $$35] <- [$$t2.getField("c_x"), $$t2.getField("c_s")]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$t2])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.TestOpen2)  |PARTITIONED|
+                                      data-scan []<-[$$33, $$t2] <- test.TestOpen2
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$43] <- [agg-range-map($$40, $$41, $$42)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$40, $$41, $$42] <- [agg-local-sampling($$36, $$37), agg-null-writer($$36), agg-null-writer($$37)]
                       -- AGGREGATE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$36, $$37])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  join (eq($$34, $$35))
                                   -- HYBRID_HASH_JOIN [$$34][$$35]  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$34]  |PARTITIONED|
+                                      project ([$$36, $$34])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$36, $$34] <- [$$t1.getField("c_x"), $$t1.getField("c_s")]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$t1])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.TestOpen1)  |PARTITIONED|
+                                              data-scan []<-[$$32, $$t1] <- test.TestOpen1
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$35]  |PARTITIONED|
+                                      project ([$$37, $$35])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$37, $$35] <- [$$t2.getField("c_x"), $$t2.getField("c_s")]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$t2])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.TestOpen2)  |PARTITIONED|
+                                              data-scan []<-[$$33, $$t2] <- test.TestOpen2
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-06.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-06.plan
index ea60aab..a9b1087 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-06.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-06.plan
@@ -1,26 +1,52 @@
+distribute result [$$29]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$29])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$29] <- [{"c1": $$36, "c2": $$37}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$36(ASC), $$37(ASC) ]  |PARTITIONED|
+          order (ASC, $$36) (ASC, $$37)
           -- STABLE_SORT [$$36(ASC), $$37(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$36, $$37])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  join (eq($$34, $$35))
                   -- HYBRID_HASH_JOIN [$$34][$$35]  |PARTITIONED|
+                    exchange
                     -- HASH_PARTITION_EXCHANGE [$$34]  |PARTITIONED|
+                      project ([$$36, $$34])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$36, $$34] <- [$$t1.getField("c_x"), $$t1.getField("c_s")]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$t1])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (test.TestOpen1)  |PARTITIONED|
+                              data-scan []<-[$$32, $$t1] <- test.TestOpen1
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                    exchange
                     -- HASH_PARTITION_EXCHANGE [$$35]  |PARTITIONED|
+                      project ([$$37, $$35])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$37, $$35] <- [$$t2.getField("c_x"), $$t2.getField("c_s")]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$t2])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (test.TestOpen2)  |PARTITIONED|
+                              data-scan []<-[$$33, $$t2] <- test.TestOpen2
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-06_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-06_ps.plan
index 45133f4..a4b78ba 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-06_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-06_ps.plan
@@ -1,56 +1,112 @@
+distribute result [$$29]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$29])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$29] <- [{"c1": $$36, "c2": $$37}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$36) (ASC, $$37)
           -- STABLE_SORT [$$36(ASC), $$37(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$36(ASC), $$37(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$43
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$36, $$37])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          join (eq($$34, $$35))
                           -- HYBRID_HASH_JOIN [$$34][$$35]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$34]  |PARTITIONED|
+                              project ([$$36, $$34])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$36, $$34] <- [$$t1.getField("c_x"), $$t1.getField("c_s")]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$t1])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.TestOpen1)  |PARTITIONED|
+                                      data-scan []<-[$$32, $$t1] <- test.TestOpen1
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$35]  |PARTITIONED|
+                              project ([$$37, $$35])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$37, $$35] <- [$$t2.getField("c_x"), $$t2.getField("c_s")]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$t2])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.TestOpen2)  |PARTITIONED|
+                                      data-scan []<-[$$33, $$t2] <- test.TestOpen2
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$43] <- [agg-range-map($$40, $$41, $$42)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$40, $$41, $$42] <- [agg-local-sampling($$36, $$37), agg-null-writer($$36), agg-null-writer($$37)]
                       -- AGGREGATE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$36, $$37])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  join (eq($$34, $$35))
                                   -- HYBRID_HASH_JOIN [$$34][$$35]  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$34]  |PARTITIONED|
+                                      project ([$$36, $$34])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$36, $$34] <- [$$t1.getField("c_x"), $$t1.getField("c_s")]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$t1])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.TestOpen1)  |PARTITIONED|
+                                              data-scan []<-[$$32, $$t1] <- test.TestOpen1
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$35]  |PARTITIONED|
+                                      project ([$$37, $$35])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$37, $$35] <- [$$t2.getField("c_x"), $$t2.getField("c_s")]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$t2])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.TestOpen2)  |PARTITIONED|
+                                              data-scan []<-[$$33, $$t2] <- test.TestOpen2
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-07.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-07.plan
index d347e73..a47ef19 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-07.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-07.plan
@@ -1,26 +1,52 @@
+distribute result [$$30]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$30])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$30] <- [{"c1": $$38, "c2": $$39}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$38(ASC), $$39(ASC) ]  |PARTITIONED|
+          order (ASC, $$38) (ASC, $$39)
           -- STABLE_SORT [$$38(ASC), $$39(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$38, $$39])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  join (eq($$35, $$36))
                   -- HYBRID_HASH_JOIN [$$35][$$36]  |PARTITIONED|
+                    exchange
                     -- HASH_PARTITION_EXCHANGE [$$35]  |PARTITIONED|
+                      project ([$$38, $$35])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$35, $$38] <- [to-string($$t1.getField("c_s")), $$t1.getField("c_x")]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$t1])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (test.TestOpen1)  |PARTITIONED|
+                              data-scan []<-[$$33, $$t1] <- test.TestOpen1
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                    exchange
                     -- HASH_PARTITION_EXCHANGE [$$36]  |PARTITIONED|
+                      project ([$$39, $$36])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$39, $$36] <- [$$t2.getField("c_x"), $$t2.getField("c_s")]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$t2])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (test.TestOpen2)  |PARTITIONED|
+                              data-scan []<-[$$34, $$t2] <- test.TestOpen2
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-07_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-07_ps.plan
index 7dfa995..789bb42 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-07_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-07_ps.plan
@@ -1,56 +1,112 @@
+distribute result [$$30]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$30])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$30] <- [{"c1": $$38, "c2": $$39}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$38) (ASC, $$39)
           -- STABLE_SORT [$$38(ASC), $$39(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$38(ASC), $$39(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$45
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$38, $$39])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          join (eq($$35, $$36))
                           -- HYBRID_HASH_JOIN [$$35][$$36]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$35]  |PARTITIONED|
+                              project ([$$38, $$35])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$35, $$38] <- [to-string($$t1.getField("c_s")), $$t1.getField("c_x")]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$t1])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.TestOpen1)  |PARTITIONED|
+                                      data-scan []<-[$$33, $$t1] <- test.TestOpen1
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$36]  |PARTITIONED|
+                              project ([$$39, $$36])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$39, $$36] <- [$$t2.getField("c_x"), $$t2.getField("c_s")]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$t2])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.TestOpen2)  |PARTITIONED|
+                                      data-scan []<-[$$34, $$t2] <- test.TestOpen2
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$45] <- [agg-range-map($$42, $$43, $$44)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$42, $$43, $$44] <- [agg-local-sampling($$38, $$39), agg-null-writer($$38), agg-null-writer($$39)]
                       -- AGGREGATE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$38, $$39])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  join (eq($$35, $$36))
                                   -- HYBRID_HASH_JOIN [$$35][$$36]  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$35]  |PARTITIONED|
+                                      project ([$$38, $$35])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$35, $$38] <- [to-string($$t1.getField("c_s")), $$t1.getField("c_x")]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$t1])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.TestOpen1)  |PARTITIONED|
+                                              data-scan []<-[$$33, $$t1] <- test.TestOpen1
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$36]  |PARTITIONED|
+                                      project ([$$39, $$36])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$39, $$36] <- [$$t2.getField("c_x"), $$t2.getField("c_s")]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$t2])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.TestOpen2)  |PARTITIONED|
+                                              data-scan []<-[$$34, $$t2] <- test.TestOpen2
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-08.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-08.plan
index e2f07be..847827d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-08.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-08.plan
@@ -1,27 +1,54 @@
+distribute result [$$30]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$30])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$30] <- [{"c1": $$38, "c2": $$39}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$38(ASC), $$39(ASC) ]  |PARTITIONED|
+          order (ASC, $$38) (ASC, $$39)
           -- STABLE_SORT [$$38(ASC), $$39(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$38, $$39])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (eq($$35, $$t2.getField("c_s")))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$39] <- [$$t2.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$38, $$35, $$t2])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.TestOpen2.TestOpen2)  |PARTITIONED|
+                        unnest-map [$$34, $$t2] <- index-search("TestOpen2", 0, "test", "TestOpen2", true, false, 1, $$43, 1, $$43, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$43)
                             -- STABLE_SORT [$$43(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$38, $$35, $$43])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- BTREE_SEARCH (test.TestOpen2.idx_t2_s)  |PARTITIONED|
+                                    unnest-map [$$42, $$43] <- index-search("idx_t2_s", 0, "test", "TestOpen2", true, true, 1, $$35, 1, $$35, true, true, true)
+                                    -- BTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                        project ([$$35, $$38])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$35, $$38] <- [to-string($$t1.getField("c_s")), $$t1.getField("c_x")]
                                           -- ASSIGN  |PARTITIONED|
+                                            project ([$$t1])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- DATASOURCE_SCAN (test.TestOpen1)  |PARTITIONED|
+                                                data-scan []<-[$$33, $$t1] <- test.TestOpen1
+                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-08_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-08_ps.plan
index af04b9c..4ace499 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-08_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-08_ps.plan
@@ -1,58 +1,116 @@
+distribute result [$$30]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$30])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$30] <- [{"c1": $$38, "c2": $$39}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$38) (ASC, $$39)
           -- STABLE_SORT [$$38(ASC), $$39(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$38(ASC), $$39(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$47
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$38, $$39])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (eq($$35, $$t2.getField("c_s")))
                         -- STREAM_SELECT  |PARTITIONED|
+                          assign [$$39] <- [$$t2.getField("c_x")]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$38, $$35, $$t2])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- BTREE_SEARCH (test.TestOpen2.TestOpen2)  |PARTITIONED|
+                                unnest-map [$$34, $$t2] <- index-search("TestOpen2", 0, "test", "TestOpen2", true, false, 1, $$43, 1, $$43, true, true, true)
+                                -- BTREE_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$43)
                                     -- STABLE_SORT [$$43(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$38, $$35, $$43])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (test.TestOpen2.idx_t2_s)  |PARTITIONED|
+                                            unnest-map [$$42, $$43] <- index-search("idx_t2_s", 0, "test", "TestOpen2", true, true, 1, $$35, 1, $$35, true, true, true)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                project ([$$35, $$38])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$35, $$38] <- [to-string($$t1.getField("c_s")), $$t1.getField("c_x")]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$t1])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.TestOpen1)  |PARTITIONED|
+                                                        data-scan []<-[$$33, $$t1] <- test.TestOpen1
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$47] <- [agg-range-map($$44, $$45, $$46)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$44, $$45, $$46] <- [agg-local-sampling($$38, $$39), agg-null-writer($$38), agg-null-writer($$39)]
                       -- AGGREGATE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$38, $$39])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                select (eq($$35, $$t2.getField("c_s")))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  assign [$$39] <- [$$t2.getField("c_x")]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$38, $$35, $$t2])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.TestOpen2.TestOpen2)  |PARTITIONED|
+                                        unnest-map [$$34, $$t2] <- index-search("TestOpen2", 0, "test", "TestOpen2", true, false, 1, $$43, 1, $$43, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            order (ASC, $$43)
                                             -- STABLE_SORT [$$43(ASC)]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$38, $$35, $$43])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (test.TestOpen2.idx_t2_s)  |PARTITIONED|
+                                                    unnest-map [$$42, $$43] <- index-search("idx_t2_s", 0, "test", "TestOpen2", true, true, 1, $$35, 1, $$35, true, true, true)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                        project ([$$35, $$38])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$35, $$38] <- [to-string($$t1.getField("c_s")), $$t1.getField("c_x")]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            project ([$$t1])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- DATASOURCE_SCAN (test.TestOpen1)  |PARTITIONED|
+                                                                data-scan []<-[$$33, $$t1] <- test.TestOpen1
+                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    empty-tuple-source
                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-09.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-09.plan
index 7afc23e..78df02e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-09.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-09.plan
@@ -1,27 +1,54 @@
+distribute result [$$30]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$30])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$30] <- [{"c1": $$38, "c2": $$39}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$38(ASC), $$39(ASC) ]  |PARTITIONED|
+          order (ASC, $$38) (ASC, $$39)
           -- STABLE_SORT [$$38(ASC), $$39(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$38, $$39])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (eq($$35, $$t2.getField("c_i64")))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$39] <- [$$t2.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$38, $$35, $$t2])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.TestOpen2.TestOpen2)  |PARTITIONED|
+                        unnest-map [$$34, $$t2] <- index-search("TestOpen2", 0, "test", "TestOpen2", true, false, 1, $$43, 1, $$43, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$43)
                             -- STABLE_SORT [$$43(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$38, $$35, $$43])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- BTREE_SEARCH (test.TestOpen2.idx_t2_i64)  |PARTITIONED|
+                                    unnest-map [$$42, $$43] <- index-search("idx_t2_i64", 0, "test", "TestOpen2", true, true, 1, $$35, 1, $$35, true, true, true)
+                                    -- BTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                        project ([$$35, $$38])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$35, $$38] <- [to-bigint($$t1.getField("c_i64")), $$t1.getField("c_x")]
                                           -- ASSIGN  |PARTITIONED|
+                                            project ([$$t1])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- DATASOURCE_SCAN (test.TestOpen1)  |PARTITIONED|
+                                                data-scan []<-[$$33, $$t1] <- test.TestOpen1
+                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-09_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-09_ps.plan
index aaa92c7..bd34f10 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-09_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-09_ps.plan
@@ -1,58 +1,116 @@
+distribute result [$$30]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$30])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$30] <- [{"c1": $$38, "c2": $$39}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$38) (ASC, $$39)
           -- STABLE_SORT [$$38(ASC), $$39(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$38(ASC), $$39(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$47
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$38, $$39])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (eq($$35, $$t2.getField("c_i64")))
                         -- STREAM_SELECT  |PARTITIONED|
+                          assign [$$39] <- [$$t2.getField("c_x")]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$38, $$35, $$t2])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- BTREE_SEARCH (test.TestOpen2.TestOpen2)  |PARTITIONED|
+                                unnest-map [$$34, $$t2] <- index-search("TestOpen2", 0, "test", "TestOpen2", true, false, 1, $$43, 1, $$43, true, true, true)
+                                -- BTREE_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$43)
                                     -- STABLE_SORT [$$43(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$38, $$35, $$43])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (test.TestOpen2.idx_t2_i64)  |PARTITIONED|
+                                            unnest-map [$$42, $$43] <- index-search("idx_t2_i64", 0, "test", "TestOpen2", true, true, 1, $$35, 1, $$35, true, true, true)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                project ([$$35, $$38])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$35, $$38] <- [to-bigint($$t1.getField("c_i64")), $$t1.getField("c_x")]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$t1])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.TestOpen1)  |PARTITIONED|
+                                                        data-scan []<-[$$33, $$t1] <- test.TestOpen1
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$47] <- [agg-range-map($$44, $$45, $$46)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$44, $$45, $$46] <- [agg-local-sampling($$38, $$39), agg-null-writer($$38), agg-null-writer($$39)]
                       -- AGGREGATE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$38, $$39])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                select (eq($$35, $$t2.getField("c_i64")))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  assign [$$39] <- [$$t2.getField("c_x")]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$38, $$35, $$t2])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.TestOpen2.TestOpen2)  |PARTITIONED|
+                                        unnest-map [$$34, $$t2] <- index-search("TestOpen2", 0, "test", "TestOpen2", true, false, 1, $$43, 1, $$43, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            order (ASC, $$43)
                                             -- STABLE_SORT [$$43(ASC)]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$38, $$35, $$43])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (test.TestOpen2.idx_t2_i64)  |PARTITIONED|
+                                                    unnest-map [$$42, $$43] <- index-search("idx_t2_i64", 0, "test", "TestOpen2", true, true, 1, $$35, 1, $$35, true, true, true)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                        project ([$$35, $$38])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$35, $$38] <- [to-bigint($$t1.getField("c_i64")), $$t1.getField("c_x")]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            project ([$$t1])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- DATASOURCE_SCAN (test.TestOpen1)  |PARTITIONED|
+                                                                data-scan []<-[$$33, $$t1] <- test.TestOpen1
+                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    empty-tuple-source
                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-04.plan
index c32b198..84753e1 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-04.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-04.plan
@@ -1,22 +1,44 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"res": $$20}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$20(ASC) ]  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$20])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (eq($$t.getField("c_s"), "world"))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$20] <- [$$t.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$t])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                        unnest-map [$$18, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$25, 1, $$25, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$25)
                             -- STABLE_SORT [$$25(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$25])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- BTREE_SEARCH (test.TestOpen.idx_s)  |PARTITIONED|
+                                    unnest-map [$$24, $$25] <- index-search("idx_s", 0, "test", "TestOpen", false, false, 1, $$22, 1, $$23, true, true, true)
+                                    -- BTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        assign [$$22, $$23] <- ["world", "world"]
                                         -- ASSIGN  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-04_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-04_ps.plan
index bc44f0e..2246a6b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-04_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-04_ps.plan
@@ -1,48 +1,96 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"res": $$20}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$20(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$28
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$20])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (eq($$t.getField("c_s"), "world"))
                         -- STREAM_SELECT  |PARTITIONED|
+                          assign [$$20] <- [$$t.getField("c_x")]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$t])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                                unnest-map [$$18, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$25, 1, $$25, true, true, true)
+                                -- BTREE_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$25)
                                     -- STABLE_SORT [$$25(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$25])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (test.TestOpen.idx_s)  |PARTITIONED|
+                                            unnest-map [$$24, $$25] <- index-search("idx_s", 0, "test", "TestOpen", false, false, 1, $$22, 1, $$23, true, true, true)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$22, $$23] <- ["world", "world"]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$28] <- [agg-range-map($$26, $$27)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$26, $$27] <- [agg-local-sampling($$20), agg-null-writer($$20)]
                       -- AGGREGATE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$20])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                select (eq($$t.getField("c_s"), "world"))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  assign [$$20] <- [$$t.getField("c_x")]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$t])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                                        unnest-map [$$18, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$25, 1, $$25, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            order (ASC, $$25)
                                             -- STABLE_SORT [$$25(ASC)]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$25])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (test.TestOpen.idx_s)  |PARTITIONED|
+                                                    unnest-map [$$24, $$25] <- index-search("idx_s", 0, "test", "TestOpen", false, false, 1, $$22, 1, $$23, true, true, true)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        assign [$$22, $$23] <- ["world", "world"]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-05.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-05.plan
index bb301a0..16c3fd4 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-05.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-05.plan
@@ -1,22 +1,44 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"res": $$20}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$20(ASC) ]  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$20])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (eq($$t.getField("c_i64"), 2))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$20] <- [$$t.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$t])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                        unnest-map [$$18, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$25, 1, $$25, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$25)
                             -- STABLE_SORT [$$25(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$25])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- BTREE_SEARCH (test.TestOpen.idx_i64)  |PARTITIONED|
+                                    unnest-map [$$24, $$25] <- index-search("idx_i64", 0, "test", "TestOpen", false, false, 1, $$22, 1, $$23, true, true, true)
+                                    -- BTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        assign [$$22, $$23] <- [2, 2]
                                         -- ASSIGN  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-05_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-05_ps.plan
index bb1fe46..f8eae6e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-05_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-05_ps.plan
@@ -1,48 +1,96 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"res": $$20}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$20(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$28
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$20])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (eq($$t.getField("c_i64"), 2))
                         -- STREAM_SELECT  |PARTITIONED|
+                          assign [$$20] <- [$$t.getField("c_x")]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$t])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                                unnest-map [$$18, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$25, 1, $$25, true, true, true)
+                                -- BTREE_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$25)
                                     -- STABLE_SORT [$$25(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$25])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (test.TestOpen.idx_i64)  |PARTITIONED|
+                                            unnest-map [$$24, $$25] <- index-search("idx_i64", 0, "test", "TestOpen", false, false, 1, $$22, 1, $$23, true, true, true)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$22, $$23] <- [2, 2]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$28] <- [agg-range-map($$26, $$27)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$26, $$27] <- [agg-local-sampling($$20), agg-null-writer($$20)]
                       -- AGGREGATE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$20])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                select (eq($$t.getField("c_i64"), 2))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  assign [$$20] <- [$$t.getField("c_x")]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$t])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                                        unnest-map [$$18, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$25, 1, $$25, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            order (ASC, $$25)
                                             -- STABLE_SORT [$$25(ASC)]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$25])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (test.TestOpen.idx_i64)  |PARTITIONED|
+                                                    unnest-map [$$24, $$25] <- index-search("idx_i64", 0, "test", "TestOpen", false, false, 1, $$22, 1, $$23, true, true, true)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        assign [$$22, $$23] <- [2, 2]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-06.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-06.plan
index b5d7af2..797c441 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-06.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-06.plan
@@ -1,22 +1,44 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"res": $$20}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$20(ASC) ]  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$20])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (gt($$t.getField("c_i64"), 2))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$20] <- [$$t.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$t])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                        unnest-map [$$18, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$24, 1, $$24, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$24)
                             -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$24])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- BTREE_SEARCH (test.TestOpen.idx_i64)  |PARTITIONED|
+                                    unnest-map [$$23, $$24] <- index-search("idx_i64", 0, "test", "TestOpen", false, false, 1, $$22, 0, true, true, false)
+                                    -- BTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        assign [$$22] <- [2]
                                         -- ASSIGN  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-06_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-06_ps.plan
index 5181114..61a9f64 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-06_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-06_ps.plan
@@ -1,48 +1,96 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"res": $$20}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$20(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$27
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$20])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (gt($$t.getField("c_i64"), 2))
                         -- STREAM_SELECT  |PARTITIONED|
+                          assign [$$20] <- [$$t.getField("c_x")]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$t])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                                unnest-map [$$18, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$24, 1, $$24, true, true, true)
+                                -- BTREE_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$24)
                                     -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$24])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (test.TestOpen.idx_i64)  |PARTITIONED|
+                                            unnest-map [$$23, $$24] <- index-search("idx_i64", 0, "test", "TestOpen", false, false, 1, $$22, 0, true, true, false)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$22] <- [2]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$27] <- [agg-range-map($$25, $$26)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$25, $$26] <- [agg-local-sampling($$20), agg-null-writer($$20)]
                       -- AGGREGATE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$20])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                select (gt($$t.getField("c_i64"), 2))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  assign [$$20] <- [$$t.getField("c_x")]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$t])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                                        unnest-map [$$18, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$24, 1, $$24, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            order (ASC, $$24)
                                             -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$24])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (test.TestOpen.idx_i64)  |PARTITIONED|
+                                                    unnest-map [$$23, $$24] <- index-search("idx_i64", 0, "test", "TestOpen", false, false, 1, $$22, 0, true, true, false)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        assign [$$22] <- [2]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-07.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-07.plan
index b5d7af2..70a63d9 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-07.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-07.plan
@@ -1,22 +1,44 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"res": $$20}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$20(ASC) ]  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$20])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (gt($$t.getField("c_i64"), 2.0))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$20] <- [$$t.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$t])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                        unnest-map [$$18, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$24, 1, $$24, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$24)
                             -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$24])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- BTREE_SEARCH (test.TestOpen.idx_i64)  |PARTITIONED|
+                                    unnest-map [$$23, $$24] <- index-search("idx_i64", 0, "test", "TestOpen", false, false, 1, $$22, 0, true, true, false)
+                                    -- BTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        assign [$$22] <- [2]
                                         -- ASSIGN  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-07_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-07_ps.plan
index 5181114..98d6951 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-07_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-07_ps.plan
@@ -1,48 +1,96 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"res": $$20}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$20(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$27
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$20])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (gt($$t.getField("c_i64"), 2.0))
                         -- STREAM_SELECT  |PARTITIONED|
+                          assign [$$20] <- [$$t.getField("c_x")]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$t])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                                unnest-map [$$18, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$24, 1, $$24, true, true, true)
+                                -- BTREE_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$24)
                                     -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$24])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (test.TestOpen.idx_i64)  |PARTITIONED|
+                                            unnest-map [$$23, $$24] <- index-search("idx_i64", 0, "test", "TestOpen", false, false, 1, $$22, 0, true, true, false)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$22] <- [2]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$27] <- [agg-range-map($$25, $$26)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$25, $$26] <- [agg-local-sampling($$20), agg-null-writer($$20)]
                       -- AGGREGATE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$20])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                select (gt($$t.getField("c_i64"), 2.0))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  assign [$$20] <- [$$t.getField("c_x")]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$t])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                                        unnest-map [$$18, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$24, 1, $$24, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            order (ASC, $$24)
                                             -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$24])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (test.TestOpen.idx_i64)  |PARTITIONED|
+                                                    unnest-map [$$23, $$24] <- index-search("idx_i64", 0, "test", "TestOpen", false, false, 1, $$22, 0, true, true, false)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        assign [$$22] <- [2]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-08.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-08.plan
index cc01990..0b1078c 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-08.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-08.plan
@@ -1,22 +1,44 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"res": $$20}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$20(ASC) ]  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$20])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (gt($$t.getField("c_i8"), 2))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$20] <- [$$t.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$t])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                        unnest-map [$$18, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$24, 1, $$24, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$24)
                             -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$24])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- BTREE_SEARCH (test.TestOpen.idx_i8)  |PARTITIONED|
+                                    unnest-map [$$23, $$24] <- index-search("idx_i8", 0, "test", "TestOpen", false, false, 1, $$22, 0, true, true, false)
+                                    -- BTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        assign [$$22] <- [2]
                                         -- ASSIGN  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-08_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-08_ps.plan
index fca170c..4dae617 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-08_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-08_ps.plan
@@ -1,48 +1,96 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"res": $$20}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$20(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$27
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$20])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (gt($$t.getField("c_i8"), 2))
                         -- STREAM_SELECT  |PARTITIONED|
+                          assign [$$20] <- [$$t.getField("c_x")]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$t])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                                unnest-map [$$18, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$24, 1, $$24, true, true, true)
+                                -- BTREE_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$24)
                                     -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$24])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (test.TestOpen.idx_i8)  |PARTITIONED|
+                                            unnest-map [$$23, $$24] <- index-search("idx_i8", 0, "test", "TestOpen", false, false, 1, $$22, 0, true, true, false)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$22] <- [2]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$27] <- [agg-range-map($$25, $$26)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$25, $$26] <- [agg-local-sampling($$20), agg-null-writer($$20)]
                       -- AGGREGATE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$20])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                select (gt($$t.getField("c_i8"), 2))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  assign [$$20] <- [$$t.getField("c_x")]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$t])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                                        unnest-map [$$18, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$24, 1, $$24, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            order (ASC, $$24)
                                             -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$24])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (test.TestOpen.idx_i8)  |PARTITIONED|
+                                                    unnest-map [$$23, $$24] <- index-search("idx_i8", 0, "test", "TestOpen", false, false, 1, $$22, 0, true, true, false)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        assign [$$22] <- [2]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-09.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-09.plan
index cc01990..3fb1f6b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-09.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-09.plan
@@ -1,22 +1,44 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"res": $$20}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$20(ASC) ]  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$20])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (gt($$t.getField("c_i8"), 2.5))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$20] <- [$$t.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$t])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                        unnest-map [$$18, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$24, 1, $$24, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$24)
                             -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$24])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- BTREE_SEARCH (test.TestOpen.idx_i8)  |PARTITIONED|
+                                    unnest-map [$$23, $$24] <- index-search("idx_i8", 0, "test", "TestOpen", false, false, 1, $$22, 0, true, true, false)
+                                    -- BTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        assign [$$22] <- [2]
                                         -- ASSIGN  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-09_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-09_ps.plan
index fca170c..a988282 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-09_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-09_ps.plan
@@ -1,48 +1,96 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"res": $$20}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$20(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$27
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$20])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (gt($$t.getField("c_i8"), 2.5))
                         -- STREAM_SELECT  |PARTITIONED|
+                          assign [$$20] <- [$$t.getField("c_x")]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$t])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                                unnest-map [$$18, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$24, 1, $$24, true, true, true)
+                                -- BTREE_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$24)
                                     -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$24])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (test.TestOpen.idx_i8)  |PARTITIONED|
+                                            unnest-map [$$23, $$24] <- index-search("idx_i8", 0, "test", "TestOpen", false, false, 1, $$22, 0, true, true, false)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$22] <- [2]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$27] <- [agg-range-map($$25, $$26)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$25, $$26] <- [agg-local-sampling($$20), agg-null-writer($$20)]
                       -- AGGREGATE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$20])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                select (gt($$t.getField("c_i8"), 2.5))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  assign [$$20] <- [$$t.getField("c_x")]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$t])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                                        unnest-map [$$18, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$24, 1, $$24, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            order (ASC, $$24)
                                             -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$24])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (test.TestOpen.idx_i8)  |PARTITIONED|
+                                                    unnest-map [$$23, $$24] <- index-search("idx_i8", 0, "test", "TestOpen", false, false, 1, $$22, 0, true, true, false)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        assign [$$22] <- [2]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-10.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-10.plan
index 71a312f..c084f63 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-10.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-10.plan
@@ -1,22 +1,44 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"res": $$20}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$20(ASC) ]  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$20])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (ge($$t.getField("c_d"), 3.25))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$20] <- [$$t.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$t])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                        unnest-map [$$18, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$24, 1, $$24, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$24)
                             -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$24])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- BTREE_SEARCH (test.TestOpen.idx_d)  |PARTITIONED|
+                                    unnest-map [$$23, $$24] <- index-search("idx_d", 0, "test", "TestOpen", false, false, 1, $$22, 0, true, true, false)
+                                    -- BTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        assign [$$22] <- [3.25]
                                         -- ASSIGN  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-105.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-105.plan
index a769c18..2ca33e8 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-105.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-105.plan
@@ -1,33 +1,66 @@
+distribute result [$$19]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$19])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$19] <- [{"res": $$24}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$24(ASC) ]  |PARTITIONED|
+          order (ASC, $$24)
           -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$24])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (and(gt($$t.getField("c_i8"), 2), lt($$t.getField("c_i64"), 3)))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$24] <- [$$t.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$t])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                        unnest-map [$$21, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$32, 1, $$32, true, true, true)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            intersect [$$32] <- [[$$28], [$$31]]
                             -- INTERSECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$28)
                                 -- STABLE_SORT [$$28(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$28])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.TestOpen.idx_3)  |PARTITIONED|
+                                        unnest-map [$$27, $$28] <- index-search("idx_3", 0, "test", "TestOpen", false, false, 0, 1, $$26, true, true, false)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            assign [$$26] <- [3]
                                             -- ASSIGN  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$31)
                                 -- STABLE_SORT [$$31(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$31])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.TestOpen.idx_4)  |PARTITIONED|
+                                        unnest-map [$$30, $$31] <- index-search("idx_4", 0, "test", "TestOpen", false, false, 1, $$29, 0, true, true, false)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            assign [$$29] <- [2]
                                             -- ASSIGN  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-105_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-105_ps.plan
index 4f87b34..ecb6472 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-105_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-105_ps.plan
@@ -1,70 +1,140 @@
+distribute result [$$19]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$19])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$19] <- [{"res": $$24}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$24)
           -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$24(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$35
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$24])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (and(gt($$t.getField("c_i8"), 2), lt($$t.getField("c_i64"), 3)))
                         -- STREAM_SELECT  |PARTITIONED|
+                          assign [$$24] <- [$$t.getField("c_x")]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$t])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                                unnest-map [$$21, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$32, 1, $$32, true, true, true)
+                                -- BTREE_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    intersect [$$32] <- [[$$28], [$$31]]
                                     -- INTERSECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        order (ASC, $$28)
                                         -- STABLE_SORT [$$28(ASC)]  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$28])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- BTREE_SEARCH (test.TestOpen.idx_3)  |PARTITIONED|
+                                                unnest-map [$$27, $$28] <- index-search("idx_3", 0, "test", "TestOpen", false, false, 0, 1, $$26, true, true, false)
+                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    assign [$$26] <- [3]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        order (ASC, $$31)
                                         -- STABLE_SORT [$$31(ASC)]  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$31])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- BTREE_SEARCH (test.TestOpen.idx_4)  |PARTITIONED|
+                                                unnest-map [$$30, $$31] <- index-search("idx_4", 0, "test", "TestOpen", false, false, 1, $$29, 0, true, true, false)
+                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    assign [$$29] <- [2]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$35] <- [agg-range-map($$33, $$34)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$33, $$34] <- [agg-local-sampling($$24), agg-null-writer($$24)]
                       -- AGGREGATE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$24])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                select (and(gt($$t.getField("c_i8"), 2), lt($$t.getField("c_i64"), 3)))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  assign [$$24] <- [$$t.getField("c_x")]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$t])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                                        unnest-map [$$21, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$32, 1, $$32, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            intersect [$$32] <- [[$$28], [$$31]]
                                             -- INTERSECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                order (ASC, $$28)
                                                 -- STABLE_SORT [$$28(ASC)]  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$$28])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- BTREE_SEARCH (test.TestOpen.idx_3)  |PARTITIONED|
+                                                        unnest-map [$$27, $$28] <- index-search("idx_3", 0, "test", "TestOpen", false, false, 0, 1, $$26, true, true, false)
+                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            assign [$$26] <- [3]
                                                             -- ASSIGN  |PARTITIONED|
+                                                              empty-tuple-source
                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                order (ASC, $$31)
                                                 -- STABLE_SORT [$$31(ASC)]  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$$31])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- BTREE_SEARCH (test.TestOpen.idx_4)  |PARTITIONED|
+                                                        unnest-map [$$30, $$31] <- index-search("idx_4", 0, "test", "TestOpen", false, false, 1, $$29, 0, true, true, false)
+                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            assign [$$29] <- [2]
                                                             -- ASSIGN  |PARTITIONED|
+                                                              empty-tuple-source
                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-10_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-10_ps.plan
index 62bf5b4..7ab85325 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-10_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-10_ps.plan
@@ -1,48 +1,96 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"res": $$20}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$20(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$27
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$20])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (ge($$t.getField("c_d"), 3.25))
                         -- STREAM_SELECT  |PARTITIONED|
+                          assign [$$20] <- [$$t.getField("c_x")]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$t])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                                unnest-map [$$18, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$24, 1, $$24, true, true, true)
+                                -- BTREE_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$24)
                                     -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$24])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (test.TestOpen.idx_d)  |PARTITIONED|
+                                            unnest-map [$$23, $$24] <- index-search("idx_d", 0, "test", "TestOpen", false, false, 1, $$22, 0, true, true, false)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$22] <- [3.25]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$27] <- [agg-range-map($$25, $$26)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$25, $$26] <- [agg-local-sampling($$20), agg-null-writer($$20)]
                       -- AGGREGATE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$20])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                select (ge($$t.getField("c_d"), 3.25))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  assign [$$20] <- [$$t.getField("c_x")]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$t])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                                        unnest-map [$$18, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$24, 1, $$24, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            order (ASC, $$24)
                                             -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$24])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (test.TestOpen.idx_d)  |PARTITIONED|
+                                                    unnest-map [$$23, $$24] <- index-search("idx_d", 0, "test", "TestOpen", false, false, 1, $$22, 0, true, true, false)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        assign [$$22] <- [3.25]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-11.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-11.plan
index d408e8f..943ee7c 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-11.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-11.plan
@@ -1,23 +1,46 @@
+distribute result [$$19]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$19])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$19] <- [{"res": $$23}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+          order (ASC, $$23)
           -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$23])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (and(gt($$21, 499), lt($$21, 99999)))
                 -- STREAM_SELECT  |PARTITIONED|
+                  project ([$$23, $$21])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$23, $$21] <- [$$t.getField("c_x"), $$t.getField("c_i8")]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$t])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                          unnest-map [$$22, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$28, 1, $$28, true, true, true)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              order (ASC, $$28)
                               -- STABLE_SORT [$$28(ASC)]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$28])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- BTREE_SEARCH (test.TestOpen.idx_i8)  |PARTITIONED|
+                                      unnest-map [$$27, $$28] <- index-search("idx_i8", 0, "test", "TestOpen", false, false, 1, $$25, 1, $$26, true, true, false)
+                                      -- BTREE_SEARCH  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$25, $$26] <- [127, 127]
                                           -- ASSIGN  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-11_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-11_ps.plan
index dbe5b68..5e5c6e4 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-11_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-11_ps.plan
@@ -1,50 +1,100 @@
+distribute result [$$19]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$19])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$19] <- [{"res": $$23}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$23)
           -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$23(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$31
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$23])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (and(gt($$21, 499), lt($$21, 99999)))
                         -- STREAM_SELECT  |PARTITIONED|
+                          project ([$$23, $$21])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$23, $$21] <- [$$t.getField("c_x"), $$t.getField("c_i8")]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$t])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                                  unnest-map [$$22, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$28, 1, $$28, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$28)
                                       -- STABLE_SORT [$$28(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$28])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- BTREE_SEARCH (test.TestOpen.idx_i8)  |PARTITIONED|
+                                              unnest-map [$$27, $$28] <- index-search("idx_i8", 0, "test", "TestOpen", false, false, 1, $$25, 1, $$26, true, true, false)
+                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  assign [$$25, $$26] <- [127, 127]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$31] <- [agg-range-map($$29, $$30)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$29, $$30] <- [agg-local-sampling($$23), agg-null-writer($$23)]
                       -- AGGREGATE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$23])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                select (and(gt($$21, 499), lt($$21, 99999)))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  project ([$$23, $$21])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$23, $$21] <- [$$t.getField("c_x"), $$t.getField("c_i8")]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$t])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+                                          unnest-map [$$22, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$28, 1, $$28, true, true, true)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              order (ASC, $$28)
                                               -- STABLE_SORT [$$28(ASC)]  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  project ([$$28])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- BTREE_SEARCH (test.TestOpen.idx_i8)  |PARTITIONED|
+                                                      unnest-map [$$27, $$28] <- index-search("idx_i8", 0, "test", "TestOpen", false, false, 1, $$25, 1, $$26, true, true, false)
+                                                      -- BTREE_SEARCH  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          assign [$$25, $$26] <- [127, 127]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/orderby-desc-using-gby_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/orderby-desc-using-gby_ps.plan
index cb25666..c857f5e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/orderby-desc-using-gby_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/orderby-desc-using-gby_ps.plan
@@ -1,44 +1,82 @@
+distribute result [$$46]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$46])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$46] <- [{"name": $$name, "age": $$age}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (DESC, $$name) (ASC, $$age)
           -- STABLE_SORT [$$name(DESC), $$age(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$name(DESC), $$age(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$53
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- SORT_GROUP_BY[$$47, $$48]  |PARTITIONED|
-                              {
+                      group by ([$$name := $$47; $$age := $$48]) decor ([]) {
+                                aggregate [] <- []
                                 -- AGGREGATE  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- SORT_GROUP_BY[$$47, $$48]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$47, $$48]  |PARTITIONED|
+                          project ([$$47, $$48])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$48, $$47] <- [$$c.getField(2), $$c.getField(1)]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$c])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (`gby-using-orderby-desc`.Customers)  |PARTITIONED|
+                                  data-scan []<-[$$49, $$c] <- `gby-using-orderby-desc`.Customers
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$53] <- [agg-range-map($$50, $$51, $$52)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$50, $$51, $$52] <- [agg-local-sampling($$name, $$age), agg-null-writer($$name), agg-null-writer($$age)]
                       -- AGGREGATE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- SORT_GROUP_BY[$$47, $$48]  |PARTITIONED|
-                                      {
+                              group by ([$$name := $$47; $$age := $$48]) decor ([]) {
+                                        aggregate [] <- []
                                         -- AGGREGATE  |LOCAL|
+                                          nested tuple source
                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                      }
+                                     }
+                              -- SORT_GROUP_BY[$$47, $$48]  |PARTITIONED|
+                                exchange
                                 -- HASH_PARTITION_EXCHANGE [$$47, $$48]  |PARTITIONED|
+                                  project ([$$47, $$48])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$48, $$47] <- [$$c.getField(2), $$c.getField(1)]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$c])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (`gby-using-orderby-desc`.Customers)  |PARTITIONED|
+                                          data-scan []<-[$$49, $$c] <- `gby-using-orderby-desc`.Customers
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/orderby-nulls-first-last.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/orderby-nulls-first-last.plan
index fe5e86f..b610831 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/orderby-nulls-first-last.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/orderby-nulls-first-last.plan
@@ -1,13 +1,26 @@
+distribute result [$$d]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$d])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- SORT_MERGE_EXCHANGE [$$14(ASC), $$17(ASC), $$15(DESC), $$18(DESC) ]  |PARTITIONED|
+        order (ASC, $$14) (ASC, $$17) (DESC, $$15) (DESC, $$18)
         -- STABLE_SORT [$$14(ASC), $$17(ASC), $$15(DESC), $$18(DESC)]  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            assign [$$15, $$14] <- [is-unknown($$18), is-unknown($$17)]
             -- ASSIGN  |PARTITIONED|
+              assign [$$18, $$17] <- [$$d.getField("b"), $$d.getField("a")]
               -- ASSIGN  |PARTITIONED|
+                project ([$$d])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- DATASOURCE_SCAN (test.data)  |PARTITIONED|
+                    data-scan []<-[$$16, $$d] <- test.data
+                    -- DATASOURCE_SCAN  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                        empty-tuple-source
+                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive-open_01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive-open_01.plan
index eed20bb..ef5b9c6 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive-open_01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive-open_01.plan
@@ -1,32 +1,38 @@
--- SINK  |PARTITIONED|
-  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- STREAM_PROJECT  |PARTITIONED|
-      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-        -- BULKLOAD  |PARTITIONED|
-          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- STABLE_SORT [$$2(ASC)]  |PARTITIONED|
-              -- HASH_PARTITION_EXCHANGE [$$2]  |PARTITIONED|
-                -- ASSIGN  |PARTITIONED|
-                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- DATASOURCE_SCAN (loadable_dv.loadable_ds)  |PARTITIONED|
-                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+distribute result [$$20]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$20])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$20] <- [{"o_orderkey": $$23, "o_custkey": $$22}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+          project ([$$23, $$22])
           -- STREAM_PROJECT  |PARTITIONED|
+            select (and(gt($$o.getField(3), 150000.0), eq($$22, 40)))
             -- STREAM_SELECT  |PARTITIONED|
+              assign [$$22] <- [$$o.getField(1)]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (tpch.Orders.Orders)  |PARTITIONED|
+                  unnest-map [$$23, $$o] <- index-search("Orders", 0, "tpch", "Orders", false, false, 1, $$30, 1, $$30, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$30)
                       -- STABLE_SORT [$$30(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$30])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (tpch.Orders.idx_Orders_Custkey)  |PARTITIONED|
+                              unnest-map [$$29, $$30] <- index-search("idx_Orders_Custkey", 0, "tpch", "Orders", false, false, 1, $$27, 1, $$28, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$27, $$28] <- [40, 40]
                                   -- ASSIGN  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive-open_01_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive-open_01_ps.plan
index 61cf933..31c65bb 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive-open_01_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive-open_01_ps.plan
@@ -1,60 +1,94 @@
--- SINK  |PARTITIONED|
-  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- STREAM_PROJECT  |PARTITIONED|
-      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-        -- BULKLOAD  |PARTITIONED|
-          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- STABLE_SORT [$$2(ASC)]  |PARTITIONED|
-              -- HASH_PARTITION_EXCHANGE [$$2]  |PARTITIONED|
-                -- ASSIGN  |PARTITIONED|
-                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- DATASOURCE_SCAN (loadable_dv.loadable_ds)  |PARTITIONED|
-                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+distribute result [$$20]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$20])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$20] <- [{"o_orderkey": $$23, "o_custkey": $$22}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$23)
           -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$23(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$33
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$23, $$22])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (and(gt($$o.getField(3), 150000.0), eq($$22, 40)))
                         -- STREAM_SELECT  |PARTITIONED|
+                          assign [$$22] <- [$$o.getField(1)]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (tpch.Orders.Orders)  |PARTITIONED|
+                              unnest-map [$$23, $$o] <- index-search("Orders", 0, "tpch", "Orders", false, false, 1, $$30, 1, $$30, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  order (ASC, $$30)
                                   -- STABLE_SORT [$$30(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$30])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (tpch.Orders.idx_Orders_Custkey)  |PARTITIONED|
+                                          unnest-map [$$29, $$30] <- index-search("idx_Orders_Custkey", 0, "tpch", "Orders", false, false, 1, $$27, 1, $$28, true, true, true)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$27, $$28] <- [40, 40]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$33] <- [agg-range-map($$31, $$32)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$31, $$32] <- [agg-local-sampling($$23), agg-null-writer($$23)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$23])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$23, $$22])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  select (and(gt($$o.getField(3), 150000.0), eq($$22, 40)))
                                   -- STREAM_SELECT  |PARTITIONED|
+                                    assign [$$22] <- [$$o.getField(1)]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (tpch.Orders.Orders)  |PARTITIONED|
+                                        unnest-map [$$23, $$o] <- index-search("Orders", 0, "tpch", "Orders", false, false, 1, $$30, 1, $$30, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            order (ASC, $$30)
                                             -- STABLE_SORT [$$30(ASC)]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$30])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (tpch.Orders.idx_Orders_Custkey)  |PARTITIONED|
+                                                    unnest-map [$$29, $$30] <- index-search("idx_Orders_Custkey", 0, "tpch", "Orders", false, false, 1, $$27, 1, $$28, true, true, true)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        assign [$$27, $$28] <- [40, 40]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive-open_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive-open_02.plan
index 80fa709..48f6cd6 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive-open_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive-open_02.plan
@@ -1,32 +1,38 @@
--- SINK  |PARTITIONED|
-  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- STREAM_PROJECT  |PARTITIONED|
-      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-        -- BULKLOAD  |PARTITIONED|
-          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- STABLE_SORT [$$2(ASC)]  |PARTITIONED|
-              -- HASH_PARTITION_EXCHANGE [$$2]  |PARTITIONED|
-                -- ASSIGN  |PARTITIONED|
-                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- DATASOURCE_SCAN (loadable_dv.loadable_ds)  |PARTITIONED|
-                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+distribute result [$$21]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$21])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$21] <- [{"o_orderkey": $$25, "o_custkey": $$23, "o_totalprice": $$24}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$25(ASC) ]  |PARTITIONED|
+          select (and(gt($$24, 150000.0), eq($$23, 40)))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$25, $$23, $$24])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$23, $$24] <- [$$o.getField(1), $$o.getField(3)]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (tpch.Orders.Orders)  |PARTITIONED|
+                  unnest-map [$$25, $$o] <- index-search("Orders", 0, "tpch", "Orders", false, false, 1, $$31, 1, $$31, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$31)
                       -- STABLE_SORT [$$31(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$31])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (tpch.Orders.idx_Orders_Custkey)  |PARTITIONED|
+                              unnest-map [$$30, $$31] <- index-search("idx_Orders_Custkey", 0, "tpch", "Orders", false, false, 1, $$28, 1, $$29, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$28, $$29] <- [40, 40]
                                   -- ASSIGN  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive-open_02_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive-open_02_ps.plan
index 159cc10..6eb16fb 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive-open_02_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive-open_02_ps.plan
@@ -1,60 +1,94 @@
--- SINK  |PARTITIONED|
-  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- STREAM_PROJECT  |PARTITIONED|
-      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-        -- BULKLOAD  |PARTITIONED|
-          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- STABLE_SORT [$$2(ASC)]  |PARTITIONED|
-              -- HASH_PARTITION_EXCHANGE [$$2]  |PARTITIONED|
-                -- ASSIGN  |PARTITIONED|
-                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- DATASOURCE_SCAN (loadable_dv.loadable_ds)  |PARTITIONED|
-                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+distribute result [$$21]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$21])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$21] <- [{"o_orderkey": $$25, "o_custkey": $$23, "o_totalprice": $$24}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$25)
           -- STABLE_SORT [$$25(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$25(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$34
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      select (and(gt($$24, 150000.0), eq($$23, 40)))
                       -- STREAM_SELECT  |PARTITIONED|
+                        project ([$$25, $$23, $$24])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$23, $$24] <- [$$o.getField(1), $$o.getField(3)]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (tpch.Orders.Orders)  |PARTITIONED|
+                              unnest-map [$$25, $$o] <- index-search("Orders", 0, "tpch", "Orders", false, false, 1, $$31, 1, $$31, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  order (ASC, $$31)
                                   -- STABLE_SORT [$$31(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$31])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (tpch.Orders.idx_Orders_Custkey)  |PARTITIONED|
+                                          unnest-map [$$30, $$31] <- index-search("idx_Orders_Custkey", 0, "tpch", "Orders", false, false, 1, $$28, 1, $$29, true, true, true)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$28, $$29] <- [40, 40]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$34] <- [agg-range-map($$32, $$33)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$32, $$33] <- [agg-local-sampling($$25), agg-null-writer($$25)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$25])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                select (and(gt($$24, 150000.0), eq($$23, 40)))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  project ([$$25, $$23, $$24])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$23, $$24] <- [$$o.getField(1), $$o.getField(3)]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (tpch.Orders.Orders)  |PARTITIONED|
+                                        unnest-map [$$25, $$o] <- index-search("Orders", 0, "tpch", "Orders", false, false, 1, $$31, 1, $$31, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            order (ASC, $$31)
                                             -- STABLE_SORT [$$31(ASC)]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$31])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (tpch.Orders.idx_Orders_Custkey)  |PARTITIONED|
+                                                    unnest-map [$$30, $$31] <- index-search("idx_Orders_Custkey", 0, "tpch", "Orders", false, false, 1, $$28, 1, $$29, true, true, true)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        assign [$$28, $$29] <- [40, 40]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive_01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive_01.plan
index eed20bb..ef5b9c6 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive_01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive_01.plan
@@ -1,32 +1,38 @@
--- SINK  |PARTITIONED|
-  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- STREAM_PROJECT  |PARTITIONED|
-      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-        -- BULKLOAD  |PARTITIONED|
-          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- STABLE_SORT [$$2(ASC)]  |PARTITIONED|
-              -- HASH_PARTITION_EXCHANGE [$$2]  |PARTITIONED|
-                -- ASSIGN  |PARTITIONED|
-                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- DATASOURCE_SCAN (loadable_dv.loadable_ds)  |PARTITIONED|
-                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+distribute result [$$20]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$20])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$20] <- [{"o_orderkey": $$23, "o_custkey": $$22}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+          project ([$$23, $$22])
           -- STREAM_PROJECT  |PARTITIONED|
+            select (and(gt($$o.getField(3), 150000.0), eq($$22, 40)))
             -- STREAM_SELECT  |PARTITIONED|
+              assign [$$22] <- [$$o.getField(1)]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (tpch.Orders.Orders)  |PARTITIONED|
+                  unnest-map [$$23, $$o] <- index-search("Orders", 0, "tpch", "Orders", false, false, 1, $$30, 1, $$30, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$30)
                       -- STABLE_SORT [$$30(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$30])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (tpch.Orders.idx_Orders_Custkey)  |PARTITIONED|
+                              unnest-map [$$29, $$30] <- index-search("idx_Orders_Custkey", 0, "tpch", "Orders", false, false, 1, $$27, 1, $$28, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$27, $$28] <- [40, 40]
                                   -- ASSIGN  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive_01_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive_01_ps.plan
index 61cf933..31c65bb 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive_01_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive_01_ps.plan
@@ -1,60 +1,94 @@
--- SINK  |PARTITIONED|
-  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- STREAM_PROJECT  |PARTITIONED|
-      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-        -- BULKLOAD  |PARTITIONED|
-          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- STABLE_SORT [$$2(ASC)]  |PARTITIONED|
-              -- HASH_PARTITION_EXCHANGE [$$2]  |PARTITIONED|
-                -- ASSIGN  |PARTITIONED|
-                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- DATASOURCE_SCAN (loadable_dv.loadable_ds)  |PARTITIONED|
-                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+distribute result [$$20]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$20])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$20] <- [{"o_orderkey": $$23, "o_custkey": $$22}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$23)
           -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$23(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$33
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$23, $$22])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (and(gt($$o.getField(3), 150000.0), eq($$22, 40)))
                         -- STREAM_SELECT  |PARTITIONED|
+                          assign [$$22] <- [$$o.getField(1)]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (tpch.Orders.Orders)  |PARTITIONED|
+                              unnest-map [$$23, $$o] <- index-search("Orders", 0, "tpch", "Orders", false, false, 1, $$30, 1, $$30, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  order (ASC, $$30)
                                   -- STABLE_SORT [$$30(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$30])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (tpch.Orders.idx_Orders_Custkey)  |PARTITIONED|
+                                          unnest-map [$$29, $$30] <- index-search("idx_Orders_Custkey", 0, "tpch", "Orders", false, false, 1, $$27, 1, $$28, true, true, true)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$27, $$28] <- [40, 40]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$33] <- [agg-range-map($$31, $$32)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$31, $$32] <- [agg-local-sampling($$23), agg-null-writer($$23)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$23])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$23, $$22])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  select (and(gt($$o.getField(3), 150000.0), eq($$22, 40)))
                                   -- STREAM_SELECT  |PARTITIONED|
+                                    assign [$$22] <- [$$o.getField(1)]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (tpch.Orders.Orders)  |PARTITIONED|
+                                        unnest-map [$$23, $$o] <- index-search("Orders", 0, "tpch", "Orders", false, false, 1, $$30, 1, $$30, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            order (ASC, $$30)
                                             -- STABLE_SORT [$$30(ASC)]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$30])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (tpch.Orders.idx_Orders_Custkey)  |PARTITIONED|
+                                                    unnest-map [$$29, $$30] <- index-search("idx_Orders_Custkey", 0, "tpch", "Orders", false, false, 1, $$27, 1, $$28, true, true, true)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        assign [$$27, $$28] <- [40, 40]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive_02.plan
index 80fa709..48f6cd6 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive_02.plan
@@ -1,32 +1,38 @@
--- SINK  |PARTITIONED|
-  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- STREAM_PROJECT  |PARTITIONED|
-      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-        -- BULKLOAD  |PARTITIONED|
-          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- STABLE_SORT [$$2(ASC)]  |PARTITIONED|
-              -- HASH_PARTITION_EXCHANGE [$$2]  |PARTITIONED|
-                -- ASSIGN  |PARTITIONED|
-                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- DATASOURCE_SCAN (loadable_dv.loadable_ds)  |PARTITIONED|
-                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+distribute result [$$21]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$21])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$21] <- [{"o_orderkey": $$25, "o_custkey": $$23, "o_totalprice": $$24}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$25(ASC) ]  |PARTITIONED|
+          select (and(gt($$24, 150000.0), eq($$23, 40)))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$25, $$23, $$24])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$23, $$24] <- [$$o.getField(1), $$o.getField(3)]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (tpch.Orders.Orders)  |PARTITIONED|
+                  unnest-map [$$25, $$o] <- index-search("Orders", 0, "tpch", "Orders", false, false, 1, $$31, 1, $$31, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$31)
                       -- STABLE_SORT [$$31(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$31])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (tpch.Orders.idx_Orders_Custkey)  |PARTITIONED|
+                              unnest-map [$$30, $$31] <- index-search("idx_Orders_Custkey", 0, "tpch", "Orders", false, false, 1, $$28, 1, $$29, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$28, $$29] <- [40, 40]
                                   -- ASSIGN  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive_02_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive_02_ps.plan
index 159cc10..6eb16fb 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive_02_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive_02_ps.plan
@@ -1,60 +1,94 @@
--- SINK  |PARTITIONED|
-  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- STREAM_PROJECT  |PARTITIONED|
-      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-        -- BULKLOAD  |PARTITIONED|
-          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- STABLE_SORT [$$2(ASC)]  |PARTITIONED|
-              -- HASH_PARTITION_EXCHANGE [$$2]  |PARTITIONED|
-                -- ASSIGN  |PARTITIONED|
-                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- DATASOURCE_SCAN (loadable_dv.loadable_ds)  |PARTITIONED|
-                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+distribute result [$$21]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$21])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$21] <- [{"o_orderkey": $$25, "o_custkey": $$23, "o_totalprice": $$24}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$25)
           -- STABLE_SORT [$$25(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$25(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$34
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      select (and(gt($$24, 150000.0), eq($$23, 40)))
                       -- STREAM_SELECT  |PARTITIONED|
+                        project ([$$25, $$23, $$24])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$23, $$24] <- [$$o.getField(1), $$o.getField(3)]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (tpch.Orders.Orders)  |PARTITIONED|
+                              unnest-map [$$25, $$o] <- index-search("Orders", 0, "tpch", "Orders", false, false, 1, $$31, 1, $$31, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  order (ASC, $$31)
                                   -- STABLE_SORT [$$31(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$31])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (tpch.Orders.idx_Orders_Custkey)  |PARTITIONED|
+                                          unnest-map [$$30, $$31] <- index-search("idx_Orders_Custkey", 0, "tpch", "Orders", false, false, 1, $$28, 1, $$29, true, true, true)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$28, $$29] <- [40, 40]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$34] <- [agg-range-map($$32, $$33)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$32, $$33] <- [agg-local-sampling($$25), agg-null-writer($$25)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$25])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                select (and(gt($$24, 150000.0), eq($$23, 40)))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  project ([$$25, $$23, $$24])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$23, $$24] <- [$$o.getField(1), $$o.getField(3)]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (tpch.Orders.Orders)  |PARTITIONED|
+                                        unnest-map [$$25, $$o] <- index-search("Orders", 0, "tpch", "Orders", false, false, 1, $$31, 1, $$31, true, true, true)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            order (ASC, $$31)
                                             -- STABLE_SORT [$$31(ASC)]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$31])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (tpch.Orders.idx_Orders_Custkey)  |PARTITIONED|
+                                                    unnest-map [$$30, $$31] <- index-search("idx_Orders_Custkey", 0, "tpch", "Orders", false, false, 1, $$28, 1, $$29, true, true, true)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        assign [$$28, $$29] <- [40, 40]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/p_sort_join/p_sort_join.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/p_sort_join/p_sort_join.plan
index 0ea33f1..89c5b8f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/p_sort_join/p_sort_join.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/p_sort_join/p_sort_join.plan
@@ -1,76 +1,146 @@
+distribute result [$$81]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$81])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$81] <- [{"id2": $$id2}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$id2)
           -- STABLE_SORT [$$id2(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$id2(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$95
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- SORT_GROUP_BY[$$87]  |PARTITIONED|
-                              {
+                      group by ([$$id2 := $$87]) decor ([]) {
+                                aggregate [] <- []
                                 -- AGGREGATE  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- SORT_GROUP_BY[$$87]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$87])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              join (eq($$87, $$90))
                               -- HYBRID_HASH_JOIN [$$87][$$90]  |PARTITIONED|
+                                exchange
                                 -- HASH_PARTITION_EXCHANGE [$$87]  |PARTITIONED|
+                                  order (ASC, $$87)
                                   -- STABLE_SORT [$$87(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- RANGE_PARTITION_EXCHANGE [$$87(ASC)] RANGE_MAP:{SPLIT:1}  |PARTITIONED|
+                                      project ([$$87])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$87] <- [$$TestDS1.getField(1)]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$TestDS1])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.TestDS1)  |PARTITIONED|
+                                              data-scan []<-[$$84, $$TestDS1] <- test.TestDS1
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                exchange
                                 -- HASH_PARTITION_EXCHANGE [$$90]  |PARTITIONED|
+                                  order (ASC, $$90)
                                   -- STABLE_SORT [$$90(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- RANGE_PARTITION_EXCHANGE [$$90(ASC)] RANGE_MAP:{SPLIT:1}  |PARTITIONED|
+                                      project ([$$90])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$90] <- [$$TestDS2.getField(1)]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$TestDS2])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.TestDS2)  |PARTITIONED|
+                                              data-scan []<-[$$85, $$TestDS2] <- test.TestDS2
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$95] <- [agg-range-map($$93, $$94)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$93, $$94] <- [agg-local-sampling($$id2), agg-null-writer($$id2)]
                       -- AGGREGATE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- SORT_GROUP_BY[$$87]  |PARTITIONED|
-                                      {
+                              group by ([$$id2 := $$87]) decor ([]) {
+                                        aggregate [] <- []
                                         -- AGGREGATE  |LOCAL|
+                                          nested tuple source
                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                      }
+                                     }
+                              -- SORT_GROUP_BY[$$87]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$87])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      join (eq($$87, $$90))
                                       -- HYBRID_HASH_JOIN [$$87][$$90]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$87]  |PARTITIONED|
+                                          order (ASC, $$87)
                                           -- STABLE_SORT [$$87(ASC)]  |PARTITIONED|
+                                            exchange
                                             -- RANGE_PARTITION_EXCHANGE [$$87(ASC)] RANGE_MAP:{SPLIT:1}  |PARTITIONED|
+                                              project ([$$87])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$87] <- [$$TestDS1.getField(1)]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  project ([$$TestDS1])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.TestDS1)  |PARTITIONED|
+                                                      data-scan []<-[$$84, $$TestDS1] <- test.TestDS1
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$90]  |PARTITIONED|
+                                          order (ASC, $$90)
                                           -- STABLE_SORT [$$90(ASC)]  |PARTITIONED|
+                                            exchange
                                             -- RANGE_PARTITION_EXCHANGE [$$90(ASC)] RANGE_MAP:{SPLIT:1}  |PARTITIONED|
+                                              project ([$$90])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$90] <- [$$TestDS2.getField(1)]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  project ([$$TestDS2])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.TestDS2)  |PARTITIONED|
+                                                      data-scan []<-[$$85, $$TestDS2] <- test.TestDS2
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/p_sort_seq_merge/p_sort_seq_merge.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/p_sort_seq_merge/p_sort_seq_merge.plan
index c91f5f6..509ac1a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/p_sort_seq_merge/p_sort_seq_merge.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/p_sort_seq_merge/p_sort_seq_merge.plan
@@ -1,34 +1,68 @@
+distribute result [$$11]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$11])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$11] <- [ordered-list-constructor($$18)]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$18] <- [listify($$15)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- SEQUENTIAL_MERGE_EXCHANGE  |PARTITIONED|
+            project ([$$15])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$15] <- [{"v": $$v}]
               -- ASSIGN  |PARTITIONED|
+                project ([$$v])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    order (ASC, $$20) (ASC, $$19)
                     -- STABLE_SORT [$$20(ASC), $$19(ASC)]  |PARTITIONED|
+                      exchange
                       -- RANGE_PARTITION_EXCHANGE [$$20(ASC), $$19(ASC)]  |PARTITIONED|
+                        forward: shared-variable = $$25
                         -- FORWARD  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                assign [$$20] <- [$$v.getField(1)]
                                 -- ASSIGN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (test.TestDS)  |PARTITIONED|
+                                    data-scan []<-[$$19, $$v] <- test.TestDS
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                            aggregate [$$25] <- [agg-range-map($$22, $$23, $$24)]
                             -- AGGREGATE  |UNPARTITIONED|
+                              exchange
                               -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                                aggregate [$$22, $$23, $$24] <- [agg-local-sampling($$20, $$19), agg-null-writer($$20), agg-null-writer($$19)]
                                 -- AGGREGATE  |PARTITIONED|
+                                  project ([$$20, $$19])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      replicate
                                       -- REPLICATE  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          assign [$$20] <- [$$v.getField(1)]
                                           -- ASSIGN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.TestDS)  |PARTITIONED|
+                                              data-scan []<-[$$19, $$v] <- test.TestDS
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/parallel_sort_enabled_disabled/parallel_sort_enabled_disabled.1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/parallel_sort_enabled_disabled/parallel_sort_enabled_disabled.1.plan
index a6bb323..1de42e6 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/parallel_sort_enabled_disabled/parallel_sort_enabled_disabled.1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/parallel_sort_enabled_disabled/parallel_sort_enabled_disabled.1.plan
@@ -1,30 +1,60 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$c])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$14)
         -- STABLE_SORT [$$14(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$14(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$17
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    assign [$$14] <- [$$c.getField(1)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$c])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                          data-scan []<-[$$13, $$c] <- test.Customers
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$17] <- [agg-range-map($$15, $$16)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$15, $$16] <- [agg-local-sampling($$14), agg-null-writer($$14)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$14])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              assign [$$14] <- [$$c.getField(1)]
                               -- ASSIGN  |PARTITIONED|
+                                project ([$$c])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                    data-scan []<-[$$13, $$c] <- test.Customers
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/parallel_sort_enabled_disabled/parallel_sort_enabled_disabled.2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/parallel_sort_enabled_disabled/parallel_sort_enabled_disabled.2.plan
index 3dfb1a0..87e3e0d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/parallel_sort_enabled_disabled/parallel_sort_enabled_disabled.2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/parallel_sort_enabled_disabled/parallel_sort_enabled_disabled.2.plan
@@ -1,12 +1,24 @@
+distribute result [$$c]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$c])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- SORT_MERGE_EXCHANGE [$$14(ASC) ]  |PARTITIONED|
+        order (ASC, $$14)
         -- STABLE_SORT [$$14(ASC)]  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            assign [$$14] <- [$$c.getField(1)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$c])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                  data-scan []<-[$$13, $$c] <- test.Customers
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/primary-key-index/delete-primary-key-index-with-secondary.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/primary-key-index/delete-primary-key-index-with-secondary.plan
index 6c4ca95..0bdc6bf 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/primary-key-index/delete-primary-key-index-with-secondary.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/primary-key-index/delete-primary-key-index-with-secondary.plan
@@ -1,20 +1,40 @@
+commit
 -- COMMIT  |PARTITIONED|
+  project ([$$15])
   -- STREAM_PROJECT  |PARTITIONED|
+    exchange
     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+      delete from titleIndex on test.DBLP from [$$21]
       -- INDEX_INSERT_DELETE  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          delete from pkIndex on test.DBLP from []
           -- INDEX_INSERT_DELETE  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$21, $$15])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  delete from test.DBLP from record: $$DBLP partitioned by [$$15]
                   -- INSERT_DELETE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      materialize
                       -- MATERIALIZE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$21, $$15] <- [$$DBLP.getField(2), $$DBLP.getField(0)]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$DBLP])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- BTREE_SEARCH (test.DBLP.DBLP)  |PARTITIONED|
+                                unnest-map [$$16, $$DBLP] <- index-search("DBLP", 0, "test", "DBLP", false, false, 1, $$18, 0, false, true, false)
+                                -- BTREE_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    assign [$$18] <- [10]
                                     -- ASSIGN  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/primary-key-index/insert-and-scan-primary-key-index-with-secondary.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/primary-key-index/insert-and-scan-primary-key-index-with-secondary.plan
index 04583cd..3239b96 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/primary-key-index/insert-and-scan-primary-key-index-with-secondary.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/primary-key-index/insert-and-scan-primary-key-index-with-secondary.plan
@@ -1,19 +1,38 @@
+commit
 -- COMMIT  |PARTITIONED|
+  project ([$$16])
   -- STREAM_PROJECT  |PARTITIONED|
+    exchange
     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+      insert into nameIndex on test.myData from [$$20]
       -- INDEX_INSERT_DELETE  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          project ([$$20, $$16])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              insert into test.myData from record: $$17 partitioned by [$$16]
               -- INSERT_DELETE  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  materialize
                   -- MATERIALIZE  |PARTITIONED|
+                    exchange
                     -- HASH_PARTITION_EXCHANGE [$$16]  |PARTITIONED|
+                      assign [$$20, $$16] <- [$$17.getField(1), $$17.getField(0)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$17])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$17] <- [cast({"id": numeric-add($$18, 1)})]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$18])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.myData)  |PARTITIONED|
+                                data-scan []<-[$$18, $$x] <- test.myData
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/primary-key-index/insert-primary-key-index-with-auto-gen-pk.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/primary-key-index/insert-primary-key-index-with-auto-gen-pk.plan
index 9a296a5..fc84e30 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/primary-key-index/insert-primary-key-index-with-auto-gen-pk.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/primary-key-index/insert-primary-key-index-with-auto-gen-pk.plan
@@ -1,10 +1,20 @@
+commit
 -- COMMIT  |PARTITIONED|
+  project ([$$3])
   -- STREAM_PROJECT  |PARTITIONED|
+    exchange
     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+      insert into test.DBLP from record: $$5 partitioned by [$$3]
       -- INSERT_DELETE  |PARTITIONED|
+        exchange
         -- HASH_PARTITION_EXCHANGE [$$3]  |PARTITIONED|
+          assign [$$3] <- [$$5.getField(0)]
           -- ASSIGN  |UNPARTITIONED|
+            project ([$$5])
             -- STREAM_PROJECT  |UNPARTITIONED|
+              assign [$$5] <- [cast(check-unknown(object-merge-ignore-duplicates($$1, {"id": create-uuid()})))]
               -- ASSIGN  |UNPARTITIONED|
+                assign [$$1] <- [{ "dblpid": "books/acm/kim95/Blakeley95", "title": "OQL[C++]  Extending C++ with an Object Query Capability.", "authors": "José A. Blakeley", "misc": "2002-01-03 69-88 Modern Database Systems db/books/collections/kim95.html#Blakeley95 1995" }]
                 -- ASSIGN  |UNPARTITIONED|
+                  empty-tuple-source
                   -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/primary-key-index/insert-primary-key-index.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/primary-key-index/insert-primary-key-index.plan
index 2c493d3..bafd5ed 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/primary-key-index/insert-primary-key-index.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/primary-key-index/insert-primary-key-index.plan
@@ -1,8 +1,16 @@
+commit
 -- COMMIT  |PARTITIONED|
+  project ([$$3])
   -- STREAM_PROJECT  |PARTITIONED|
+    exchange
     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+      insert into test.DBLP from record: $$1 partitioned by [$$3]
       -- INSERT_DELETE  |PARTITIONED|
+        exchange
         -- HASH_PARTITION_EXCHANGE [$$3]  |PARTITIONED|
+          assign [$$3] <- [1]
           -- ASSIGN  |UNPARTITIONED|
+            assign [$$1] <- [{ "id": 1, "dblpid": "books/acm/kim95/Blakeley95", "title": "OQL[C++]  Extending C++ with an Object Query Capability.", "authors": "José A. Blakeley", "misc": "2002-01-03 69-88 Modern Database Systems db/books/collections/kim95.html#Blakeley95 1995" }]
             -- ASSIGN  |UNPARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/primary-key-index/load-primary-key-index-with-secondary.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/primary-key-index/load-primary-key-index-with-secondary.plan
index 689fae14..5159646 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/primary-key-index/load-primary-key-index-with-secondary.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/primary-key-index/load-primary-key-index-with-secondary.plan
@@ -1,67 +1,134 @@
+sink
 -- SINK  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        insert into kwds_index on test.MyData from [$$3] [bulkload]
         -- INDEX_BULKLOAD  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            order (ASC, $$3) (ASC, $$2)
             -- STABLE_SORT [$$3(ASC), $$2(ASC)]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$3, $$2])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$3, $$4, $$2])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            insert into test.MyData from record: $$1 partitioned by [$$2] [bulkload]
                             -- BULKLOAD  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$2)
                                 -- STABLE_SORT [$$2(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- HASH_PARTITION_EXCHANGE [$$2]  |PARTITIONED|
+                                    assign [$$3, $$4, $$2] <- [$$1.getField(2), $$1.getField(1), $$1.getField(0)]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (loadable_dv.loadable_ds)  |PARTITIONED|
+                                        data-scan []<-[$$1] <- loadable_dv.loadable_ds
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        insert into pkIndex on test.MyData from [] [bulkload]
         -- INDEX_BULKLOAD  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            project ([$$2])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$3, $$4, $$2])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        insert into test.MyData from record: $$1 partitioned by [$$2] [bulkload]
                         -- BULKLOAD  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            order (ASC, $$2)
                             -- STABLE_SORT [$$2(ASC)]  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$2]  |PARTITIONED|
+                                assign [$$3, $$4, $$2] <- [$$1.getField(2), $$1.getField(1), $$1.getField(0)]
                                 -- ASSIGN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (loadable_dv.loadable_ds)  |PARTITIONED|
+                                    data-scan []<-[$$1] <- loadable_dv.loadable_ds
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        insert into rtree_index_point on test.MyData from [$$5, $$6, $$5, $$6] [bulkload]
         -- INDEX_BULKLOAD  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            order (ASC, $$5) (ASC, $$6) (ASC, $$2)
             -- STABLE_SORT [$$5(ASC), $$6(ASC), $$2(ASC)]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$2, $$5, $$6])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$5, $$6] <- [create-mbr($$4, 2, 0), create-mbr($$4, 2, 1)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$4, $$2])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        replicate
                         -- REPLICATE  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$3, $$4, $$2])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                insert into test.MyData from record: $$1 partitioned by [$$2] [bulkload]
                                 -- BULKLOAD  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$2)
                                     -- STABLE_SORT [$$2(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$2]  |PARTITIONED|
+                                        assign [$$3, $$4, $$2] <- [$$1.getField(2), $$1.getField(1), $$1.getField(0)]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (loadable_dv.loadable_ds)  |PARTITIONED|
+                                            data-scan []<-[$$1] <- loadable_dv.loadable_ds
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/primary-key-index/load-primary-key-index.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/primary-key-index/load-primary-key-index.plan
index 3f0b903..9db29bf 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/primary-key-index/load-primary-key-index.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/primary-key-index/load-primary-key-index.plan
@@ -1,17 +1,34 @@
+sink
 -- SINK  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        insert into pkIndex on test.MyData from [] [bulkload]
         -- INDEX_BULKLOAD  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            project ([$$2])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                insert into test.MyData from record: $$1 partitioned by [$$2] [bulkload]
                 -- BULKLOAD  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    order (ASC, $$2)
                     -- STABLE_SORT [$$2(ASC)]  |PARTITIONED|
+                      exchange
                       -- HASH_PARTITION_EXCHANGE [$$2]  |PARTITIONED|
+                        assign [$$2] <- [$$1.getField(0)]
                         -- ASSIGN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (loadable_dv.loadable_ds)  |PARTITIONED|
+                            data-scan []<-[$$1] <- loadable_dv.loadable_ds
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/primary-key-index/upsert-primary-key-index-with-secondary.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/primary-key-index/upsert-primary-key-index-with-secondary.plan
index 9ad7e30..b5938cf 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/primary-key-index/upsert-primary-key-index-with-secondary.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/primary-key-index/upsert-primary-key-index-with-secondary.plan
@@ -1,16 +1,32 @@
+commit
 -- COMMIT  |PARTITIONED|
+  project ([$$3])
   -- STREAM_PROJECT  |PARTITIONED|
+    exchange
     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+      upsert into titleIndex on test.DBLP from  replace:[$$7] with:[$$6]
       -- INDEX_INSERT_DELETE  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          upsert into pkIndex on test.DBLP from  replace:[] with:[]
           -- INDEX_INSERT_DELETE  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$4, $$6, $$3, $$7])
               -- STREAM_PROJECT  |PARTITIONED|
+                assign [$$7] <- [$$5.getField(2)]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$4, $$5, $$6, $$3])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      upsert into test.DBLP from record: $$1 partitioned by [$$3] out: ([record-before-upsert:$$5]) 
                       -- INSERT_DELETE  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$3]  |PARTITIONED|
+                          assign [$$6, $$3] <- [$$1.getField(2), 1]
                           -- ASSIGN  |UNPARTITIONED|
+                            assign [$$1] <- [{ "id": 1, "dblpid": "books/acm/kim95/Blakeley95", "title": "OQL[C++]  Extending C++ with an Object Query Capability.", "authors": "José A. Blakeley", "misc": "2002-01-03 69-88 Modern Database Systems db/books/collections/kim95.html#Blakeley95 1995" }]
                             -- ASSIGN  |UNPARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/pull_select_above_eq_join.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/pull_select_above_eq_join.plan
index f7dc3b0..4f9e139 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/pull_select_above_eq_join.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/pull_select_above_eq_join.plan
@@ -1,23 +1,46 @@
+distribute result [$$33]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$33])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$33] <- [{"uid": $$34, "vid": $$35}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$34, $$35])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (neq($$36, $$37))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$34, $$36, $$35, $$37])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                join (eq($$38, $$39))
                 -- HYBRID_HASH_JOIN [$$38][$$39]  |PARTITIONED|
+                  exchange
                   -- HASH_PARTITION_EXCHANGE [$$38]  |PARTITIONED|
+                    project ([$$34, $$36, $$38])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$38, $$36] <- [$$user.getField(1), $$user.getField(2)]
                       -- ASSIGN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (`pull-select-above-eq-join`.Users)  |PARTITIONED|
+                          data-scan []<-[$$34, $$user] <- `pull-select-above-eq-join`.Users
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- HASH_PARTITION_EXCHANGE [$$39]  |PARTITIONED|
+                    project ([$$35, $$37, $$39])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$39, $$37] <- [$$visitor.getField(1), $$visitor.getField(2)]
                       -- ASSIGN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (`pull-select-above-eq-join`.Visitors)  |PARTITIONED|
+                          data-scan []<-[$$35, $$visitor] <- `pull-select-above-eq-join`.Visitors
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/push-project-through-group.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/push-project-through-group.plan
index ee985d4..3ca5c69 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/push-project-through-group.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/push-project-through-group.plan
@@ -1,32 +1,61 @@
+distribute result [$$41]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$41])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$41] <- [{"id": $$48, "matches": $$38}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- PRE_CLUSTERED_GROUP_BY[$$42]  |PARTITIONED|
-                  {
+          group by ([$$48 := $$42]) decor ([]) {
+                    aggregate [$$38] <- [listify($$37)]
                     -- AGGREGATE  |LOCAL|
+                      select (not(is-missing($$47)))
                       -- STREAM_SELECT  |LOCAL|
+                        nested tuple source
                         -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- PRE_CLUSTERED_GROUP_BY[$$42]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$42)
               -- STABLE_SORT [$$42(ASC)]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$42]  |PARTITIONED|
+                  project ([$$37, $$47, $$42])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      left outer join (eq($$44, $$45))
                       -- HYBRID_HASH_JOIN [$$45][$$44]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$45]  |PARTITIONED|
+                          project ([$$42, $$45])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$45] <- [$$paperDBLP.getField(3)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (fuzzyjoin_080.DBLP)  |PARTITIONED|
+                                data-scan []<-[$$42, $$paperDBLP] <- fuzzyjoin_080.DBLP
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$44]  |PARTITIONED|
+                          project ([$$37, $$47, $$44])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$47, $$37, $$44] <- [true, $$paper.getField(2), $$paper.getField(3)]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$paper])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (fuzzyjoin_080.DBLP)  |PARTITIONED|
+                                  data-scan []<-[$$43, $$paper] <- fuzzyjoin_080.DBLP
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/q01_pricing_summary_report_nt_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/q01_pricing_summary_report_nt_ps.plan
index 0128265..c9efe66 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/q01_pricing_summary_report_nt_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/q01_pricing_summary_report_nt_ps.plan
@@ -1,74 +1,110 @@
--- SINK  |PARTITIONED|
-  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- STREAM_PROJECT  |PARTITIONED|
-      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-        -- BULKLOAD  |PARTITIONED|
-          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- STABLE_SORT [$$2(ASC), $$3(ASC)]  |PARTITIONED|
-              -- HASH_PARTITION_EXCHANGE [$$2, $$3]  |PARTITIONED|
-                -- ASSIGN  |PARTITIONED|
-                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- DATASOURCE_SCAN (loadable_dv.loadable_ds)  |PARTITIONED|
-                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+distribute result [$$180]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$180])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$180] <- [{"l_returnflag": $$l_returnflag, "l_linestatus": $$l_linestatus, "sum_qty": $$186, "sum_base_price": $$187, "sum_disc_price": $$188, "sum_charge": $$189, "ave_qty": $$190, "ave_price": $$191, "ave_disc": $$192, "count_order": $$193}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$l_returnflag) (ASC, $$l_linestatus)
           -- STABLE_SORT [$$l_returnflag(ASC), $$l_linestatus(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$l_returnflag(ASC), $$l_linestatus(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$211
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- EXTERNAL_GROUP_BY[$$206, $$207]  |PARTITIONED|
-                              {
+                      group by ([$$l_returnflag := $$206; $$l_linestatus := $$207]) decor ([]) {
+                                aggregate [$$186, $$187, $$188, $$189, $$190, $$191, $$192, $$193] <- [global-sum-serial($$198), global-sum-serial($$199), global-sum-serial($$200), global-sum-serial($$201), global-avg-serial($$202), global-avg-serial($$203), global-avg-serial($$204), sum-serial($$205)]
                                 -- AGGREGATE  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- EXTERNAL_GROUP_BY[$$206, $$207]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$206, $$207]  |PARTITIONED|
-                          -- EXTERNAL_GROUP_BY[$$181, $$182]  |PARTITIONED|
-                                  {
+                          group by ([$$206 := $$181; $$207 := $$182]) decor ([]) {
+                                    aggregate [$$198, $$199, $$200, $$201, $$202, $$203, $$204, $$205] <- [local-sum-serial($$136), local-sum-serial($$141), local-sum-serial(numeric-multiply($$141, numeric-subtract(1, $$195))), local-sum-serial(numeric-multiply(numeric-multiply($$141, numeric-subtract(1, $$195)), numeric-add(1, $$197))), local-avg-serial($$136), local-avg-serial($$141), local-avg-serial($$195), count-serial($$128)]
                                     -- AGGREGATE  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                  }
+                                 }
+                          -- EXTERNAL_GROUP_BY[$$181, $$182]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$136, $$141, $$195, $$197, $$128, $$181, $$182])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$128] <- [{"l": $$l}]
                                 -- ASSIGN  |PARTITIONED|
+                                  select (le($$l.getField(10), "1998-09-02"))
                                   -- STREAM_SELECT  |PARTITIONED|
+                                    assign [$$182, $$181, $$136, $$195, $$197, $$141] <- [$$l.getField(9), $$l.getField(8), $$l.getField(4), $$l.getField(6), $$l.getField(7), $$l.getField(5)]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$l])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
+                                          data-scan []<-[$$184, $$185, $$l] <- tpch.LineItem
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$211] <- [agg-range-map($$208, $$209, $$210)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$208, $$209, $$210] <- [agg-local-sampling($$l_returnflag, $$l_linestatus), agg-null-writer($$l_returnflag), agg-null-writer($$l_linestatus)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$l_returnflag, $$l_linestatus])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- EXTERNAL_GROUP_BY[$$206, $$207]  |PARTITIONED|
-                                        {
+                                group by ([$$l_returnflag := $$206; $$l_linestatus := $$207]) decor ([]) {
+                                          aggregate [$$186, $$187, $$188, $$189, $$190, $$191, $$192, $$193] <- [global-sum-serial($$198), global-sum-serial($$199), global-sum-serial($$200), global-sum-serial($$201), global-avg-serial($$202), global-avg-serial($$203), global-avg-serial($$204), sum-serial($$205)]
                                           -- AGGREGATE  |LOCAL|
+                                            nested tuple source
                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- EXTERNAL_GROUP_BY[$$206, $$207]  |PARTITIONED|
+                                  exchange
                                   -- HASH_PARTITION_EXCHANGE [$$206, $$207]  |PARTITIONED|
-                                    -- EXTERNAL_GROUP_BY[$$181, $$182]  |PARTITIONED|
-                                            {
+                                    group by ([$$206 := $$181; $$207 := $$182]) decor ([]) {
+                                              aggregate [$$198, $$199, $$200, $$201, $$202, $$203, $$204, $$205] <- [local-sum-serial($$136), local-sum-serial($$141), local-sum-serial(numeric-multiply($$141, numeric-subtract(1, $$195))), local-sum-serial(numeric-multiply(numeric-multiply($$141, numeric-subtract(1, $$195)), numeric-add(1, $$197))), local-avg-serial($$136), local-avg-serial($$141), local-avg-serial($$195), count-serial($$128)]
                                               -- AGGREGATE  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                            }
+                                           }
+                                    -- EXTERNAL_GROUP_BY[$$181, $$182]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$136, $$141, $$195, $$197, $$128, $$181, $$182])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$128] <- [{"l": $$l}]
                                           -- ASSIGN  |PARTITIONED|
+                                            select (le($$l.getField(10), "1998-09-02"))
                                             -- STREAM_SELECT  |PARTITIONED|
+                                              assign [$$182, $$181, $$136, $$195, $$197, $$141] <- [$$l.getField(9), $$l.getField(8), $$l.getField(4), $$l.getField(6), $$l.getField(7), $$l.getField(5)]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$l])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
+                                                    data-scan []<-[$$184, $$185, $$l] <- tpch.LineItem
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/q08_group_by.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/q08_group_by.plan
index f22ba51..0af335e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/q08_group_by.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/q08_group_by.plan
@@ -1,78 +1,156 @@
+distribute result [$$191]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$191])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$191] <- [{"o_orderdate": $$216, "l_discount": $$219, "l_extendedprice": $$220, "l_suppkey": $$221, "s_nationkey": $$230}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$230, $$216, $$219, $$220, $$221])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$193, $$221))
             -- HYBRID_HASH_JOIN [$$193][$$221]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$230, $$193])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$230] <- [$$s.getField(3)]
                   -- ASSIGN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (q08_group_by.Supplier)  |PARTITIONED|
+                      data-scan []<-[$$193, $$s] <- q08_group_by.Supplier
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$221]  |PARTITIONED|
+                project ([$$216, $$219, $$220, $$221])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    join (eq($$200, $$218))
                     -- HYBRID_HASH_JOIN [$$218][$$200]  |PARTITIONED|
+                      exchange
                       -- HASH_PARTITION_EXCHANGE [$$218]  |PARTITIONED|
+                        project ([$$216, $$219, $$220, $$221, $$218])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            join (eq($$194, $$196))
                             -- HYBRID_HASH_JOIN [$$194][$$196]  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$194]  |PARTITIONED|
+                                project ([$$219, $$220, $$221, $$218, $$194])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  assign [$$221, $$220, $$219, $$218] <- [$$l.getField(2), $$l.getField(5), $$l.getField(6), $$l.getField(1)]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$194, $$l])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (q08_group_by.LineItem)  |PARTITIONED|
+                                        data-scan []<-[$$194, $$195, $$l] <- q08_group_by.LineItem
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$196]  |PARTITIONED|
+                                project ([$$216, $$196])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    join (eq($$197, $$209))
                                     -- HYBRID_HASH_JOIN [$$209][$$197]  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$209]  |PARTITIONED|
+                                        select (and(ge($$216, "1995-01-01"), le($$216, "1996-12-31")))
                                         -- STREAM_SELECT  |PARTITIONED|
+                                          project ([$$196, $$216, $$209])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$216, $$209] <- [$$o.getField(4), $$o.getField(1)]
                                             -- ASSIGN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- DATASOURCE_SCAN (q08_group_by.Orders)  |PARTITIONED|
+                                                data-scan []<-[$$196, $$o] <- q08_group_by.Orders
+                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$197]  |PARTITIONED|
+                                        project ([$$197])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            join (eq($$206, $$198))
                                             -- HYBRID_HASH_JOIN [$$206][$$198]  |PARTITIONED|
+                                              exchange
                                               -- HASH_PARTITION_EXCHANGE [$$206]  |PARTITIONED|
+                                                project ([$$197, $$206])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$206] <- [$$c.getField(3)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (q08_group_by.Customer)  |PARTITIONED|
+                                                      data-scan []<-[$$197, $$c] <- q08_group_by.Customer
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                              exchange
                                               -- HASH_PARTITION_EXCHANGE [$$198]  |PARTITIONED|
+                                                project ([$$198])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    join (eq($$204, $$199))
                                                     -- HYBRID_HASH_JOIN [$$204][$$199]  |PARTITIONED|
+                                                      exchange
                                                       -- HASH_PARTITION_EXCHANGE [$$204]  |PARTITIONED|
+                                                        project ([$$198, $$204])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$204] <- [$$n1.getField(2)]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- DATASOURCE_SCAN (q08_group_by.Nation)  |PARTITIONED|
+                                                              data-scan []<-[$$198, $$n1] <- q08_group_by.Nation
+                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  empty-tuple-source
                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        project ([$$199])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          select (eq($$r1.getField(1), "AMERICA"))
                                                           -- STREAM_SELECT  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- DATASOURCE_SCAN (q08_group_by.Region)  |PARTITIONED|
+                                                              data-scan []<-[$$199, $$r1] <- q08_group_by.Region
+                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  empty-tuple-source
                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$200])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          select (eq($$p.getField(4), "ECONOMY ANODIZED STEEL"))
                           -- STREAM_SELECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (q08_group_by.Part)  |PARTITIONED|
+                              data-scan []<-[$$200, $$p] <- q08_group_by.Part
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/q09_group_by.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/q09_group_by.plan
index 9bc4351..358f6bf 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/q09_group_by.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/q09_group_by.plan
@@ -1,55 +1,110 @@
+distribute result [$$137]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$137])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$137] <- [{"l_extendedprice": $$158, "l_discount": $$159, "l_quantity": $$160, "l_orderkey": $$144, "n_name": $$157, "ps_supplycost": $$169}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$158, $$159, $$160, $$144, $$157, $$169])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$139, $$161))
             -- HYBRID_HASH_JOIN [$$139][$$161]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$139])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (contains($$p.getField(1), "green"))
                   -- STREAM_SELECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (q09_group_by.Part)  |PARTITIONED|
+                      data-scan []<-[$$139, $$p] <- q09_group_by.Part
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$161]  |PARTITIONED|
+                project ([$$158, $$159, $$160, $$144, $$157, $$169, $$161])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    join (and(eq($$140, $$161), eq($$141, $$146)))
                     -- HYBRID_HASH_JOIN [$$140, $$141][$$161, $$146]  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$169, $$140, $$141])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$169] <- [$$ps.getField(3)]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (q09_group_by.Partsupp)  |PARTITIONED|
+                              data-scan []<-[$$140, $$141, $$ps] <- q09_group_by.Partsupp
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      exchange
                       -- HASH_PARTITION_EXCHANGE [$$161, $$146]  |PARTITIONED|
+                        project ([$$158, $$159, $$160, $$144, $$157, $$161, $$146])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            join (eq($$142, $$146))
                             -- HYBRID_HASH_JOIN [$$142][$$146]  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$142]  |PARTITIONED|
+                                project ([$$157, $$142])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    join (eq($$143, $$149))
                                     -- HYBRID_HASH_JOIN [$$149][$$143]  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$149]  |PARTITIONED|
+                                        project ([$$142, $$149])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$149] <- [$$s.getField(3)]
                                           -- ASSIGN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (q09_group_by.Supplier)  |PARTITIONED|
+                                              data-scan []<-[$$142, $$s] <- q09_group_by.Supplier
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$157, $$143])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$157] <- [$$n.getField(1)]
                                           -- ASSIGN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (q09_group_by.Nation)  |PARTITIONED|
+                                              data-scan []<-[$$143, $$n] <- q09_group_by.Nation
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$146]  |PARTITIONED|
+                                project ([$$158, $$159, $$160, $$144, $$161, $$146])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  assign [$$161, $$160, $$159, $$158, $$146] <- [$$l.getField(1), $$l.getField(4), $$l.getField(6), $$l.getField(5), $$l.getField(2)]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$144, $$l])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (q09_group_by.LineItem)  |PARTITIONED|
+                                        data-scan []<-[$$144, $$145, $$l] <- q09_group_by.LineItem
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/quantifiers/query-ASTERIXDB-2696.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/quantifiers/query-ASTERIXDB-2696.plan
index 26b18be..9975605 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/quantifiers/query-ASTERIXDB-2696.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/quantifiers/query-ASTERIXDB-2696.plan
@@ -1,25 +1,44 @@
+distribute result [$$70]
 -- DISTRIBUTE_RESULT  |LOCAL|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+    project ([$$70])
     -- STREAM_PROJECT  |LOCAL|
+      assign [$$70] <- [{"a": $$a, "s": $$72}]
       -- ASSIGN  |LOCAL|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-          -- PRE_CLUSTERED_GROUP_BY[$$67]  |LOCAL|
-                  {
+          group by ([$$a := $$71]) decor ([]) {
+                    aggregate [$$72] <- [agg-global-sql-sum($$76)]
                     -- AGGREGATE  |LOCAL|
+                      aggregate [$$76] <- [agg-local-sql-sum(switch-case(true, $$67, 1, 0))]
                       -- AGGREGATE  |LOCAL|
-                        -- SUBPLAN  |LOCAL|
-                                {
+                        subplan {
+                                  aggregate [$$67] <- [non-empty-stream()]
                                   -- AGGREGATE  |LOCAL|
+                                    select (ge($$x, 50))
                                     -- STREAM_SELECT  |LOCAL|
+                                      unnest $$x <- scan-collection($$74)
                                       -- UNNEST  |LOCAL|
+                                        nested tuple source
                                         -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                }
+                               }
+                        -- SUBPLAN  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- PRE_CLUSTERED_GROUP_BY[$$71]  |LOCAL|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-              -- STABLE_SORT [$$67(ASC)]  |LOCAL|
+              order (ASC, $$71)
+              -- STABLE_SORT [$$71(ASC)]  |LOCAL|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                  project ([$$74, $$71])
                   -- STREAM_PROJECT  |UNPARTITIONED|
+                    assign [$$74, $$71] <- [$$t.getField(1), $$t.getField(0)]
                     -- ASSIGN  |UNPARTITIONED|
+                      unnest $$t <- scan-collection(array: [ { "a": 1, "b": array: [ 10, 20, 30 ] }, { "a": 1, "b": array: [ 40, 50, 60 ] }, { "a": 1, "b": array: [ 70, 80, 90 ] }, { "a": 2, "b": array: [ 100, 200, 300 ] }, { "a": 2, "b": array: [ 400, 500, 600 ] }, { "a": 2, "b": array: [ 700, 800, 900 ] } ])
                       -- UNNEST  |UNPARTITIONED|
-                        -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
\ No newline at end of file
+                        empty-tuple-source
+                        -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-159-3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-159-3.plan
index 6c713c4..6e9ecad 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-159-3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-159-3.plan
@@ -1,61 +1,119 @@
+distribute result [$$39]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    limit 5
     -- STREAM_LIMIT  |UNPARTITIONED|
+      project ([$$39])
       -- STREAM_PROJECT  |PARTITIONED|
+        assign [$$39] <- [{"id1": $$45, "id2": $$46}]
         -- ASSIGN  |PARTITIONED|
+          exchange
           -- SORT_MERGE_EXCHANGE [$$45(DESC), $$46(DESC) ]  |PARTITIONED|
+            limit 5
             -- STREAM_LIMIT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (topK: 5) (DESC, $$45) (DESC, $$46)
                 -- STABLE_SORT [topK: 5] [$$45(DESC), $$46(DESC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$45, $$46])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        left outer join (eq($$45, $$54))
                         -- HYBRID_HASH_JOIN [$$45][$$54]  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$45])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$45] <- [$$54]
                               -- ASSIGN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  replicate
                                   -- REPLICATE  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$54])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$54] <- [$$46]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$46])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (TinySocial.FacebookUsers)  |PARTITIONED|
+                                                    data-scan []<-[$$46, $$fu2] <- TinySocial.FacebookUsers
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$46, $$54])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              select (and(lt($$47, 5), gt($$47, 2)))
                               -- STREAM_SELECT  |PARTITIONED|
-                                -- SUBPLAN  |PARTITIONED|
-                                        {
+                                subplan {
+                                          aggregate [$$47] <- [agg-count(1)]
                                           -- AGGREGATE  |LOCAL|
+                                            unnest $$43 <- range($$54, $$46)
                                             -- UNNEST  |LOCAL|
+                                              nested tuple source
                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- SUBPLAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    join (true)
                                     -- NESTED_LOOP  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        replicate
                                         -- REPLICATE  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$54])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$54] <- [$$46]
                                               -- ASSIGN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  replicate
                                                   -- REPLICATE  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      project ([$$46])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- DATASOURCE_SCAN (TinySocial.FacebookUsers)  |PARTITIONED|
+                                                          data-scan []<-[$$46, $$fu2] <- TinySocial.FacebookUsers
+                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              empty-tuple-source
                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                      exchange
                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                        replicate
                                         -- REPLICATE  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$46])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- DATASOURCE_SCAN (TinySocial.FacebookUsers)  |PARTITIONED|
+                                                data-scan []<-[$$46, $$fu2] <- TinySocial.FacebookUsers
+                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-1671.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-1671.plan
index 83b412d..756a95e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-1671.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-1671.plan
@@ -1,17 +1,34 @@
+distribute result [$$13]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    limit 0
     -- STREAM_LIMIT  |UNPARTITIONED|
+      project ([$$13])
       -- STREAM_PROJECT  |PARTITIONED|
+        assign [$$13] <- [{"l": $$l}]
         -- ASSIGN  |PARTITIONED|
+          project ([$$l])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- SORT_MERGE_EXCHANGE [$$19(ASC), $$20(ASC) ]  |PARTITIONED|
+              limit 0
               -- STREAM_LIMIT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  order (topK: 0) (ASC, $$19) (ASC, $$20)
                   -- STABLE_SORT [topK: 0] [$$19(ASC), $$20(ASC)]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      assign [$$20, $$19] <- [$$l.getField("l_linestatus"), $$l.getField("l_returnflag")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$l])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
+                            data-scan []<-[$$17, $$18, $$l] <- tpch.LineItem
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-1806.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-1806.plan
index 1feedcd..93c5df7 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-1806.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-1806.plan
@@ -1,25 +1,44 @@
+distribute result [$$132]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$132])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$132] <- [{"l_returnflag": $$l_returnflag, "l_linestatus": $$l_linestatus, "sum_qty": $$138, "sum_base_price": $$139, "sum_disc_price": $$140, "sum_charge": $$141, "ave_qty": $$142, "ave_price": $$143, "ave_disc": $$144, "count_order": $$145}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$l_returnflag(ASC), $$l_linestatus(ASC) ]  |PARTITIONED|
-          -- SORT_GROUP_BY[$$159, $$160]  |PARTITIONED|
-                  {
+          group by ([$$l_returnflag := $$159; $$l_linestatus := $$160]) decor ([]) {
+                    aggregate [$$138, $$139, $$140, $$141, $$142, $$143, $$144, $$145] <- [agg-global-sql-sum($$151), agg-global-sql-sum($$152), agg-global-sql-sum($$153), agg-global-sql-sum($$154), agg-global-sql-avg($$155), agg-global-sql-avg($$156), agg-global-sql-avg($$157), agg-sql-sum($$158)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- SORT_GROUP_BY[$$159, $$160]  |PARTITIONED|
+            exchange
             -- HASH_PARTITION_EXCHANGE [$$159, $$160]  |PARTITIONED|
-              -- SORT_GROUP_BY[$$133, $$134]  |PARTITIONED|
-                      {
+              group by ([$$159 := $$133; $$160 := $$134]) decor ([]) {
+                        aggregate [$$151, $$152, $$153, $$154, $$155, $$156, $$157, $$158] <- [agg-local-sql-sum($$86), agg-local-sql-sum($$91), agg-local-sql-sum(numeric-multiply($$91, numeric-subtract(1, $$148))), agg-local-sql-sum(numeric-multiply(numeric-multiply($$91, numeric-subtract(1, $$148)), numeric-add(1, $$150))), agg-local-sql-avg($$86), agg-local-sql-avg($$91), agg-local-sql-avg($$148), agg-sql-count(1)]
                         -- AGGREGATE  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SORT_GROUP_BY[$$133, $$134]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$86, $$91, $$148, $$150, $$133, $$134])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    select (inject-failure(le($$l.getField(10), "1998-09-02"), eq($$136, 5988)))
                     -- STREAM_SELECT  |PARTITIONED|
+                      assign [$$134, $$133, $$86, $$148, $$150, $$91] <- [$$l.getField(9), $$l.getField(8), $$l.getField(4), $$l.getField(6), $$l.getField(7), $$l.getField(5)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$136, $$l])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
+                            data-scan []<-[$$136, $$137, $$l] <- tpch.LineItem
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-1806_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-1806_ps.plan
index 0d669e0..9c33f68 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-1806_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-1806_ps.plan
@@ -1,59 +1,106 @@
+distribute result [$$132]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$132])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$132] <- [{"l_returnflag": $$l_returnflag, "l_linestatus": $$l_linestatus, "sum_qty": $$138, "sum_base_price": $$139, "sum_disc_price": $$140, "sum_charge": $$141, "ave_qty": $$142, "ave_price": $$143, "ave_disc": $$144, "count_order": $$145}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$l_returnflag) (ASC, $$l_linestatus)
           -- STABLE_SORT [$$l_returnflag(ASC), $$l_linestatus(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$l_returnflag(ASC), $$l_linestatus(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$164
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- SORT_GROUP_BY[$$159, $$160]  |PARTITIONED|
-                              {
+                      group by ([$$l_returnflag := $$159; $$l_linestatus := $$160]) decor ([]) {
+                                aggregate [$$138, $$139, $$140, $$141, $$142, $$143, $$144, $$145] <- [agg-global-sql-sum($$151), agg-global-sql-sum($$152), agg-global-sql-sum($$153), agg-global-sql-sum($$154), agg-global-sql-avg($$155), agg-global-sql-avg($$156), agg-global-sql-avg($$157), agg-sql-sum($$158)]
                                 -- AGGREGATE  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- SORT_GROUP_BY[$$159, $$160]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$159, $$160]  |PARTITIONED|
-                          -- SORT_GROUP_BY[$$133, $$134]  |PARTITIONED|
-                                  {
+                          group by ([$$159 := $$133; $$160 := $$134]) decor ([]) {
+                                    aggregate [$$151, $$152, $$153, $$154, $$155, $$156, $$157, $$158] <- [agg-local-sql-sum($$86), agg-local-sql-sum($$91), agg-local-sql-sum(numeric-multiply($$91, numeric-subtract(1, $$148))), agg-local-sql-sum(numeric-multiply(numeric-multiply($$91, numeric-subtract(1, $$148)), numeric-add(1, $$150))), agg-local-sql-avg($$86), agg-local-sql-avg($$91), agg-local-sql-avg($$148), agg-sql-count(1)]
                                     -- AGGREGATE  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                  }
+                                 }
+                          -- SORT_GROUP_BY[$$133, $$134]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$86, $$91, $$148, $$150, $$133, $$134])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                select (inject-failure(le($$l.getField(10), "1998-09-02"), eq($$136, 5988)))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  assign [$$134, $$133, $$86, $$148, $$150, $$91] <- [$$l.getField(9), $$l.getField(8), $$l.getField(4), $$l.getField(6), $$l.getField(7), $$l.getField(5)]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$136, $$l])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
+                                        data-scan []<-[$$136, $$137, $$l] <- tpch.LineItem
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$164] <- [agg-range-map($$161, $$162, $$163)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$161, $$162, $$163] <- [agg-local-sampling($$l_returnflag, $$l_linestatus), agg-null-writer($$l_returnflag), agg-null-writer($$l_linestatus)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$l_returnflag, $$l_linestatus])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- SORT_GROUP_BY[$$159, $$160]  |PARTITIONED|
-                                        {
+                                group by ([$$l_returnflag := $$159; $$l_linestatus := $$160]) decor ([]) {
+                                          aggregate [$$138, $$139, $$140, $$141, $$142, $$143, $$144, $$145] <- [agg-global-sql-sum($$151), agg-global-sql-sum($$152), agg-global-sql-sum($$153), agg-global-sql-sum($$154), agg-global-sql-avg($$155), agg-global-sql-avg($$156), agg-global-sql-avg($$157), agg-sql-sum($$158)]
                                           -- AGGREGATE  |LOCAL|
+                                            nested tuple source
                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- SORT_GROUP_BY[$$159, $$160]  |PARTITIONED|
+                                  exchange
                                   -- HASH_PARTITION_EXCHANGE [$$159, $$160]  |PARTITIONED|
-                                    -- SORT_GROUP_BY[$$133, $$134]  |PARTITIONED|
-                                            {
+                                    group by ([$$159 := $$133; $$160 := $$134]) decor ([]) {
+                                              aggregate [$$151, $$152, $$153, $$154, $$155, $$156, $$157, $$158] <- [agg-local-sql-sum($$86), agg-local-sql-sum($$91), agg-local-sql-sum(numeric-multiply($$91, numeric-subtract(1, $$148))), agg-local-sql-sum(numeric-multiply(numeric-multiply($$91, numeric-subtract(1, $$148)), numeric-add(1, $$150))), agg-local-sql-avg($$86), agg-local-sql-avg($$91), agg-local-sql-avg($$148), agg-sql-count(1)]
                                               -- AGGREGATE  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                            }
+                                           }
+                                    -- SORT_GROUP_BY[$$133, $$134]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$86, $$91, $$148, $$150, $$133, $$134])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          select (inject-failure(le($$l.getField(10), "1998-09-02"), eq($$136, 5988)))
                                           -- STREAM_SELECT  |PARTITIONED|
+                                            assign [$$134, $$133, $$86, $$148, $$150, $$91] <- [$$l.getField(9), $$l.getField(8), $$l.getField(4), $$l.getField(6), $$l.getField(7), $$l.getField(5)]
                                             -- ASSIGN  |PARTITIONED|
+                                              project ([$$136, $$l])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
+                                                  data-scan []<-[$$136, $$137, $$l] <- tpch.LineItem
+                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-2354.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-2354.plan
index 93b59d4..f88626e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-2354.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-2354.plan
@@ -1,45 +1,90 @@
+distribute result [$#1]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$#1])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- SORT_MERGE_EXCHANGE [$$114(ASC), $$115(ASC), $$116(ASC) ]  |PARTITIONED|
+        order (ASC, $$114) (ASC, $$115) (ASC, $$116)
         -- STABLE_SORT [$$114(ASC), $$115(ASC), $$116(ASC)]  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            union ($$213, $$214, $#1) ($$117, $$74, $$116) ($$143, $$73, $$115) ($$71, $$76, $$114)
             -- UNION_ALL  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$213, $$117, $$143, $$71])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- RANDOM_PARTITION_EXCHANGE  |PARTITIONED|
+                    project ([$$71, $$213, $$117, $$143])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$213, $$117, $$143] <- [cast($$45), $$45.getField("v3"), $$45.getField("v2")]
                       -- ASSIGN  |PARTITIONED|
+                        assign [$$45] <- [{"v1": $$71}]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$71])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$71] <- [$$76]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                replicate
                                 -- REPLICATE  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    select (like($$76, "Orders%"))
                                     -- STREAM_SELECT  |PARTITIONED|
+                                      project ([$$76])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (Metadata.Dataset)  |PARTITIONED|
+                                          data-scan []<-[$$75, $$76, $$ds] <- Metadata.Dataset
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$214, $$74, $$73, $$76])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$214] <- [cast({"v1": $$76, "v2": $$73, "v3": $$74})]
                   -- ASSIGN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (true)
                       -- NESTED_LOOP  |PARTITIONED|
+                        exchange
                         -- RANDOM_PARTITION_EXCHANGE  |PARTITIONED|
+                          select (like($$73, "Orders%"))
                           -- STREAM_SELECT  |PARTITIONED|
+                            project ([$$73, $$74])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (Metadata.Index)  |PARTITIONED|
+                                data-scan []<-[$$72, $$73, $$74, $$idx] <- Metadata.Index
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (like($$76, "Orders%"))
                               -- STREAM_SELECT  |PARTITIONED|
+                                project ([$$76])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (Metadata.Dataset)  |PARTITIONED|
+                                    data-scan []<-[$$75, $$76, $$ds] <- Metadata.Dataset
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-2354_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-2354_ps.plan
index 323e1cd..648f0f2 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-2354_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-2354_ps.plan
@@ -1,96 +1,192 @@
+distribute result [$#1]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$#1])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$114) (ASC, $$115) (ASC, $$116)
         -- STABLE_SORT [$$114(ASC), $$115(ASC), $$116(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$114(ASC), $$115(ASC), $$116(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$219
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    union ($$213, $$214, $#1) ($$117, $$74, $$116) ($$143, $$73, $$115) ($$71, $$76, $$114)
                     -- UNION_ALL  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$213, $$117, $$143, $$71])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- RANDOM_PARTITION_EXCHANGE  |PARTITIONED|
+                            project ([$$71, $$213, $$117, $$143])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$213, $$117, $$143] <- [cast($$45), $$45.getField("v3"), $$45.getField("v2")]
                               -- ASSIGN  |PARTITIONED|
+                                assign [$$45] <- [{"v1": $$71}]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$71])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$71] <- [$$76]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        replicate
                                         -- REPLICATE  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            select (like($$76, "Orders%"))
                                             -- STREAM_SELECT  |PARTITIONED|
+                                              project ([$$76])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- DATASOURCE_SCAN (Metadata.Dataset)  |PARTITIONED|
+                                                  data-scan []<-[$$75, $$76, $$ds] <- Metadata.Dataset
+                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$214, $$74, $$73, $$76])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$214] <- [cast({"v1": $$76, "v2": $$73, "v3": $$74})]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              join (true)
                               -- NESTED_LOOP  |PARTITIONED|
+                                exchange
                                 -- RANDOM_PARTITION_EXCHANGE  |PARTITIONED|
+                                  select (like($$73, "Orders%"))
                                   -- STREAM_SELECT  |PARTITIONED|
+                                    project ([$$73, $$74])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (Metadata.Index)  |PARTITIONED|
+                                        data-scan []<-[$$72, $$73, $$74, $$idx] <- Metadata.Index
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                exchange
                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                  replicate
                                   -- REPLICATE  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      select (like($$76, "Orders%"))
                                       -- STREAM_SELECT  |PARTITIONED|
+                                        project ([$$76])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (Metadata.Dataset)  |PARTITIONED|
+                                            data-scan []<-[$$75, $$76, $$ds] <- Metadata.Dataset
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$219] <- [agg-range-map($$215, $$216, $$217, $$218)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$215, $$216, $$217, $$218] <- [agg-local-sampling($$114, $$115, $$116), agg-null-writer($$114), agg-null-writer($$115), agg-null-writer($$116)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$114, $$115, $$116])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              union ($$213, $$214, $#1) ($$117, $$74, $$116) ($$143, $$73, $$115) ($$71, $$76, $$114)
                               -- UNION_ALL  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$213, $$117, $$143, $$71])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- RANDOM_PARTITION_EXCHANGE  |PARTITIONED|
+                                      project ([$$71, $$213, $$117, $$143])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$213, $$117, $$143] <- [cast($$45), $$45.getField("v3"), $$45.getField("v2")]
                                         -- ASSIGN  |PARTITIONED|
+                                          assign [$$45] <- [{"v1": $$71}]
                                           -- ASSIGN  |PARTITIONED|
+                                            project ([$$71])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$71] <- [$$76]
                                               -- ASSIGN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  replicate
                                                   -- REPLICATE  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      select (like($$76, "Orders%"))
                                                       -- STREAM_SELECT  |PARTITIONED|
+                                                        project ([$$76])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- DATASOURCE_SCAN (Metadata.Dataset)  |PARTITIONED|
+                                                            data-scan []<-[$$75, $$76, $$ds] <- Metadata.Dataset
+                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                empty-tuple-source
                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$214, $$74, $$73, $$76])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$214] <- [cast({"v1": $$76, "v2": $$73, "v3": $$74})]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        join (true)
                                         -- NESTED_LOOP  |PARTITIONED|
+                                          exchange
                                           -- RANDOM_PARTITION_EXCHANGE  |PARTITIONED|
+                                            select (like($$73, "Orders%"))
                                             -- STREAM_SELECT  |PARTITIONED|
+                                              project ([$$73, $$74])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- DATASOURCE_SCAN (Metadata.Index)  |PARTITIONED|
+                                                  data-scan []<-[$$72, $$73, $$74, $$idx] <- Metadata.Index
+                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                          exchange
                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                select (like($$76, "Orders%"))
                                                 -- STREAM_SELECT  |PARTITIONED|
+                                                  project ([$$76])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (Metadata.Dataset)  |PARTITIONED|
+                                                      data-scan []<-[$$75, $$76, $$ds] <- Metadata.Dataset
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-2408.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-2408.plan
index 9a5ddbf..ecb60ea 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-2408.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-2408.plan
@@ -1,34 +1,65 @@
+distribute result [$$40]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$40])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$40] <- [{"name": $$48, "orders": $$37}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$48, $$37])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- SORT_MERGE_EXCHANGE [$$45(ASC) ]  |PARTITIONED|
+            order (ASC, $$45)
             -- STABLE_SORT [$$45(ASC)]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$48, $$37, $$45])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- PRE_CLUSTERED_GROUP_BY[$$43]  |PARTITIONED|
-                            {
+                    group by ([$$50 := $$43]) decor ([$$48]) {
+                              aggregate [$$37, $$45] <- [listify($$44), agg-sql-count($$44)]
                               -- AGGREGATE  |LOCAL|
+                                select (not(is-missing($$49)))
                                 -- STREAM_SELECT  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                            }
+                           }
+                    -- PRE_CLUSTERED_GROUP_BY[$$43]  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$48, $$44, $$49, $$43])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            left outer join (eq($$46, $$43))
                             -- HYBRID_HASH_JOIN [$$43][$$46]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$48, $$43])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  assign [$$48] <- [$$c.getField("name")]
                                   -- ASSIGN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.customers)  |PARTITIONED|
+                                      data-scan []<-[$$43, $$c] <- test.customers
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$46]  |PARTITIONED|
+                                project ([$$44, $$49, $$46])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  assign [$$49, $$46] <- [true, $$o.getField("customer_id")]
                                   -- ASSIGN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                      data-scan []<-[$$44, $$o] <- test.orders
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-2408_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-2408_ps.plan
index 8456246..96c169f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-2408_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-2408_ps.plan
@@ -1,72 +1,138 @@
+distribute result [$$40]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$40])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$40] <- [{"name": $$48, "orders": $$37}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$48, $$37])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            order (ASC, $$45)
             -- STABLE_SORT [$$45(ASC)]  |PARTITIONED|
+              exchange
               -- RANGE_PARTITION_EXCHANGE [$$45(ASC)]  |PARTITIONED|
+                forward: shared-variable = $$53
                 -- FORWARD  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$48, $$37, $$45])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- PRE_CLUSTERED_GROUP_BY[$$43]  |PARTITIONED|
-                                    {
+                            group by ([$$50 := $$43]) decor ([$$48]) {
+                                      aggregate [$$37, $$45] <- [listify($$44), agg-sql-count($$44)]
                                       -- AGGREGATE  |LOCAL|
+                                        select (not(is-missing($$49)))
                                         -- STREAM_SELECT  |LOCAL|
+                                          nested tuple source
                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                    }
+                                   }
+                            -- PRE_CLUSTERED_GROUP_BY[$$43]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$48, $$44, $$49, $$43])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    left outer join (eq($$46, $$43))
                                     -- HYBRID_HASH_JOIN [$$43][$$46]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$48, $$43])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$48] <- [$$c.getField("name")]
                                           -- ASSIGN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.customers)  |PARTITIONED|
+                                              data-scan []<-[$$43, $$c] <- test.customers
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$46]  |PARTITIONED|
+                                        project ([$$44, $$49, $$46])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$49, $$46] <- [true, $$o.getField("customer_id")]
                                           -- ASSIGN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                              data-scan []<-[$$44, $$o] <- test.orders
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    aggregate [$$53] <- [agg-range-map($$51, $$52)]
                     -- AGGREGATE  |UNPARTITIONED|
+                      exchange
                       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                        aggregate [$$51, $$52] <- [agg-local-sampling($$45), agg-null-writer($$45)]
                         -- AGGREGATE  |PARTITIONED|
+                          project ([$$45])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              replicate
                               -- REPLICATE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$48, $$37, $$45])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- PRE_CLUSTERED_GROUP_BY[$$43]  |PARTITIONED|
-                                              {
+                                      group by ([$$50 := $$43]) decor ([$$48]) {
+                                                aggregate [$$37, $$45] <- [listify($$44), agg-sql-count($$44)]
                                                 -- AGGREGATE  |LOCAL|
+                                                  select (not(is-missing($$49)))
                                                   -- STREAM_SELECT  |LOCAL|
+                                                    nested tuple source
                                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                              }
+                                             }
+                                      -- PRE_CLUSTERED_GROUP_BY[$$43]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$48, $$44, $$49, $$43])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              left outer join (eq($$46, $$43))
                                               -- HYBRID_HASH_JOIN [$$43][$$46]  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  project ([$$48, $$43])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    assign [$$48] <- [$$c.getField("name")]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.customers)  |PARTITIONED|
+                                                        data-scan []<-[$$43, $$c] <- test.customers
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$46]  |PARTITIONED|
+                                                  project ([$$44, $$49, $$46])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    assign [$$49, $$46] <- [true, $$o.getField("customer_id")]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                                        data-scan []<-[$$44, $$o] <- test.orders
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-2700.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-2700.plan
index 4587b19..d9a996a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-2700.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-2700.plan
@@ -1,35 +1,70 @@
+distribute result [$$43]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$43])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$43] <- [{"uname": $$52, "message": $$msg.getField("message")}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$52, $$msg])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$msg.getField("author_id"), $$45))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$52, $$45, $$msg])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- BTREE_SEARCH (bigfun.GleambookMessagesComposite.GleambookMessagesComposite)  |PARTITIONED|
+                unnest-map [$$46, $$47, $$msg] <- index-search("GleambookMessagesComposite", 0, "bigfun", "GleambookMessagesComposite", true, false, 2, $$59, $$60, 2, $$59, $$60, true, true, true)
+                -- BTREE_SEARCH  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    order (ASC, $$59) (ASC, $$60)
                     -- STABLE_SORT [$$59(ASC), $$60(ASC)]  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$52, $$45, $$59, $$60])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (bigfun.GleambookMessagesComposite.authorIdIx)  |PARTITIONED|
+                            unnest-map [$$58, $$59, $$60] <- index-search("authorIdIx", 0, "bigfun", "GleambookMessagesComposite", true, true, 1, $$45, 1, $$45, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                assign [] <- []
                                 -- ASSIGN  |PARTITIONED|
+                                  exchange
                                   -- SORT_MERGE_EXCHANGE [$$45(ASC) ]  |PARTITIONED|
+                                    order (ASC, $$45)
                                     -- STABLE_SORT [$$45(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$52, $$45])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          select (ge($$u.getField("user_since"), "2008-07-22T00:00:00"))
                                           -- STREAM_SELECT  |PARTITIONED|
+                                            assign [$$52] <- [$$u.getField("name")]
                                             -- ASSIGN  |PARTITIONED|
+                                              project ([$$45, $$u])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- BTREE_SEARCH (bigfun.GleambookUsersComposite.GleambookUsersComposite)  |PARTITIONED|
+                                                  unnest-map [$$44, $$45, $$u] <- index-search("GleambookUsersComposite", 0, "bigfun", "GleambookUsersComposite", false, false, 2, $$56, $$57, 2, $$56, $$57, true, true, true)
+                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      order (ASC, $$56) (ASC, $$57)
                                                       -- STABLE_SORT [$$56(ASC), $$57(ASC)]  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          project ([$$56, $$57])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- BTREE_SEARCH (bigfun.GleambookUsersComposite.usrSinceIx)  |PARTITIONED|
+                                                              unnest-map [$$55, $$56, $$57] <- index-search("usrSinceIx", 0, "bigfun", "GleambookUsersComposite", false, false, 1, $$54, 0, true, true, false)
+                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  assign [$$54] <- ["2008-07-22T00:00:00"]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    empty-tuple-source
                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-3334.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-3334.plan
index bbb94e3..58bd9ab 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-3334.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-3334.plan
@@ -1,61 +1,110 @@
+distribute result [$$792]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$792])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$792] <- [{"Employee Name": $$Employee Name, "avg:Employee Salary:ok": $$804}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- SORT_GROUP_BY[$$1112]  |PARTITIONED|
-                  {
+          group by ([$$Employee Name := $$1112]) decor ([]) {
+                    aggregate [$$804] <- [agg-global-sql-avg($$1111)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- SORT_GROUP_BY[$$1112]  |PARTITIONED|
+            exchange
             -- HASH_PARTITION_EXCHANGE [$$1112]  |PARTITIONED|
-              -- SORT_GROUP_BY[$$1113]  |PARTITIONED|
-                      {
+              group by ([$$1112 := $$1113]) decor ([]) {
+                        aggregate [$$1111] <- [agg-local-sql-avg($$1118)]
                         -- AGGREGATE  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SORT_GROUP_BY[$$1113]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$1118, $$1113])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (and(eq($$1113, $$Employee Name), eq($$1114, $$Call Center Region)))
                       -- HYBRID_HASH_JOIN [$$1113, $$1114][$$Employee Name, $$Call Center Region]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$1114, $$1113]  |PARTITIONED|
+                          project ([$$1118, $$1113, $$1114])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            select (and(not(is-null(int64-default-null($#6.getField("Item Count")))), not(is-null(string-default-null($#6.getField("Ship Priority")))), not(is-null(string-default-null($#6.getField("Order Priority")))), not(is-null(string-default-null($#6.getField("Order Status")))), not(is-null(double-default-null($#6.getField("Order Quantity")))), not(is-null(double-default-null($#6.getField("Sales Total")))), not(is-null(double-default-null($#6.getField("Discount")))), not(is-null(double-default-null($#6.getField("Tax Rate")))), not(is-null(string-default-null($#6.getField("Ship Mode")))), not(is-null(double-default-null($#6.getField("Fill Time")))), not(is-null(double-default-null($#6.getField("Gross Profit")))), not(is-null(double-default-null($#6.getField("Price")))), not(is-null(double-default-null($#6.getField("Ship Handle Cost")))), not(is-null($$1113)), not(is-null(string-default-null($#6.getField("Employee Dept")))), not(is-null(string-default-null($#6.getField("Manager Name")))), not(is-null(double-default-null($#6.getField("Employee Yrs Exp")))), not(is-null($$1118)), not(is-null(string-default-null($#6.getField("Customer Name")))), not(is-null(string-default-null($#6.getField("Customer State")))), not(is-null($$1114)), not(is-null(double-default-null($#6.getField("Customer Balance")))), not(is-null(string-default-null($#6.getField("Customer Segment")))), not(is-null(string-default-null($#6.getField("Prod Type1")))), not(is-null(string-default-null($#6.getField("Prod Type2")))), not(is-null(string-default-null($#6.getField("Prod Type3")))), not(is-null(string-default-null($#6.getField("Prod Type4")))), not(is-null(string-default-null($#6.getField("Product Name")))), not(is-null(string-default-null($#6.getField("Product Container")))), not(is-null(string-default-null($#6.getField("Ship Promo")))), not(is-null(string-default-null($#6.getField("Supplier Name")))), not(is-null(double-default-null($#6.getField("Supplier Balance")))), not(is-null(string-default-null($#6.getField("Supplier Region")))), not(is-null(string-default-null($#6.getField("Supplier State")))), not(is-null(string-default-null($#6.getField("Order ID")))), not(is-null(int64-default-null($#6.getField("Order Year")))), not(is-null(int64-default-null($#6.getField("Order Month")))), not(is-null(int64-default-null($#6.getField("Order Day")))), not(is-null(datetime-default-null($#6.getField("Order Date")))), not(is-null(string-default-null($#6.getField("Order Quarter")))), not(is-null(double-default-null($#6.getField("Product Base Margin")))), not(is-null(string-default-null($#6.getField("Product ID")))), not(is-null(double-default-null($#6.getField("Receive Time")))), not(is-null(datetime-default-null($#6.getField("Received Date")))), not(is-null(datetime-default-null($#6.getField("Ship Date")))), not(is-null(double-default-null($#6.getField("Ship Charge")))), not(is-null(double-default-null($#6.getField("Total Cycle Time")))), not(is-null(string-default-null($#6.getField("Product In Stock")))), not(is-null(int64-default-null($#6.getField("PID")))), not(is-null(string-default-null($#6.getField("Market Segment"))))))
                             -- STREAM_SELECT  |PARTITIONED|
+                              assign [$$1118, $$1114, $$1113] <- [double-default-null($#6.getField("Employee Salary")), string-default-null($#6.getField("Call Center Region")), string-default-null($#6.getField("Employee Name"))]
                               -- ASSIGN  |PARTITIONED|
+                                project ([$#6])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  assign [$#6] <- [$#6]
                                   -- ASSIGN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      replicate
                                       -- REPLICATE  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$#6])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                              data-scan []<-[$$798, $#6] <- test.collection0
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$Employee Name, $$Call Center Region])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            select (and(ge($$803, 102499.99999999898), le($$802, 110000.0000000011)))
                             -- STREAM_SELECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- SORT_GROUP_BY[$$1109, $$1110]  |PARTITIONED|
-                                        {
+                                group by ([$$Call Center Region := $$1109; $$Employee Name := $$1110]) decor ([]) {
+                                          aggregate [$$802, $$803] <- [agg-global-sql-avg($$1107), agg-global-sql-avg($$1108)]
                                           -- AGGREGATE  |LOCAL|
+                                            nested tuple source
                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- SORT_GROUP_BY[$$1109, $$1110]  |PARTITIONED|
+                                  exchange
                                   -- HASH_PARTITION_EXCHANGE [$$1109, $$1110]  |PARTITIONED|
-                                    -- SORT_GROUP_BY[$$1117, $$1116]  |PARTITIONED|
-                                            {
+                                    group by ([$$1109 := $$1117; $$1110 := $$1116]) decor ([]) {
+                                              aggregate [$$1107, $$1108] <- [agg-local-sql-avg($$1115), agg-local-sql-avg($$1115)]
                                               -- AGGREGATE  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                            }
+                                           }
+                                    -- SORT_GROUP_BY[$$1117, $$1116]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$1115, $$1117, $$1116])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          select (and(not(is-null(int64-default-null($#6.getField("Item Count")))), not(is-null(string-default-null($#6.getField("Ship Priority")))), not(is-null(string-default-null($#6.getField("Order Priority")))), not(is-null(string-default-null($#6.getField("Order Status")))), not(is-null(double-default-null($#6.getField("Order Quantity")))), not(is-null(double-default-null($#6.getField("Sales Total")))), not(is-null(double-default-null($#6.getField("Discount")))), not(is-null(double-default-null($#6.getField("Tax Rate")))), not(is-null(string-default-null($#6.getField("Ship Mode")))), not(is-null(double-default-null($#6.getField("Fill Time")))), not(is-null(double-default-null($#6.getField("Gross Profit")))), not(is-null(double-default-null($#6.getField("Price")))), not(is-null(double-default-null($#6.getField("Ship Handle Cost")))), not(is-null($$1116)), not(is-null(string-default-null($#6.getField("Employee Dept")))), not(is-null(string-default-null($#6.getField("Manager Name")))), not(is-null(double-default-null($#6.getField("Employee Yrs Exp")))), not(is-null($$1115)), not(is-null(string-default-null($#6.getField("Customer Name")))), not(is-null(string-default-null($#6.getField("Customer State")))), not(is-null($$1117)), not(is-null(double-default-null($#6.getField("Customer Balance")))), not(is-null(string-default-null($#6.getField("Customer Segment")))), not(is-null(string-default-null($#6.getField("Prod Type1")))), not(is-null(string-default-null($#6.getField("Prod Type2")))), not(is-null(string-default-null($#6.getField("Prod Type3")))), not(is-null(string-default-null($#6.getField("Prod Type4")))), not(is-null(string-default-null($#6.getField("Product Name")))), not(is-null(string-default-null($#6.getField("Product Container")))), not(is-null(string-default-null($#6.getField("Ship Promo")))), not(is-null(string-default-null($#6.getField("Supplier Name")))), not(is-null(double-default-null($#6.getField("Supplier Balance")))), not(is-null(string-default-null($#6.getField("Supplier Region")))), not(is-null(string-default-null($#6.getField("Supplier State")))), not(is-null(string-default-null($#6.getField("Order ID")))), not(is-null(int64-default-null($#6.getField("Order Year")))), not(is-null(int64-default-null($#6.getField("Order Month")))), not(is-null(int64-default-null($#6.getField("Order Day")))), not(is-null(datetime-default-null($#6.getField("Order Date")))), not(is-null(string-default-null($#6.getField("Order Quarter")))), not(is-null(double-default-null($#6.getField("Product Base Margin")))), not(is-null(string-default-null($#6.getField("Product ID")))), not(is-null(double-default-null($#6.getField("Receive Time")))), not(is-null(datetime-default-null($#6.getField("Received Date")))), not(is-null(datetime-default-null($#6.getField("Ship Date")))), not(is-null(double-default-null($#6.getField("Ship Charge")))), not(is-null(double-default-null($#6.getField("Total Cycle Time")))), not(is-null(string-default-null($#6.getField("Product In Stock")))), not(is-null(int64-default-null($#6.getField("PID")))), not(is-null(string-default-null($#6.getField("Market Segment"))))))
                                           -- STREAM_SELECT  |PARTITIONED|
+                                            assign [$$1117, $$1116, $$1115] <- [string-default-null($#6.getField("Call Center Region")), string-default-null($#6.getField("Employee Name")), double-default-null($#6.getField("Employee Salary"))]
                                             -- ASSIGN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                replicate
                                                 -- REPLICATE  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$#6])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                        data-scan []<-[$$798, $#6] <- test.collection0
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-3512.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-3512.plan
index 9160a43..0a1b98c 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-3512.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-3512.plan
@@ -1,28 +1,56 @@
+distribute result [$$91]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    union ($$83, $$88, $$91)
     -- UNION_ALL  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$83])
         -- STREAM_PROJECT  |PARTITIONED|
+          assign [$$83] <- [{"sym": $$S.getField("sym")}]
           -- ASSIGN  |PARTITIONED|
+            select (lt($$S.getField("date"), print-date(current-date(), "YYYY-MM-DD")))
             -- STREAM_SELECT  |PARTITIONED|
+              project ([$$S])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                  data-scan []<-[$$102, $$S] <- test.collection1
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$88])
         -- STREAM_PROJECT  |PARTITIONED|
+          assign [$$88] <- [{"sym": $$100.getField("sym")}]
           -- ASSIGN  |PARTITIONED|
+            select (lt($$100.getField("date"), print-date(current-date(), "YYYY-MM-DD")))
             -- STREAM_SELECT  |PARTITIONED|
+              project ([$$100])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.collection2.collection2)  |PARTITIONED|
+                  unnest-map [$$105, $$100] <- index-search("collection2", 0, "test", "collection2", false, false, 1, $$117, 1, $$117, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$117)
                       -- STABLE_SORT [$$117(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$117])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.collection2.idx1)  |PARTITIONED|
+                              unnest-map [$$113, $$114, $$115, $$116, $$117] <- index-search("idx1", 0, "test", "collection2", false, false, 0, 1, $$112, true, false, false)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$112] <- [print-date(current-date(), "YYYY-MM-DD")]
                                   -- ASSIGN  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-810-2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-810-2.plan
index 70e5fb0..eabc096 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-810-2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-810-2.plan
@@ -1,37 +1,64 @@
+distribute result [$$105]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$105])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$105] <- [{"l_returnflag": $$l_returnflag, "l_linestatus": $$l_linestatus, "count_cheaps": $$112, "count_expensives": $$113}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$l_returnflag(ASC), $$l_linestatus(ASC) ]  |PARTITIONED|
+          group by ([$$l_returnflag := $$120; $$l_linestatus := $$121]) decor ([]) {
+                    aggregate [$$112] <- [agg-sum($$118)]
+                    -- AGGREGATE  |LOCAL|
+                      nested tuple source
+                      -- NESTED_TUPLE_SOURCE  |LOCAL|
+                 }
+                 {
+                    aggregate [$$113] <- [agg-sum($$119)]
+                    -- AGGREGATE  |LOCAL|
+                      nested tuple source
+                      -- NESTED_TUPLE_SOURCE  |LOCAL|
+                 }
           -- PRE_CLUSTERED_GROUP_BY[$$120, $$121]  |PARTITIONED|
-                  {
-                    -- AGGREGATE  |LOCAL|
-                      -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
-                  {
-                    -- AGGREGATE  |LOCAL|
-                      -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$120) (ASC, $$121)
               -- STABLE_SORT [$$120(ASC), $$121(ASC)]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$120, $$121]  |PARTITIONED|
+                  group by ([$$120 := $$106; $$121 := $$107]) decor ([]) {
+                            aggregate [$$118] <- [agg-count($$l)]
+                            -- AGGREGATE  |LOCAL|
+                              select (gt($$116, 0.05))
+                              -- STREAM_SELECT  |LOCAL|
+                                nested tuple source
+                                -- NESTED_TUPLE_SOURCE  |LOCAL|
+                         }
+                         {
+                            aggregate [$$119] <- [agg-count($$l)]
+                            -- AGGREGATE  |LOCAL|
+                              select (le($$116, 0.05))
+                              -- STREAM_SELECT  |LOCAL|
+                                nested tuple source
+                                -- NESTED_TUPLE_SOURCE  |LOCAL|
+                         }
                   -- PRE_CLUSTERED_GROUP_BY[$$106, $$107]  |PARTITIONED|
-                          {
-                            -- AGGREGATE  |LOCAL|
-                              -- STREAM_SELECT  |LOCAL|
-                                -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
-                          {
-                            -- AGGREGATE  |LOCAL|
-                              -- STREAM_SELECT  |LOCAL|
-                                -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$106) (ASC, $$107)
                       -- STABLE_SORT [$$106(ASC), $$107(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$107, $$106, $$116] <- [$$l.getField(9), $$l.getField(8), $$l.getField(6)]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$l])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
+                                data-scan []<-[$$110, $$111, $$l] <- tpch.LineItem
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-810-2_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-810-2_ps.plan
index 74741ef..4c6e2a8 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-810-2_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-810-2_ps.plan
@@ -1,83 +1,146 @@
+distribute result [$$105]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$105])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$105] <- [{"l_returnflag": $$l_returnflag, "l_linestatus": $$l_linestatus, "count_cheaps": $$112, "count_expensives": $$113}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$l_returnflag) (ASC, $$l_linestatus)
           -- STABLE_SORT [$$l_returnflag(ASC), $$l_linestatus(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$l_returnflag(ASC), $$l_linestatus(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$125
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      group by ([$$l_returnflag := $$120; $$l_linestatus := $$121]) decor ([]) {
+                                aggregate [$$112] <- [agg-sum($$118)]
+                                -- AGGREGATE  |LOCAL|
+                                  nested tuple source
+                                  -- NESTED_TUPLE_SOURCE  |LOCAL|
+                             }
+                             {
+                                aggregate [$$113] <- [agg-sum($$119)]
+                                -- AGGREGATE  |LOCAL|
+                                  nested tuple source
+                                  -- NESTED_TUPLE_SOURCE  |LOCAL|
+                             }
                       -- PRE_CLUSTERED_GROUP_BY[$$120, $$121]  |PARTITIONED|
-                              {
-                                -- AGGREGATE  |LOCAL|
-                                  -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
-                              {
-                                -- AGGREGATE  |LOCAL|
-                                  -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$120) (ASC, $$121)
                           -- STABLE_SORT [$$120(ASC), $$121(ASC)]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$120, $$121]  |PARTITIONED|
+                              group by ([$$120 := $$106; $$121 := $$107]) decor ([]) {
+                                        aggregate [$$118] <- [agg-count($$l)]
+                                        -- AGGREGATE  |LOCAL|
+                                          select (gt($$116, 0.05))
+                                          -- STREAM_SELECT  |LOCAL|
+                                            nested tuple source
+                                            -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                     }
+                                     {
+                                        aggregate [$$119] <- [agg-count($$l)]
+                                        -- AGGREGATE  |LOCAL|
+                                          select (le($$116, 0.05))
+                                          -- STREAM_SELECT  |LOCAL|
+                                            nested tuple source
+                                            -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                     }
                               -- PRE_CLUSTERED_GROUP_BY[$$106, $$107]  |PARTITIONED|
-                                      {
-                                        -- AGGREGATE  |LOCAL|
-                                          -- STREAM_SELECT  |LOCAL|
-                                            -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                      }
-                                      {
-                                        -- AGGREGATE  |LOCAL|
-                                          -- STREAM_SELECT  |LOCAL|
-                                            -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                      }
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  order (ASC, $$106) (ASC, $$107)
                                   -- STABLE_SORT [$$106(ASC), $$107(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      assign [$$107, $$106, $$116] <- [$$l.getField(9), $$l.getField(8), $$l.getField(6)]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$l])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
+                                            data-scan []<-[$$110, $$111, $$l] <- tpch.LineItem
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$125] <- [agg-range-map($$122, $$123, $$124)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$122, $$123, $$124] <- [agg-local-sampling($$l_returnflag, $$l_linestatus), agg-null-writer($$l_returnflag), agg-null-writer($$l_linestatus)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$l_returnflag, $$l_linestatus])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                group by ([$$l_returnflag := $$120; $$l_linestatus := $$121]) decor ([]) {
+                                          aggregate [$$112] <- [agg-sum($$118)]
+                                          -- AGGREGATE  |LOCAL|
+                                            nested tuple source
+                                            -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                       }
+                                       {
+                                          aggregate [$$113] <- [agg-sum($$119)]
+                                          -- AGGREGATE  |LOCAL|
+                                            nested tuple source
+                                            -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                       }
                                 -- PRE_CLUSTERED_GROUP_BY[$$120, $$121]  |PARTITIONED|
-                                        {
-                                          -- AGGREGATE  |LOCAL|
-                                            -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
-                                        {
-                                          -- AGGREGATE  |LOCAL|
-                                            -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$120) (ASC, $$121)
                                     -- STABLE_SORT [$$120(ASC), $$121(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$120, $$121]  |PARTITIONED|
+                                        group by ([$$120 := $$106; $$121 := $$107]) decor ([]) {
+                                                  aggregate [$$118] <- [agg-count($$l)]
+                                                  -- AGGREGATE  |LOCAL|
+                                                    select (gt($$116, 0.05))
+                                                    -- STREAM_SELECT  |LOCAL|
+                                                      nested tuple source
+                                                      -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                               }
+                                               {
+                                                  aggregate [$$119] <- [agg-count($$l)]
+                                                  -- AGGREGATE  |LOCAL|
+                                                    select (le($$116, 0.05))
+                                                    -- STREAM_SELECT  |LOCAL|
+                                                      nested tuple source
+                                                      -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                               }
                                         -- PRE_CLUSTERED_GROUP_BY[$$106, $$107]  |PARTITIONED|
-                                                {
-                                                  -- AGGREGATE  |LOCAL|
-                                                    -- STREAM_SELECT  |LOCAL|
-                                                      -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                }
-                                                {
-                                                  -- AGGREGATE  |LOCAL|
-                                                    -- STREAM_SELECT  |LOCAL|
-                                                      -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                }
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            order (ASC, $$106) (ASC, $$107)
                                             -- STABLE_SORT [$$106(ASC), $$107(ASC)]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$107, $$106, $$116] <- [$$l.getField(9), $$l.getField(8), $$l.getField(6)]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  project ([$$l])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
+                                                      data-scan []<-[$$110, $$111, $$l] <- tpch.LineItem
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-810-3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-810-3.plan
index 25952ed..a486666 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-810-3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-810-3.plan
@@ -1,37 +1,64 @@
+distribute result [$$116]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$116])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$116] <- [{"l_returnflag": $$l_returnflag, "l_linestatus": $$l_linestatus, "count_cheaps": $$122, "count_expensives": $$123}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$l_returnflag(ASC), $$l_linestatus(ASC) ]  |PARTITIONED|
+          group by ([$$l_returnflag := $$130; $$l_linestatus := $$131]) decor ([]) {
+                    aggregate [$$122] <- [agg-sum($$128)]
+                    -- AGGREGATE  |LOCAL|
+                      nested tuple source
+                      -- NESTED_TUPLE_SOURCE  |LOCAL|
+                 }
+                 {
+                    aggregate [$$123] <- [agg-sum($$129)]
+                    -- AGGREGATE  |LOCAL|
+                      nested tuple source
+                      -- NESTED_TUPLE_SOURCE  |LOCAL|
+                 }
           -- PRE_CLUSTERED_GROUP_BY[$$130, $$131]  |PARTITIONED|
-                  {
-                    -- AGGREGATE  |LOCAL|
-                      -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
-                  {
-                    -- AGGREGATE  |LOCAL|
-                      -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$130) (ASC, $$131)
               -- STABLE_SORT [$$130(ASC), $$131(ASC)]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$130, $$131]  |PARTITIONED|
+                  group by ([$$130 := $$117; $$131 := $$118]) decor ([]) {
+                            aggregate [$$128] <- [agg-count($$l)]
+                            -- AGGREGATE  |LOCAL|
+                              select (gt($$126, 0.05))
+                              -- STREAM_SELECT  |LOCAL|
+                                nested tuple source
+                                -- NESTED_TUPLE_SOURCE  |LOCAL|
+                         }
+                         {
+                            aggregate [$$129] <- [agg-count($$l)]
+                            -- AGGREGATE  |LOCAL|
+                              select (le($$126, 0.05))
+                              -- STREAM_SELECT  |LOCAL|
+                                nested tuple source
+                                -- NESTED_TUPLE_SOURCE  |LOCAL|
+                         }
                   -- PRE_CLUSTERED_GROUP_BY[$$117, $$118]  |PARTITIONED|
-                          {
-                            -- AGGREGATE  |LOCAL|
-                              -- STREAM_SELECT  |LOCAL|
-                                -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
-                          {
-                            -- AGGREGATE  |LOCAL|
-                              -- STREAM_SELECT  |LOCAL|
-                                -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$117) (ASC, $$118)
                       -- STABLE_SORT [$$117(ASC), $$118(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$118, $$117, $$126] <- [$$l.getField(9), $$l.getField(8), $$l.getField(6)]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$l])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
+                                data-scan []<-[$$120, $$121, $$l] <- tpch.LineItem
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-810-3_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-810-3_ps.plan
index d99b3ed..0853ac6 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-810-3_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-810-3_ps.plan
@@ -1,83 +1,146 @@
+distribute result [$$116]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$116])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$116] <- [{"l_returnflag": $$l_returnflag, "l_linestatus": $$l_linestatus, "count_cheaps": $$122, "count_expensives": $$123}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$l_returnflag) (ASC, $$l_linestatus)
           -- STABLE_SORT [$$l_returnflag(ASC), $$l_linestatus(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$l_returnflag(ASC), $$l_linestatus(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$135
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      group by ([$$l_returnflag := $$130; $$l_linestatus := $$131]) decor ([]) {
+                                aggregate [$$122] <- [agg-sum($$128)]
+                                -- AGGREGATE  |LOCAL|
+                                  nested tuple source
+                                  -- NESTED_TUPLE_SOURCE  |LOCAL|
+                             }
+                             {
+                                aggregate [$$123] <- [agg-sum($$129)]
+                                -- AGGREGATE  |LOCAL|
+                                  nested tuple source
+                                  -- NESTED_TUPLE_SOURCE  |LOCAL|
+                             }
                       -- PRE_CLUSTERED_GROUP_BY[$$130, $$131]  |PARTITIONED|
-                              {
-                                -- AGGREGATE  |LOCAL|
-                                  -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
-                              {
-                                -- AGGREGATE  |LOCAL|
-                                  -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$130) (ASC, $$131)
                           -- STABLE_SORT [$$130(ASC), $$131(ASC)]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$130, $$131]  |PARTITIONED|
+                              group by ([$$130 := $$117; $$131 := $$118]) decor ([]) {
+                                        aggregate [$$128] <- [agg-count($$l)]
+                                        -- AGGREGATE  |LOCAL|
+                                          select (gt($$126, 0.05))
+                                          -- STREAM_SELECT  |LOCAL|
+                                            nested tuple source
+                                            -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                     }
+                                     {
+                                        aggregate [$$129] <- [agg-count($$l)]
+                                        -- AGGREGATE  |LOCAL|
+                                          select (le($$126, 0.05))
+                                          -- STREAM_SELECT  |LOCAL|
+                                            nested tuple source
+                                            -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                     }
                               -- PRE_CLUSTERED_GROUP_BY[$$117, $$118]  |PARTITIONED|
-                                      {
-                                        -- AGGREGATE  |LOCAL|
-                                          -- STREAM_SELECT  |LOCAL|
-                                            -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                      }
-                                      {
-                                        -- AGGREGATE  |LOCAL|
-                                          -- STREAM_SELECT  |LOCAL|
-                                            -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                      }
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  order (ASC, $$117) (ASC, $$118)
                                   -- STABLE_SORT [$$117(ASC), $$118(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      assign [$$118, $$117, $$126] <- [$$l.getField(9), $$l.getField(8), $$l.getField(6)]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$l])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
+                                            data-scan []<-[$$120, $$121, $$l] <- tpch.LineItem
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$135] <- [agg-range-map($$132, $$133, $$134)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$132, $$133, $$134] <- [agg-local-sampling($$l_returnflag, $$l_linestatus), agg-null-writer($$l_returnflag), agg-null-writer($$l_linestatus)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$l_returnflag, $$l_linestatus])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                group by ([$$l_returnflag := $$130; $$l_linestatus := $$131]) decor ([]) {
+                                          aggregate [$$122] <- [agg-sum($$128)]
+                                          -- AGGREGATE  |LOCAL|
+                                            nested tuple source
+                                            -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                       }
+                                       {
+                                          aggregate [$$123] <- [agg-sum($$129)]
+                                          -- AGGREGATE  |LOCAL|
+                                            nested tuple source
+                                            -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                       }
                                 -- PRE_CLUSTERED_GROUP_BY[$$130, $$131]  |PARTITIONED|
-                                        {
-                                          -- AGGREGATE  |LOCAL|
-                                            -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
-                                        {
-                                          -- AGGREGATE  |LOCAL|
-                                            -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$130) (ASC, $$131)
                                     -- STABLE_SORT [$$130(ASC), $$131(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$130, $$131]  |PARTITIONED|
+                                        group by ([$$130 := $$117; $$131 := $$118]) decor ([]) {
+                                                  aggregate [$$128] <- [agg-count($$l)]
+                                                  -- AGGREGATE  |LOCAL|
+                                                    select (gt($$126, 0.05))
+                                                    -- STREAM_SELECT  |LOCAL|
+                                                      nested tuple source
+                                                      -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                               }
+                                               {
+                                                  aggregate [$$129] <- [agg-count($$l)]
+                                                  -- AGGREGATE  |LOCAL|
+                                                    select (le($$126, 0.05))
+                                                    -- STREAM_SELECT  |LOCAL|
+                                                      nested tuple source
+                                                      -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                               }
                                         -- PRE_CLUSTERED_GROUP_BY[$$117, $$118]  |PARTITIONED|
-                                                {
-                                                  -- AGGREGATE  |LOCAL|
-                                                    -- STREAM_SELECT  |LOCAL|
-                                                      -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                }
-                                                {
-                                                  -- AGGREGATE  |LOCAL|
-                                                    -- STREAM_SELECT  |LOCAL|
-                                                      -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                }
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            order (ASC, $$117) (ASC, $$118)
                                             -- STABLE_SORT [$$117(ASC), $$118(ASC)]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$118, $$117, $$126] <- [$$l.getField(9), $$l.getField(8), $$l.getField(6)]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  project ([$$l])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
+                                                      data-scan []<-[$$120, $$121, $$l] <- tpch.LineItem
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-810.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-810.plan
index a9398d5..73c5250 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-810.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-810.plan
@@ -1,37 +1,64 @@
+distribute result [$$127]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$127])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$127] <- [{"l_returnflag": $$l_returnflag, "l_linestatus": $$l_linestatus, "count_cheaps": $$132, "count_expensives": $$133}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$l_returnflag(ASC), $$l_linestatus(ASC) ]  |PARTITIONED|
+          group by ([$$l_returnflag := $$140; $$l_linestatus := $$141]) decor ([]) {
+                    aggregate [$$132] <- [agg-sum($$138)]
+                    -- AGGREGATE  |LOCAL|
+                      nested tuple source
+                      -- NESTED_TUPLE_SOURCE  |LOCAL|
+                 }
+                 {
+                    aggregate [$$133] <- [agg-sum($$139)]
+                    -- AGGREGATE  |LOCAL|
+                      nested tuple source
+                      -- NESTED_TUPLE_SOURCE  |LOCAL|
+                 }
           -- PRE_CLUSTERED_GROUP_BY[$$140, $$141]  |PARTITIONED|
-                  {
-                    -- AGGREGATE  |LOCAL|
-                      -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
-                  {
-                    -- AGGREGATE  |LOCAL|
-                      -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$140) (ASC, $$141)
               -- STABLE_SORT [$$140(ASC), $$141(ASC)]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$140, $$141]  |PARTITIONED|
+                  group by ([$$140 := $$128; $$141 := $$129]) decor ([]) {
+                            aggregate [$$138] <- [agg-count($$l)]
+                            -- AGGREGATE  |LOCAL|
+                              select (gt($$136, 0.05))
+                              -- STREAM_SELECT  |LOCAL|
+                                nested tuple source
+                                -- NESTED_TUPLE_SOURCE  |LOCAL|
+                         }
+                         {
+                            aggregate [$$139] <- [agg-count($$l)]
+                            -- AGGREGATE  |LOCAL|
+                              select (le($$136, 0.05))
+                              -- STREAM_SELECT  |LOCAL|
+                                nested tuple source
+                                -- NESTED_TUPLE_SOURCE  |LOCAL|
+                         }
                   -- PRE_CLUSTERED_GROUP_BY[$$128, $$129]  |PARTITIONED|
-                          {
-                            -- AGGREGATE  |LOCAL|
-                              -- STREAM_SELECT  |LOCAL|
-                                -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
-                          {
-                            -- AGGREGATE  |LOCAL|
-                              -- STREAM_SELECT  |LOCAL|
-                                -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$128) (ASC, $$129)
                       -- STABLE_SORT [$$128(ASC), $$129(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$129, $$128, $$136] <- [$$l.getField(9), $$l.getField(8), $$l.getField(6)]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$l])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
+                                data-scan []<-[$$130, $$131, $$l] <- tpch.LineItem
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-810_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-810_ps.plan
index 038190e..50922aa 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-810_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-ASTERIXDB-810_ps.plan
@@ -1,83 +1,146 @@
+distribute result [$$127]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$127])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$127] <- [{"l_returnflag": $$l_returnflag, "l_linestatus": $$l_linestatus, "count_cheaps": $$132, "count_expensives": $$133}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$l_returnflag) (ASC, $$l_linestatus)
           -- STABLE_SORT [$$l_returnflag(ASC), $$l_linestatus(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$l_returnflag(ASC), $$l_linestatus(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$145
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      group by ([$$l_returnflag := $$140; $$l_linestatus := $$141]) decor ([]) {
+                                aggregate [$$132] <- [agg-sum($$138)]
+                                -- AGGREGATE  |LOCAL|
+                                  nested tuple source
+                                  -- NESTED_TUPLE_SOURCE  |LOCAL|
+                             }
+                             {
+                                aggregate [$$133] <- [agg-sum($$139)]
+                                -- AGGREGATE  |LOCAL|
+                                  nested tuple source
+                                  -- NESTED_TUPLE_SOURCE  |LOCAL|
+                             }
                       -- PRE_CLUSTERED_GROUP_BY[$$140, $$141]  |PARTITIONED|
-                              {
-                                -- AGGREGATE  |LOCAL|
-                                  -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
-                              {
-                                -- AGGREGATE  |LOCAL|
-                                  -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$140) (ASC, $$141)
                           -- STABLE_SORT [$$140(ASC), $$141(ASC)]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$140, $$141]  |PARTITIONED|
+                              group by ([$$140 := $$128; $$141 := $$129]) decor ([]) {
+                                        aggregate [$$138] <- [agg-count($$l)]
+                                        -- AGGREGATE  |LOCAL|
+                                          select (gt($$136, 0.05))
+                                          -- STREAM_SELECT  |LOCAL|
+                                            nested tuple source
+                                            -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                     }
+                                     {
+                                        aggregate [$$139] <- [agg-count($$l)]
+                                        -- AGGREGATE  |LOCAL|
+                                          select (le($$136, 0.05))
+                                          -- STREAM_SELECT  |LOCAL|
+                                            nested tuple source
+                                            -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                     }
                               -- PRE_CLUSTERED_GROUP_BY[$$128, $$129]  |PARTITIONED|
-                                      {
-                                        -- AGGREGATE  |LOCAL|
-                                          -- STREAM_SELECT  |LOCAL|
-                                            -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                      }
-                                      {
-                                        -- AGGREGATE  |LOCAL|
-                                          -- STREAM_SELECT  |LOCAL|
-                                            -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                      }
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  order (ASC, $$128) (ASC, $$129)
                                   -- STABLE_SORT [$$128(ASC), $$129(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      assign [$$129, $$128, $$136] <- [$$l.getField(9), $$l.getField(8), $$l.getField(6)]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$l])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
+                                            data-scan []<-[$$130, $$131, $$l] <- tpch.LineItem
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$145] <- [agg-range-map($$142, $$143, $$144)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$142, $$143, $$144] <- [agg-local-sampling($$l_returnflag, $$l_linestatus), agg-null-writer($$l_returnflag), agg-null-writer($$l_linestatus)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$l_returnflag, $$l_linestatus])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                group by ([$$l_returnflag := $$140; $$l_linestatus := $$141]) decor ([]) {
+                                          aggregate [$$132] <- [agg-sum($$138)]
+                                          -- AGGREGATE  |LOCAL|
+                                            nested tuple source
+                                            -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                       }
+                                       {
+                                          aggregate [$$133] <- [agg-sum($$139)]
+                                          -- AGGREGATE  |LOCAL|
+                                            nested tuple source
+                                            -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                       }
                                 -- PRE_CLUSTERED_GROUP_BY[$$140, $$141]  |PARTITIONED|
-                                        {
-                                          -- AGGREGATE  |LOCAL|
-                                            -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
-                                        {
-                                          -- AGGREGATE  |LOCAL|
-                                            -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$140) (ASC, $$141)
                                     -- STABLE_SORT [$$140(ASC), $$141(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$140, $$141]  |PARTITIONED|
+                                        group by ([$$140 := $$128; $$141 := $$129]) decor ([]) {
+                                                  aggregate [$$138] <- [agg-count($$l)]
+                                                  -- AGGREGATE  |LOCAL|
+                                                    select (gt($$136, 0.05))
+                                                    -- STREAM_SELECT  |LOCAL|
+                                                      nested tuple source
+                                                      -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                               }
+                                               {
+                                                  aggregate [$$139] <- [agg-count($$l)]
+                                                  -- AGGREGATE  |LOCAL|
+                                                    select (le($$136, 0.05))
+                                                    -- STREAM_SELECT  |LOCAL|
+                                                      nested tuple source
+                                                      -- NESTED_TUPLE_SOURCE  |LOCAL|
+                                               }
                                         -- PRE_CLUSTERED_GROUP_BY[$$128, $$129]  |PARTITIONED|
-                                                {
-                                                  -- AGGREGATE  |LOCAL|
-                                                    -- STREAM_SELECT  |LOCAL|
-                                                      -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                }
-                                                {
-                                                  -- AGGREGATE  |LOCAL|
-                                                    -- STREAM_SELECT  |LOCAL|
-                                                      -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                }
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            order (ASC, $$128) (ASC, $$129)
                                             -- STABLE_SORT [$$128(ASC), $$129(ASC)]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$129, $$128, $$136] <- [$$l.getField(9), $$l.getField(8), $$l.getField(6)]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  project ([$$l])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
+                                                      data-scan []<-[$$130, $$131, $$l] <- tpch.LineItem
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-issue562_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-issue562_ps.plan
index 8230bf0..f9a2005 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-issue562_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-issue562_ps.plan
@@ -1,137 +1,250 @@
+distribute result [$$144]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$144])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$144] <- [{"cntrycode": $$cntrycode, "numcust": $$150, "totacctbal": $$151}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$cntrycode)
           -- STABLE_SORT [$$cntrycode(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$cntrycode(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$169
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- SORT_GROUP_BY[$$166]  |PARTITIONED|
-                              {
+                      group by ([$$cntrycode := $$166]) decor ([]) {
+                                aggregate [$$150, $$151] <- [agg-sum($$164), agg-global-sum($$165)]
                                 -- AGGREGATE  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- SORT_GROUP_BY[$$166]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$166]  |PARTITIONED|
-                          -- SORT_GROUP_BY[$$phone_substr]  |PARTITIONED|
-                                  {
+                          group by ([$$166 := $$phone_substr]) decor ([]) {
+                                    aggregate [$$164, $$165] <- [agg-count($$134), agg-local-sum($$155)]
                                     -- AGGREGATE  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                  }
+                                 }
+                          -- SORT_GROUP_BY[$$phone_substr]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$134, $$155, $$phone_substr])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$134] <- [{"ct": $$125}]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$phone_substr, $$155, $$125])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    select (eq($$149, 0))
                                     -- STREAM_SELECT  |PARTITIONED|
+                                      project ([$$149, $$phone_substr, $$155, $$125])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- SORT_GROUP_BY[$$163]  |PARTITIONED|
-                                                  {
+                                          group by ([$$161 := $$163]) decor ([$$phone_substr; $$155; $$125]) {
+                                                    aggregate [$$149] <- [agg-sum($$162)]
                                                     -- AGGREGATE  |LOCAL|
+                                                      nested tuple source
                                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                  }
+                                                 }
+                                          -- SORT_GROUP_BY[$$163]  |PARTITIONED|
+                                            exchange
                                             -- HASH_PARTITION_EXCHANGE [$$163]  |PARTITIONED|
-                                              -- PRE_CLUSTERED_GROUP_BY[$$159]  |PARTITIONED|
-                                                      {
+                                              group by ([$$163 := $$159]) decor ([$$phone_substr; $$155; $$125]) {
+                                                        aggregate [$$162] <- [agg-count($$o)]
                                                         -- AGGREGATE  |LOCAL|
+                                                          select (not(is-missing($$160)))
                                                           -- STREAM_SELECT  |LOCAL|
+                                                            nested tuple source
                                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                      }
+                                                     }
+                                              -- PRE_CLUSTERED_GROUP_BY[$$159]  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  order (ASC, $$159)
                                                   -- STABLE_SORT [$$159(ASC)]  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      project ([$$155, $$phone_substr, $$125, $$o, $$160, $$159])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          left outer join (eq($$146, $$153))
                                                           -- HYBRID_HASH_JOIN [$$146][$$153]  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              running-aggregate [$$159] <- [create-query-uid()]
                                                               -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                                assign [$$125] <- [{"c_acctbal": $$155, "c_custkey": $$146, "cntrycode": $$phone_substr}]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  project ([$$155, $$phone_substr, $$146])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      join (eq($$148, $$phone_substr))
                                                                       -- HYBRID_HASH_JOIN [$$phone_substr][$$148]  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          project ([$$155, $$phone_substr, $$146])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            assign [$$phone_substr, $$155] <- [substring($$c.getField(4), 0, 2), $$c.getField(5)]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                -- DATASOURCE_SCAN (tpch.Customer)  |PARTITIONED|
+                                                                                data-scan []<-[$$146, $$c] <- tpch.Customer
+                                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    empty-tuple-source
                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                        exchange
                                                                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                          unnest $$148 <- scan-collection(array: [ "23", "13", "17", "29", "18", "30", "31" ])
                                                                           -- UNNEST  |UNPARTITIONED|
+                                                                            empty-tuple-source
                                                                             -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                                            exchange
                                                             -- HASH_PARTITION_EXCHANGE [$$153]  |PARTITIONED|
+                                                              assign [$$160, $$153] <- [true, $$o.getField(1)]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                project ([$$o])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                                                                    data-scan []<-[$$147, $$o] <- tpch.Orders
+                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        empty-tuple-source
                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$169] <- [agg-range-map($$167, $$168)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$167, $$168] <- [agg-local-sampling($$cntrycode), agg-null-writer($$cntrycode)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$cntrycode])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- SORT_GROUP_BY[$$166]  |PARTITIONED|
-                                        {
+                                group by ([$$cntrycode := $$166]) decor ([]) {
+                                          aggregate [$$150, $$151] <- [agg-sum($$164), agg-global-sum($$165)]
                                           -- AGGREGATE  |LOCAL|
+                                            nested tuple source
                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- SORT_GROUP_BY[$$166]  |PARTITIONED|
+                                  exchange
                                   -- HASH_PARTITION_EXCHANGE [$$166]  |PARTITIONED|
-                                    -- SORT_GROUP_BY[$$phone_substr]  |PARTITIONED|
-                                            {
+                                    group by ([$$166 := $$phone_substr]) decor ([]) {
+                                              aggregate [$$164, $$165] <- [agg-count($$134), agg-local-sum($$155)]
                                               -- AGGREGATE  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                            }
+                                           }
+                                    -- SORT_GROUP_BY[$$phone_substr]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$134, $$155, $$phone_substr])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$134] <- [{"ct": $$125}]
                                           -- ASSIGN  |PARTITIONED|
+                                            project ([$$phone_substr, $$155, $$125])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              select (eq($$149, 0))
                                               -- STREAM_SELECT  |PARTITIONED|
+                                                project ([$$149, $$phone_substr, $$155, $$125])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- SORT_GROUP_BY[$$163]  |PARTITIONED|
-                                                            {
+                                                    group by ([$$161 := $$163]) decor ([$$phone_substr; $$155; $$125]) {
+                                                              aggregate [$$149] <- [agg-sum($$162)]
                                                               -- AGGREGATE  |LOCAL|
+                                                                nested tuple source
                                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                            }
+                                                           }
+                                                    -- SORT_GROUP_BY[$$163]  |PARTITIONED|
+                                                      exchange
                                                       -- HASH_PARTITION_EXCHANGE [$$163]  |PARTITIONED|
-                                                        -- PRE_CLUSTERED_GROUP_BY[$$159]  |PARTITIONED|
-                                                                {
+                                                        group by ([$$163 := $$159]) decor ([$$phone_substr; $$155; $$125]) {
+                                                                  aggregate [$$162] <- [agg-count($$o)]
                                                                   -- AGGREGATE  |LOCAL|
+                                                                    select (not(is-missing($$160)))
                                                                     -- STREAM_SELECT  |LOCAL|
+                                                                      nested tuple source
                                                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                }
+                                                               }
+                                                        -- PRE_CLUSTERED_GROUP_BY[$$159]  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            order (ASC, $$159)
                                                             -- STABLE_SORT [$$159(ASC)]  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                project ([$$155, $$phone_substr, $$125, $$o, $$160, $$159])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    left outer join (eq($$146, $$153))
                                                                     -- HYBRID_HASH_JOIN [$$146][$$153]  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        running-aggregate [$$159] <- [create-query-uid()]
                                                                         -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                                          assign [$$125] <- [{"c_acctbal": $$155, "c_custkey": $$146, "cntrycode": $$phone_substr}]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            project ([$$155, $$phone_substr, $$146])
                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                join (eq($$148, $$phone_substr))
                                                                                 -- HYBRID_HASH_JOIN [$$phone_substr][$$148]  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    project ([$$155, $$phone_substr, $$146])
                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                      assign [$$phone_substr, $$155] <- [substring($$c.getField(4), 0, 2), $$c.getField(5)]
                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                        exchange
                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                          -- DATASOURCE_SCAN (tpch.Customer)  |PARTITIONED|
+                                                                                          data-scan []<-[$$146, $$c] <- tpch.Customer
+                                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                            exchange
                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                              empty-tuple-source
                                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                    unnest $$148 <- scan-collection(array: [ "23", "13", "17", "29", "18", "30", "31" ])
                                                                                     -- UNNEST  |UNPARTITIONED|
+                                                                                      empty-tuple-source
                                                                                       -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                                                      exchange
                                                                       -- HASH_PARTITION_EXCHANGE [$$153]  |PARTITIONED|
+                                                                        assign [$$160, $$153] <- [true, $$o.getField(1)]
                                                                         -- ASSIGN  |PARTITIONED|
+                                                                          project ([$$o])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                              -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                                                                              data-scan []<-[$$147, $$o] <- tpch.Orders
+                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  empty-tuple-source
                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-issue601.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-issue601.plan
index 2996ded..1987d41 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-issue601.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query-issue601.plan
@@ -1,22 +1,38 @@
+distribute result [$$43]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$43])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$43] <- [{"l_linenumber": $$l_linenumber, "count_order": $$47}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- SORT_GROUP_BY[$$49]  |PARTITIONED|
-                  {
+          group by ([$$l_linenumber := $$49]) decor ([]) {
+                    aggregate [$$47] <- [agg-sql-sum($$48)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- SORT_GROUP_BY[$$49]  |PARTITIONED|
+            exchange
             -- HASH_PARTITION_EXCHANGE [$$49]  |PARTITIONED|
-              -- SORT_GROUP_BY[$$46]  |PARTITIONED|
-                      {
+              group by ([$$49 := $$46]) decor ([]) {
+                        aggregate [$$48] <- [agg-sql-count(1)]
                         -- AGGREGATE  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SORT_GROUP_BY[$$46]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$46])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
+                      data-scan []<-[$$45, $$46, $$l] <- tpch.LineItem
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query_issue3316.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query_issue3316.plan
index 630cb14..eb9df9a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query_issue3316.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query_issue3316.plan
@@ -1,1000 +1,1955 @@
+distribute result [$$186]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    distinct ([$$186])
     -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$186)
         -- STABLE_SORT [$$186(ASC)]  |PARTITIONED|
+          exchange
           -- HASH_PARTITION_EXCHANGE [$$186]  |PARTITIONED|
+            project ([$$186])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$186] <- [object-concat-strict(if-missing-or-null(to-object($$108), cast({  })), {"sub_query1": $$150, "sub_query2": $$185})]
               -- ASSIGN  |PARTITIONED|
+                project ([$$185, $$150, $$108])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- PRE_CLUSTERED_GROUP_BY[$$221]  |PARTITIONED|
-                            {
+                    group by ([$$312 := $$221]) decor ([$$150; $$108]) {
+                              aggregate [$$185] <- [listify($$184)]
                               -- AGGREGATE  |LOCAL|
+                                select (not(is-missing($$311)))
                                 -- STREAM_SELECT  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                            }
+                           }
+                    -- PRE_CLUSTERED_GROUP_BY[$$221]  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        order (ASC, $$221)
                         -- STABLE_SORT [$$221(ASC)]  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$108, $$150, $$184, $$311, $$221])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                left outer join (eq($$221, $$382))
                                 -- HYBRID_HASH_JOIN [$$221][$$382]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- PRE_CLUSTERED_GROUP_BY[$$187]  |PARTITIONED|
-                                            {
+                                    group by ([$$221 := $$187]) decor ([$$108]) {
+                                              aggregate [$$150] <- [listify($$149)]
                                               -- AGGREGATE  |LOCAL|
+                                                select (not(is-missing($$220)))
                                                 -- STREAM_SELECT  |LOCAL|
+                                                  nested tuple source
                                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                            }
+                                           }
+                                    -- PRE_CLUSTERED_GROUP_BY[$$187]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$108, $$149, $$220, $$187])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            left outer join (eq($$187, $$234))
                                             -- HYBRID_HASH_JOIN [$$187][$$234]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$108, $$187])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$108] <- [{"x_id": $$T0.getField("x_id")}]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                      data-scan []<-[$$187, $$T0] <- test.collection0
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                              exchange
                                               -- HASH_PARTITION_EXCHANGE [$$234]  |PARTITIONED|
+                                                project ([$$149, $$220, $$234])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$220, $$149] <- [true, {"u": $$207}]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$234, $$207])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        join (eq($$193, $$120))
                                                         -- HYBRID_HASH_JOIN [$$120][$$193]  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            project ([$$234, $$207, $$120])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              select ($$145)
                                                               -- STREAM_SELECT  |PARTITIONED|
+                                                                project ([$$145, $$234, $$120, $$207])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- PRE_CLUSTERED_GROUP_BY[$$219, $$188]  |PARTITIONED|
-                                                                            {
+                                                                    group by ([$$234 := $$219; $$235 := $$188]) decor ([$$120; $$207]) {
+                                                                              aggregate [$$145] <- [non-empty-stream()]
                                                                               -- AGGREGATE  |LOCAL|
+                                                                                select (not(is-missing($$233)))
                                                                                 -- STREAM_SELECT  |LOCAL|
+                                                                                  nested tuple source
                                                                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                            }
+                                                                           }
+                                                                    -- PRE_CLUSTERED_GROUP_BY[$$219, $$188]  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        order (ASC, $$219) (ASC, $$188)
                                                                         -- STABLE_SORT [$$219(ASC), $$188(ASC)]  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            project ([$$207, $$120, $$233, $$219, $$188])
                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                left outer join (and(eq($$219, $$248), eq($$188, $$249)))
                                                                                 -- HYBRID_HASH_JOIN [$$219, $$188][$$248, $$249]  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- HASH_PARTITION_EXCHANGE [$$219, $$188]  |PARTITIONED|
+                                                                                    project ([$$207, $$120, $$219, $$188])
                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                        join (eq($$201, $$217))
                                                                                         -- HYBRID_HASH_JOIN [$$217][$$201]  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                            project ([$$219, $$217])
                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                              assign [$$219, $$217] <- [$$403, $$408]
                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                exchange
                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                  replicate
                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                    exchange
                                                                                                     -- HASH_PARTITION_EXCHANGE [$$408]  |PARTITIONED|
+                                                                                                      project ([$$408, $$403])
                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                        assign [$$408, $$403] <- [$$385, $$393]
                                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                                          exchange
                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                            replicate
                                                                                                             -- REPLICATE  |PARTITIONED|
+                                                                                                              exchange
                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                project ([$$385, $$393])
                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                  assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                    exchange
                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                      -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                      data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                        exchange
                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                          empty-tuple-source
                                                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- HASH_PARTITION_EXCHANGE [$$201]  |PARTITIONED|
+                                                                                            project ([$$207, $$120, $$188, $$201])
                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                              select (eq($$H.getField("to_u"), "aaaaa"))
                                                                                               -- STREAM_SELECT  |PARTITIONED|
+                                                                                                assign [$$207, $$120, $$201] <- [$$H.getField("u"), $$H.getField("a"), $$H.getField("y_id")]
                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                  project ([$$188, $$H])
                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                    assign [$$188, $$H] <- [$$405, $$411]
                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                      exchange
                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                        replicate
                                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                                          exchange
                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                            -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                            data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                              exchange
                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                empty-tuple-source
                                                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    assign [$$233] <- [true]
                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                      project ([$$248, $$249])
                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                        select (eq($$227, $#7))
                                                                                         -- STREAM_SELECT  |PARTITIONED|
+                                                                                          project ([$$248, $$249, $$227, $#7])
                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                            unnest $#7 <- scan-collection($$142)
                                                                                             -- UNNEST  |PARTITIONED|
+                                                                                              exchange
                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                -- PRE_CLUSTERED_GROUP_BY[$$232, $$229]  |PARTITIONED|
-                                                                                                        {
+                                                                                                group by ([$$248 := $$232; $$249 := $$229]) decor ([$$227]) {
+                                                                                                          aggregate [$$142] <- [listify($$197)]
                                                                                                           -- AGGREGATE  |LOCAL|
+                                                                                                            aggregate [$$197] <- [agg-sql-max($$139)]
                                                                                                             -- AGGREGATE  |LOCAL|
+                                                                                                              select (not(is-missing($$247)))
                                                                                                               -- STREAM_SELECT  |LOCAL|
+                                                                                                                nested tuple source
                                                                                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                        }
+                                                                                                       }
+                                                                                                -- PRE_CLUSTERED_GROUP_BY[$$232, $$229]  |PARTITIONED|
+                                                                                                  exchange
                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                    order (ASC, $$232) (ASC, $$229)
                                                                                                     -- STABLE_SORT [$$232(ASC), $$229(ASC)]  |PARTITIONED|
+                                                                                                      exchange
                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                        project ([$$227, $$139, $$247, $$232, $$229])
                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                          exchange
                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                            left outer join (and(eq($$232, $$246), eq($$229, $$243)))
                                                                                                             -- HYBRID_HASH_JOIN [$$232, $$229][$$246, $$243]  |PARTITIONED|
+                                                                                                              exchange
                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                project ([$$227, $$232, $$229])
                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                  assign [$$227, $$232, $$229] <- [$$416, $$419, $$420]
                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                    exchange
                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                      replicate
                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                        exchange
                                                                                                                         -- HASH_PARTITION_EXCHANGE [$$419, $$420]  |PARTITIONED|
+                                                                                                                          project ([$$416, $$419, $$420])
                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                            exchange
                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                              join (eq($$427, $$428))
                                                                                                                               -- HYBRID_HASH_JOIN [$$428][$$427]  |PARTITIONED|
+                                                                                                                                exchange
                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                  project ([$$419, $$428])
                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                    assign [$$419, $$428] <- [$$403, $$408]
                                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                                      exchange
                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                        replicate
                                                                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                                                                          exchange
                                                                                                                                           -- HASH_PARTITION_EXCHANGE [$$408]  |PARTITIONED|
+                                                                                                                                            project ([$$408, $$403])
                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                              assign [$$408, $$403] <- [$$385, $$393]
                                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                                exchange
                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                  replicate
                                                                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                                                                    exchange
                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                      project ([$$385, $$393])
                                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                        assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                                                                                          exchange
                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                            -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                                                            data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                              exchange
                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                empty-tuple-source
                                                                                                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                exchange
                                                                                                                                 -- HASH_PARTITION_EXCHANGE [$$427]  |PARTITIONED|
+                                                                                                                                  project ([$$416, $$420, $$427])
                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                    select (eq($$422.getField("to_u"), "aaaaa"))
                                                                                                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                      exchange
                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                        replicate
                                                                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                                                                          exchange
                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                            assign [$$427, $$416] <- [$$422.getField("y_id"), $$422.getField("b")]
                                                                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                                                                              project ([$$420, $$422])
                                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                assign [$$420, $$422] <- [$$405, $$411]
                                                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                                                  exchange
                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                    replicate
                                                                                                                                                     -- REPLICATE  |PARTITIONED|
+                                                                                                                                                      exchange
                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                        -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                        data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                          exchange
                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                            empty-tuple-source
                                                                                                                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                              exchange
                                                                                                               -- HASH_PARTITION_EXCHANGE [$$246, $$243]  |PARTITIONED|
+                                                                                                                assign [$$247] <- [true]
                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                  project ([$$139, $$246, $$243])
                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                    exchange
                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                      join (eq($$192, $$129))
                                                                                                                       -- HYBRID_HASH_JOIN [$$129][$$192]  |PARTITIONED|
+                                                                                                                        exchange
                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                          project ([$$139, $$246, $$243, $$129])
                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                            exchange
                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                              join (eq($$204, $$237))
                                                                                                                               -- HYBRID_HASH_JOIN [$$237][$$204]  |PARTITIONED|
+                                                                                                                                exchange
                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                  project ([$$246, $$243, $$237])
                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                    assign [$$246, $$243, $$237] <- [$$429, $$430, $$439]
                                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                                      exchange
                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                        replicate
                                                                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                                                                          exchange
                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                            project ([$$429, $$430, $$439])
                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                              exchange
                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                join (eq($$442, $$439))
                                                                                                                                                 -- HYBRID_HASH_JOIN [$$439][$$442]  |PARTITIONED|
+                                                                                                                                                  exchange
                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                    project ([$$429, $$439])
                                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                      assign [$$429, $$439] <- [$$403, $$408]
                                                                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                                                                        exchange
                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                          replicate
                                                                                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                                                                                            exchange
                                                                                                                                                             -- HASH_PARTITION_EXCHANGE [$$408]  |PARTITIONED|
+                                                                                                                                                              project ([$$408, $$403])
                                                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                assign [$$408, $$403] <- [$$385, $$393]
                                                                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                  exchange
                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                    replicate
                                                                                                                                                                     -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                      exchange
                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                        project ([$$385, $$393])
                                                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                          assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                            exchange
                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                              -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                                                                              data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                exchange
                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                  empty-tuple-source
                                                                                                                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                  exchange
                                                                                                                                                   -- HASH_PARTITION_EXCHANGE [$$442]  |PARTITIONED|
+                                                                                                                                                    project ([$$430, $$442])
                                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                      select (eq($$444.getField("to_u"), "aaaaa"))
                                                                                                                                                       -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                        exchange
                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                          replicate
                                                                                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                                                                                            exchange
                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                              assign [$$442] <- [$$444.getField("y_id")]
                                                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                project ([$$430, $$444])
                                                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                  assign [$$430, $$444] <- [$$405, $$411]
                                                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                    exchange
                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                      replicate
                                                                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                        exchange
                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                          -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                                          data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                            exchange
                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                              empty-tuple-source
                                                                                                                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                exchange
                                                                                                                                 -- HASH_PARTITION_EXCHANGE [$$204]  |PARTITIONED|
+                                                                                                                                  project ([$$139, $$129, $$204])
                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                    select (eq($$L.getField("to_u"), "aaaaa"))
                                                                                                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                      assign [$$129, $$204, $$139] <- [$$L.getField("a"), $$L.getField("y_id"), $$L.getField("b")]
                                                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                                                        project ([$$L])
                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                          assign [$$L] <- [$$435]
                                                                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                                                                            exchange
                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                              replicate
                                                                                                                                               -- REPLICATE  |PARTITIONED|
+                                                                                                                                                exchange
                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                  project ([$$435])
                                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                    assign [$$441, $$435] <- [$$405, $$411]
                                                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                                                      exchange
                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                        replicate
                                                                                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                                                                                          exchange
                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                            -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                            data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                              exchange
                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                empty-tuple-source
                                                                                                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                        exchange
                                                                                                                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                                                          unnest $$192 <- scan-collection(array: [ 66, 67, 26, 12, 13 ])
                                                                                                                           -- UNNEST  |UNPARTITIONED|
+                                                                                                                            empty-tuple-source
                                                                                                                             -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                                          exchange
                                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                            unnest $$193 <- scan-collection(array: [ 66, 67, 26, 12, 13 ])
                                                             -- UNNEST  |UNPARTITIONED|
+                                                              empty-tuple-source
                                                               -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                  exchange
                                   -- HASH_PARTITION_EXCHANGE [$$382]  |PARTITIONED|
+                                    project ([$$184, $$311, $$382])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$311, $$184] <- [true, {"u": $$213}]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$382, $$213])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            join (eq($$196, $$156))
                                             -- HYBRID_HASH_JOIN [$$156][$$196]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$382, $$213, $$156])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    join (eq($$195, $$159))
                                                     -- HYBRID_HASH_JOIN [$$159][$$195]  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        project ([$$382, $$213, $$156, $$159])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          select ($$180)
                                                           -- STREAM_SELECT  |PARTITIONED|
+                                                            project ([$$180, $$382, $$213, $$156, $$159])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- PRE_CLUSTERED_GROUP_BY[$$250, $$190]  |PARTITIONED|
-                                                                        {
+                                                                group by ([$$382 := $$250; $$383 := $$190]) decor ([$$213; $$156; $$159]) {
+                                                                          aggregate [$$180] <- [non-empty-stream()]
                                                                           -- AGGREGATE  |LOCAL|
+                                                                            select (not(is-missing($$381)))
                                                                             -- STREAM_SELECT  |LOCAL|
+                                                                              nested tuple source
                                                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                        }
+                                                                       }
+                                                                -- PRE_CLUSTERED_GROUP_BY[$$250, $$190]  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    order (ASC, $$250) (ASC, $$190)
                                                                     -- STABLE_SORT [$$250(ASC), $$190(ASC)]  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        project ([$$213, $$156, $$159, $$381, $$250, $$190])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            left outer join (and(eq($$250, $$453), eq($$190, $$454)))
                                                                             -- HYBRID_HASH_JOIN [$$250, $$190][$$453, $$454]  |PARTITIONED|
+                                                                              exchange
                                                                               -- HASH_PARTITION_EXCHANGE [$$250, $$190]  |PARTITIONED|
+                                                                                project ([$$213, $$156, $$159, $$250, $$190])
                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    join (eq($$208, $$252))
                                                                                     -- HYBRID_HASH_JOIN [$$252][$$208]  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- HASH_PARTITION_EXCHANGE [$$252]  |PARTITIONED|
-                                                                                        -- PRE_CLUSTERED_GROUP_BY[$$251]  |PARTITIONED|
-                                                                                                {
+                                                                                        group by ([$$250 := $$251]) decor ([$$252]) {
+                                                                                                  aggregate [] <- []
                                                                                                   -- AGGREGATE  |LOCAL|
+                                                                                                    select (not(is-missing($$256)))
                                                                                                     -- STREAM_SELECT  |LOCAL|
+                                                                                                      nested tuple source
                                                                                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                }
+                                                                                               }
+                                                                                        -- PRE_CLUSTERED_GROUP_BY[$$251]  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                            project ([$$252, $$256, $$251])
                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                              exchange
                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                left outer join (eq($$251, $$255))
                                                                                                 -- HYBRID_HASH_JOIN [$$251][$$255]  |PARTITIONED|
+                                                                                                  exchange
                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                    project ([$$252, $$251])
                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                      assign [$$252, $$251] <- [$$385, $$393]
                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                        exchange
                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                          replicate
                                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                                            exchange
                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                              replicate
                                                                                                               -- REPLICATE  |PARTITIONED|
+                                                                                                                exchange
                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                  project ([$$385, $$393])
                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                    assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                      exchange
                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                        -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                        data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                          exchange
                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                            empty-tuple-source
                                                                                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                  exchange
                                                                                                   -- HASH_PARTITION_EXCHANGE [$$255]  |PARTITIONED|
+                                                                                                    assign [$$256] <- [true]
                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                      project ([$$255])
                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                        exchange
                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                          join (eq($$259, $$260))
                                                                                                           -- HYBRID_HASH_JOIN [$$260][$$259]  |PARTITIONED|
+                                                                                                            exchange
                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                              project ([$$255, $$260])
                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                select ($$261)
                                                                                                                 -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                  project ([$$261, $$255, $$260])
                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                    exchange
                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                      -- PRE_CLUSTERED_GROUP_BY[$$262, $$264]  |PARTITIONED|
-                                                                                                                              {
+                                                                                                                      group by ([$$255 := $$262; $$263 := $$264]) decor ([$$260]) {
+                                                                                                                                aggregate [$$261] <- [non-empty-stream()]
                                                                                                                                 -- AGGREGATE  |LOCAL|
+                                                                                                                                  select (not(is-missing($$274)))
                                                                                                                                   -- STREAM_SELECT  |LOCAL|
+                                                                                                                                    nested tuple source
                                                                                                                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                                              }
+                                                                                                                             }
+                                                                                                                      -- PRE_CLUSTERED_GROUP_BY[$$262, $$264]  |PARTITIONED|
+                                                                                                                        exchange
                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                          order (ASC, $$262) (ASC, $$264)
                                                                                                                           -- STABLE_SORT [$$262(ASC), $$264(ASC)]  |PARTITIONED|
+                                                                                                                            exchange
                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                              project ([$$260, $$274, $$262, $$264])
                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                exchange
                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                  left outer join (and(eq($$262, $$272), eq($$264, $$273)))
                                                                                                                                   -- HYBRID_HASH_JOIN [$$262, $$264][$$272, $$273]  |PARTITIONED|
+                                                                                                                                    exchange
                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                      project ([$$260, $$262, $$264])
                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                        assign [$$260, $$262, $$264] <- [$$401, $$403, $$405]
                                                                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                                                                          exchange
                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                            replicate
                                                                                                                                             -- REPLICATE  |PARTITIONED|
+                                                                                                                                              exchange
                                                                                                                                               -- HASH_PARTITION_EXCHANGE [$$403, $$405]  |PARTITIONED|
+                                                                                                                                                project ([$$401, $$403, $$405])
                                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                  exchange
                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                    join (eq($$409, $$408))
                                                                                                                                                     -- HYBRID_HASH_JOIN [$$408][$$409]  |PARTITIONED|
+                                                                                                                                                      exchange
                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                        replicate
                                                                                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                                                                                          exchange
                                                                                                                                                           -- HASH_PARTITION_EXCHANGE [$$408]  |PARTITIONED|
+                                                                                                                                                            project ([$$408, $$403])
                                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                              assign [$$408, $$403] <- [$$385, $$393]
                                                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                exchange
                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                  replicate
                                                                                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                    exchange
                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                      project ([$$385, $$393])
                                                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                        assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                          exchange
                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                            -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                                                                            data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                              exchange
                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                empty-tuple-source
                                                                                                                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                      exchange
                                                                                                                                                       -- HASH_PARTITION_EXCHANGE [$$409]  |PARTITIONED|
+                                                                                                                                                        project ([$$401, $$405, $$409])
                                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                          select (eq($$411.getField("to_u"), "aaaaa"))
                                                                                                                                                           -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                            assign [$$409, $$401] <- [$$411.getField("y_id"), $$411.getField("a")]
                                                                                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                                                                                              exchange
                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                replicate
                                                                                                                                                                 -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                  exchange
                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                    -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                                    data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                      exchange
                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                        empty-tuple-source
                                                                                                                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                    exchange
                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                      assign [$$274] <- [true]
                                                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                                                        project ([$$272, $$273])
                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                          select (eq($$275, $$276))
                                                                                                                                           -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                            project ([$$272, $$273, $$275, $$276])
                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                              unnest $$276 <- scan-collection($$277)
                                                                                                                                               -- UNNEST  |PARTITIONED|
+                                                                                                                                                exchange
                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                  -- PRE_CLUSTERED_GROUP_BY[$$278, $$279]  |PARTITIONED|
-                                                                                                                                                          {
+                                                                                                                                                  group by ([$$272 := $$278; $$273 := $$279]) decor ([$$275]) {
+                                                                                                                                                            aggregate [$$277] <- [listify($$309)]
                                                                                                                                                             -- AGGREGATE  |LOCAL|
+                                                                                                                                                              aggregate [$$309] <- [agg-sql-max($$291)]
                                                                                                                                                               -- AGGREGATE  |LOCAL|
+                                                                                                                                                                select (not(is-missing($$290)))
                                                                                                                                                                 -- STREAM_SELECT  |LOCAL|
+                                                                                                                                                                  nested tuple source
                                                                                                                                                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                                                                          }
+                                                                                                                                                         }
+                                                                                                                                                  -- PRE_CLUSTERED_GROUP_BY[$$278, $$279]  |PARTITIONED|
+                                                                                                                                                    exchange
                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                      order (ASC, $$278) (ASC, $$279)
                                                                                                                                                       -- STABLE_SORT [$$278(ASC), $$279(ASC)]  |PARTITIONED|
+                                                                                                                                                        exchange
                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                          project ([$$275, $$291, $$290, $$278, $$279])
                                                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                            exchange
                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                              left outer join (and(eq($$278, $$288), eq($$279, $$289)))
                                                                                                                                                               -- HYBRID_HASH_JOIN [$$278, $$279][$$288, $$289]  |PARTITIONED|
+                                                                                                                                                                exchange
                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                  project ([$$275, $$278, $$279])
                                                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                    assign [$$275, $$278, $$279] <- [$$416, $$419, $$420]
                                                                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                      exchange
                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                        replicate
                                                                                                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                          exchange
                                                                                                                                                                           -- HASH_PARTITION_EXCHANGE [$$419, $$420]  |PARTITIONED|
+                                                                                                                                                                            project ([$$416, $$419, $$420])
                                                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                              exchange
                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                join (eq($$427, $$428))
                                                                                                                                                                                 -- HYBRID_HASH_JOIN [$$428][$$427]  |PARTITIONED|
+                                                                                                                                                                                  exchange
                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                    project ([$$419, $$428])
                                                                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                      assign [$$419, $$428] <- [$$403, $$408]
                                                                                                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                        exchange
                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                          replicate
                                                                                                                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                            exchange
                                                                                                                                                                                             -- HASH_PARTITION_EXCHANGE [$$408]  |PARTITIONED|
+                                                                                                                                                                                              project ([$$408, $$403])
                                                                                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                assign [$$408, $$403] <- [$$385, $$393]
                                                                                                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                  exchange
                                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                    replicate
                                                                                                                                                                                                     -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                      exchange
                                                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                        project ([$$385, $$393])
                                                                                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                          assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                            exchange
                                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                              -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                                                                                                              data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                                                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                exchange
                                                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                  empty-tuple-source
                                                                                                                                                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                                  exchange
                                                                                                                                                                                   -- HASH_PARTITION_EXCHANGE [$$427]  |PARTITIONED|
+                                                                                                                                                                                    project ([$$416, $$420, $$427])
                                                                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                      select (eq($$422.getField("to_u"), "aaaaa"))
                                                                                                                                                                                       -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                                                        exchange
                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                          replicate
                                                                                                                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                            exchange
                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                              assign [$$427, $$416] <- [$$422.getField("y_id"), $$422.getField("b")]
                                                                                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                project ([$$420, $$422])
                                                                                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                  assign [$$420, $$422] <- [$$405, $$411]
                                                                                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                    exchange
                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                      replicate
                                                                                                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                        exchange
                                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                          -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                                                                          data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                            exchange
                                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                              empty-tuple-source
                                                                                                                                                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                exchange
                                                                                                                                                                 -- HASH_PARTITION_EXCHANGE [$$288, $$289]  |PARTITIONED|
+                                                                                                                                                                  assign [$$290] <- [true]
                                                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                    project ([$$291, $$288, $$289])
                                                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                      exchange
                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                        join (eq($$295, $$296))
                                                                                                                                                                         -- HYBRID_HASH_JOIN [$$296][$$295]  |PARTITIONED|
+                                                                                                                                                                          exchange
                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                            project ([$$291, $$288, $$289, $$296])
                                                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                              exchange
                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                join (eq($$297, $$298))
                                                                                                                                                                                 -- HYBRID_HASH_JOIN [$$298][$$297]  |PARTITIONED|
+                                                                                                                                                                                  exchange
                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                    project ([$$288, $$289, $$298])
                                                                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                      assign [$$288, $$289, $$298] <- [$$429, $$430, $$439]
                                                                                                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                        exchange
                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                          replicate
                                                                                                                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                            exchange
                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                              project ([$$429, $$430, $$439])
                                                                                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                exchange
                                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                  join (eq($$442, $$439))
                                                                                                                                                                                                   -- HYBRID_HASH_JOIN [$$439][$$442]  |PARTITIONED|
+                                                                                                                                                                                                    exchange
                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                      project ([$$429, $$439])
                                                                                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                        assign [$$429, $$439] <- [$$403, $$408]
                                                                                                                                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                          exchange
                                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                            replicate
                                                                                                                                                                                                             -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                              exchange
                                                                                                                                                                                                               -- HASH_PARTITION_EXCHANGE [$$408]  |PARTITIONED|
+                                                                                                                                                                                                                project ([$$408, $$403])
                                                                                                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                  assign [$$408, $$403] <- [$$385, $$393]
                                                                                                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                      replicate
                                                                                                                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                        exchange
                                                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                          project ([$$385, $$393])
                                                                                                                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                            assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                                                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                              exchange
                                                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                                                -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                                                                                                                                data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                                                                                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                                  exchange
                                                                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                    empty-tuple-source
                                                                                                                                                                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                                                    exchange
                                                                                                                                                                                                     -- HASH_PARTITION_EXCHANGE [$$442]  |PARTITIONED|
+                                                                                                                                                                                                      project ([$$430, $$442])
                                                                                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                        select (eq($$444.getField("to_u"), "aaaaa"))
                                                                                                                                                                                                         -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                                                                          exchange
                                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                            replicate
                                                                                                                                                                                                             -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                              exchange
                                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                assign [$$442] <- [$$444.getField("y_id")]
                                                                                                                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                  project ([$$430, $$444])
                                                                                                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                    assign [$$430, $$444] <- [$$405, $$411]
                                                                                                                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                      exchange
                                                                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                        replicate
                                                                                                                                                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                          exchange
                                                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                                            -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                                                                                            data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                                                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                              exchange
                                                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                empty-tuple-source
                                                                                                                                                                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                                  exchange
                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                    project ([$$291, $$296, $$297])
                                                                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                      assign [$$291, $$296, $$297] <- [$$432, $$437, $$438]
                                                                                                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                        exchange
                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                          replicate
                                                                                                                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                            exchange
                                                                                                                                                                                             -- HASH_PARTITION_EXCHANGE [$$438]  |PARTITIONED|
+                                                                                                                                                                                              project ([$$432, $$437, $$438])
                                                                                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                select (eq($$435.getField("to_u"), "aaaaa"))
                                                                                                                                                                                                 -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                                                                  assign [$$438, $$437, $$432] <- [$$435.getField("y_id"), $$435.getField("a"), $$435.getField("b")]
                                                                                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                    exchange
                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                      replicate
                                                                                                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                        exchange
                                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                          project ([$$435])
                                                                                                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                            assign [$$441, $$435] <- [$$405, $$411]
                                                                                                                                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                              exchange
                                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                replicate
                                                                                                                                                                                                                 -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                  exchange
                                                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                                    -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                                                                                    data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                                                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                      exchange
                                                                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                        empty-tuple-source
                                                                                                                                                                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                          exchange
                                                                                                                                                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                            unnest $$295 <- scan-collection(array: [ 66, 67, 26, 12, 13 ])
                                                                                                                                                                             -- UNNEST  |UNPARTITIONED|
+                                                                                                                                                                              empty-tuple-source
                                                                                                                                                                               -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                                                                                            exchange
                                                                                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                                              unnest $$259 <- scan-collection(array: [ 66, 67, 26, 12, 13 ])
                                                                                                               -- UNNEST  |UNPARTITIONED|
+                                                                                                                empty-tuple-source
                                                                                                                 -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                                                                      exchange
                                                                                       -- HASH_PARTITION_EXCHANGE [$$208]  |PARTITIONED|
+                                                                                        project ([$$213, $$156, $$159, $$190, $$208])
                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                          assign [$$213, $$159, $$156, $$208] <- [$$H.getField("u"), $$H.getField("posi"), $$H.getField("a"), $$H.getField("y_id")]
                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                            project ([$$190, $$H])
                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                              assign [$$190, $$H] <- [$$405, $$411]
                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                exchange
                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                  replicate
                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                    exchange
                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                      -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                      data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                        exchange
                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                          empty-tuple-source
                                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                assign [$$381] <- [true]
                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                  project ([$$453, $$454])
                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                    select (eq($$318, $#11))
                                                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                                                      project ([$$453, $$454, $$318, $#11])
                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                        unnest $#11 <- scan-collection($$177)
                                                                                         -- UNNEST  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                            -- PRE_CLUSTERED_GROUP_BY[$$321, $$320]  |PARTITIONED|
-                                                                                                    {
+                                                                                            group by ([$$453 := $$321; $$454 := $$320]) decor ([$$318]) {
+                                                                                                      aggregate [$$177] <- [listify($$198)]
                                                                                                       -- AGGREGATE  |LOCAL|
+                                                                                                        aggregate [$$198] <- [agg-sql-max($$174)]
                                                                                                         -- AGGREGATE  |LOCAL|
+                                                                                                          select (not(is-missing($$452)))
                                                                                                           -- STREAM_SELECT  |LOCAL|
+                                                                                                            nested tuple source
                                                                                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                    }
+                                                                                                   }
+                                                                                            -- PRE_CLUSTERED_GROUP_BY[$$321, $$320]  |PARTITIONED|
+                                                                                              exchange
                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                order (ASC, $$321) (ASC, $$320)
                                                                                                 -- STABLE_SORT [$$321(ASC), $$320(ASC)]  |PARTITIONED|
+                                                                                                  exchange
                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                    project ([$$318, $$174, $$452, $$321, $$320])
                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                      exchange
                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                        left outer join (and(eq($$321, $$392), eq($$320, $$391)))
                                                                                                         -- HYBRID_HASH_JOIN [$$321, $$320][$$392, $$391]  |PARTITIONED|
+                                                                                                          exchange
                                                                                                           -- HASH_PARTITION_EXCHANGE [$$321, $$320]  |PARTITIONED|
+                                                                                                            project ([$$318, $$321, $$320])
                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                              exchange
                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                join (eq($$313, $$314))
                                                                                                                 -- HYBRID_HASH_JOIN [$$314][$$313]  |PARTITIONED|
+                                                                                                                  exchange
                                                                                                                   -- HASH_PARTITION_EXCHANGE [$$314]  |PARTITIONED|
-                                                                                                                    -- PRE_CLUSTERED_GROUP_BY[$$322]  |PARTITIONED|
-                                                                                                                            {
+                                                                                                                    group by ([$$321 := $$322]) decor ([$$314]) {
+                                                                                                                              aggregate [] <- []
                                                                                                                               -- AGGREGATE  |LOCAL|
+                                                                                                                                select (not(is-missing($$326)))
                                                                                                                                 -- STREAM_SELECT  |LOCAL|
+                                                                                                                                  nested tuple source
                                                                                                                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                                            }
+                                                                                                                           }
+                                                                                                                    -- PRE_CLUSTERED_GROUP_BY[$$322]  |PARTITIONED|
+                                                                                                                      exchange
                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                        project ([$$314, $$326, $$322])
                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                          exchange
                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                            left outer join (eq($$322, $$325))
                                                                                                                             -- HYBRID_HASH_JOIN [$$322][$$325]  |PARTITIONED|
+                                                                                                                              exchange
                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                project ([$$314, $$322])
                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                  assign [$$314, $$322] <- [$$385, $$393]
                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                    exchange
                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                      replicate
                                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                                        exchange
                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                          replicate
                                                                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                                                                            exchange
                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                              project ([$$385, $$393])
                                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                                                  exchange
                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                    -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                                                    data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                      exchange
                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                        empty-tuple-source
                                                                                                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                              exchange
                                                                                                                               -- HASH_PARTITION_EXCHANGE [$$325]  |PARTITIONED|
+                                                                                                                                assign [$$326] <- [true]
                                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                                  project ([$$325])
                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                    exchange
                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                      join (eq($$329, $$330))
                                                                                                                                       -- HYBRID_HASH_JOIN [$$330][$$329]  |PARTITIONED|
+                                                                                                                                        exchange
                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                          project ([$$325, $$330])
                                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                            select ($$331)
                                                                                                                                             -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                              project ([$$331, $$325, $$330])
                                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                exchange
                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                  -- PRE_CLUSTERED_GROUP_BY[$$332, $$334]  |PARTITIONED|
-                                                                                                                                                          {
+                                                                                                                                                  group by ([$$325 := $$332; $$333 := $$334]) decor ([$$330]) {
+                                                                                                                                                            aggregate [$$331] <- [non-empty-stream()]
                                                                                                                                                             -- AGGREGATE  |LOCAL|
+                                                                                                                                                              select (not(is-missing($$344)))
                                                                                                                                                               -- STREAM_SELECT  |LOCAL|
+                                                                                                                                                                nested tuple source
                                                                                                                                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                                                                          }
+                                                                                                                                                         }
+                                                                                                                                                  -- PRE_CLUSTERED_GROUP_BY[$$332, $$334]  |PARTITIONED|
+                                                                                                                                                    exchange
                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                      order (ASC, $$332) (ASC, $$334)
                                                                                                                                                       -- STABLE_SORT [$$332(ASC), $$334(ASC)]  |PARTITIONED|
+                                                                                                                                                        exchange
                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                          project ([$$330, $$344, $$332, $$334])
                                                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                            exchange
                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                              left outer join (and(eq($$332, $$342), eq($$334, $$343)))
                                                                                                                                                               -- HYBRID_HASH_JOIN [$$332, $$334][$$342, $$343]  |PARTITIONED|
+                                                                                                                                                                exchange
                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                  project ([$$330, $$332, $$334])
                                                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                    assign [$$330, $$332, $$334] <- [$$401, $$403, $$405]
                                                                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                      exchange
                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                        replicate
                                                                                                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                          exchange
                                                                                                                                                                           -- HASH_PARTITION_EXCHANGE [$$403, $$405]  |PARTITIONED|
+                                                                                                                                                                            project ([$$401, $$403, $$405])
                                                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                              exchange
                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                join (eq($$409, $$408))
                                                                                                                                                                                 -- HYBRID_HASH_JOIN [$$408][$$409]  |PARTITIONED|
+                                                                                                                                                                                  exchange
                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                    replicate
                                                                                                                                                                                     -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                      exchange
                                                                                                                                                                                       -- HASH_PARTITION_EXCHANGE [$$408]  |PARTITIONED|
+                                                                                                                                                                                        project ([$$408, $$403])
                                                                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                          assign [$$408, $$403] <- [$$385, $$393]
                                                                                                                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                            exchange
                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                              replicate
                                                                                                                                                                                               -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                exchange
                                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                  project ([$$385, $$393])
                                                                                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                    assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                      exchange
                                                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                        -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                                                                                                        data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                                                                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                          exchange
                                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                            empty-tuple-source
                                                                                                                                                                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                                  exchange
                                                                                                                                                                                   -- HASH_PARTITION_EXCHANGE [$$409]  |PARTITIONED|
+                                                                                                                                                                                    project ([$$401, $$405, $$409])
                                                                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                      select (eq($$411.getField("to_u"), "aaaaa"))
                                                                                                                                                                                       -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                                                        assign [$$409, $$401] <- [$$411.getField("y_id"), $$411.getField("a")]
                                                                                                                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                          exchange
                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                            replicate
                                                                                                                                                                                             -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                              exchange
                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                                                                data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                  exchange
                                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                    empty-tuple-source
                                                                                                                                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                exchange
                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                  assign [$$344] <- [true]
                                                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                    project ([$$342, $$343])
                                                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                      select (eq($$345, $$346))
                                                                                                                                                                       -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                                        project ([$$342, $$343, $$345, $$346])
                                                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                          unnest $$346 <- scan-collection($$347)
                                                                                                                                                                           -- UNNEST  |PARTITIONED|
+                                                                                                                                                                            exchange
                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                              -- PRE_CLUSTERED_GROUP_BY[$$348, $$349]  |PARTITIONED|
-                                                                                                                                                                                      {
+                                                                                                                                                                              group by ([$$342 := $$348; $$343 := $$349]) decor ([$$345]) {
+                                                                                                                                                                                        aggregate [$$347] <- [listify($$379)]
                                                                                                                                                                                         -- AGGREGATE  |LOCAL|
+                                                                                                                                                                                          aggregate [$$379] <- [agg-sql-max($$361)]
                                                                                                                                                                                           -- AGGREGATE  |LOCAL|
+                                                                                                                                                                                            select (not(is-missing($$360)))
                                                                                                                                                                                             -- STREAM_SELECT  |LOCAL|
+                                                                                                                                                                                              nested tuple source
                                                                                                                                                                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                                                                                                      }
+                                                                                                                                                                                     }
+                                                                                                                                                                              -- PRE_CLUSTERED_GROUP_BY[$$348, $$349]  |PARTITIONED|
+                                                                                                                                                                                exchange
                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                  order (ASC, $$348) (ASC, $$349)
                                                                                                                                                                                   -- STABLE_SORT [$$348(ASC), $$349(ASC)]  |PARTITIONED|
+                                                                                                                                                                                    exchange
                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                      project ([$$345, $$361, $$360, $$348, $$349])
                                                                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                        exchange
                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                          left outer join (and(eq($$348, $$358), eq($$349, $$359)))
                                                                                                                                                                                           -- HYBRID_HASH_JOIN [$$348, $$349][$$358, $$359]  |PARTITIONED|
+                                                                                                                                                                                            exchange
                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                              project ([$$345, $$348, $$349])
                                                                                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                assign [$$345, $$348, $$349] <- [$$416, $$419, $$420]
                                                                                                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                  exchange
                                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                    replicate
                                                                                                                                                                                                     -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                      exchange
                                                                                                                                                                                                       -- HASH_PARTITION_EXCHANGE [$$419, $$420]  |PARTITIONED|
+                                                                                                                                                                                                        project ([$$416, $$419, $$420])
                                                                                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                          exchange
                                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                            join (eq($$427, $$428))
                                                                                                                                                                                                             -- HYBRID_HASH_JOIN [$$428][$$427]  |PARTITIONED|
+                                                                                                                                                                                                              exchange
                                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                project ([$$419, $$428])
                                                                                                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                  assign [$$419, $$428] <- [$$403, $$408]
                                                                                                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                      replicate
                                                                                                                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                        exchange
                                                                                                                                                                                                                         -- HASH_PARTITION_EXCHANGE [$$408]  |PARTITIONED|
+                                                                                                                                                                                                                          project ([$$408, $$403])
                                                                                                                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                            assign [$$408, $$403] <- [$$385, $$393]
                                                                                                                                                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                              exchange
                                                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                replicate
                                                                                                                                                                                                                                 -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                  exchange
                                                                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                    project ([$$385, $$393])
                                                                                                                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                      assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                                                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                        exchange
                                                                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                                                          -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                                                                                                                                          data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                                                                                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                                            exchange
                                                                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                              empty-tuple-source
                                                                                                                                                                                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                                                              exchange
                                                                                                                                                                                                               -- HASH_PARTITION_EXCHANGE [$$427]  |PARTITIONED|
+                                                                                                                                                                                                                project ([$$416, $$420, $$427])
                                                                                                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                  select (eq($$422.getField("to_u"), "aaaaa"))
                                                                                                                                                                                                                   -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                      replicate
                                                                                                                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                        exchange
                                                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                          assign [$$427, $$416] <- [$$422.getField("y_id"), $$422.getField("b")]
                                                                                                                                                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                            project ([$$420, $$422])
                                                                                                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                              assign [$$420, $$422] <- [$$405, $$411]
                                                                                                                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                exchange
                                                                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                  replicate
                                                                                                                                                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                                                      -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                                                                                                      data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                                                                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                                        exchange
                                                                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                          empty-tuple-source
                                                                                                                                                                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                                            exchange
                                                                                                                                                                                             -- HASH_PARTITION_EXCHANGE [$$358, $$359]  |PARTITIONED|
+                                                                                                                                                                                              assign [$$360] <- [true]
                                                                                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                project ([$$361, $$358, $$359])
                                                                                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                  exchange
                                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                    join (eq($$365, $$366))
                                                                                                                                                                                                     -- HYBRID_HASH_JOIN [$$366][$$365]  |PARTITIONED|
+                                                                                                                                                                                                      exchange
                                                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                        project ([$$361, $$358, $$359, $$366])
                                                                                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                          exchange
                                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                            join (eq($$367, $$368))
                                                                                                                                                                                                             -- HYBRID_HASH_JOIN [$$368][$$367]  |PARTITIONED|
+                                                                                                                                                                                                              exchange
                                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                project ([$$358, $$359, $$368])
                                                                                                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                  assign [$$358, $$359, $$368] <- [$$429, $$430, $$439]
                                                                                                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                      replicate
                                                                                                                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                        exchange
                                                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                          project ([$$429, $$430, $$439])
                                                                                                                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                            exchange
                                                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                              join (eq($$442, $$439))
                                                                                                                                                                                                                               -- HYBRID_HASH_JOIN [$$439][$$442]  |PARTITIONED|
+                                                                                                                                                                                                                                exchange
                                                                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                  project ([$$429, $$439])
                                                                                                                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                    assign [$$429, $$439] <- [$$403, $$408]
                                                                                                                                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                      exchange
                                                                                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                        replicate
                                                                                                                                                                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                          exchange
                                                                                                                                                                                                                                           -- HASH_PARTITION_EXCHANGE [$$408]  |PARTITIONED|
+                                                                                                                                                                                                                                            project ([$$408, $$403])
                                                                                                                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                              assign [$$408, $$403] <- [$$385, $$393]
                                                                                                                                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                                exchange
                                                                                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                  replicate
                                                                                                                                                                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                      project ([$$385, $$393])
                                                                                                                                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                                        assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                                                                                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                                          exchange
                                                                                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                                                                            -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                                                                                                                                                            data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                                                                                                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                                                              exchange
                                                                                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                                empty-tuple-source
                                                                                                                                                                                                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                                                                                exchange
                                                                                                                                                                                                                                 -- HASH_PARTITION_EXCHANGE [$$442]  |PARTITIONED|
+                                                                                                                                                                                                                                  project ([$$430, $$442])
                                                                                                                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                    select (eq($$444.getField("to_u"), "aaaaa"))
                                                                                                                                                                                                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                                                                                                      exchange
                                                                                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                        replicate
                                                                                                                                                                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                          exchange
                                                                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                            assign [$$442] <- [$$444.getField("y_id")]
                                                                                                                                                                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                              project ([$$430, $$444])
                                                                                                                                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                                assign [$$430, $$444] <- [$$405, $$411]
                                                                                                                                                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                                  exchange
                                                                                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                    replicate
                                                                                                                                                                                                                                                     -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                                      exchange
                                                                                                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                                                                        -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                                                                                                                        data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                                                                                                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                                                          exchange
                                                                                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                            empty-tuple-source
                                                                                                                                                                                                                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                                                              exchange
                                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                project ([$$361, $$366, $$367])
                                                                                                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                  assign [$$361, $$366, $$367] <- [$$432, $$437, $$438]
                                                                                                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                      replicate
                                                                                                                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                        exchange
                                                                                                                                                                                                                         -- HASH_PARTITION_EXCHANGE [$$438]  |PARTITIONED|
+                                                                                                                                                                                                                          project ([$$432, $$437, $$438])
                                                                                                                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                            select (eq($$435.getField("to_u"), "aaaaa"))
                                                                                                                                                                                                                             -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                                                                                              assign [$$438, $$437, $$432] <- [$$435.getField("y_id"), $$435.getField("a"), $$435.getField("b")]
                                                                                                                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                exchange
                                                                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                  replicate
                                                                                                                                                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                      project ([$$435])
                                                                                                                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                        assign [$$441, $$435] <- [$$405, $$411]
                                                                                                                                                                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                          exchange
                                                                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                            replicate
                                                                                                                                                                                                                                             -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                              exchange
                                                                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                                                                -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                                                                                                                data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                                                                                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                                                  exchange
                                                                                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                    empty-tuple-source
                                                                                                                                                                                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                                                      exchange
                                                                                                                                                                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                        unnest $$365 <- scan-collection(array: [ 66, 67, 26, 12, 13 ])
                                                                                                                                                                                                         -- UNNEST  |UNPARTITIONED|
+                                                                                                                                                                                                          empty-tuple-source
                                                                                                                                                                                                           -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                                                                                                                        exchange
                                                                                                                                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                                                                          unnest $$329 <- scan-collection(array: [ 66, 67, 26, 12, 13 ])
                                                                                                                                           -- UNNEST  |UNPARTITIONED|
+                                                                                                                                            empty-tuple-source
                                                                                                                                             -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                                                                                                  exchange
                                                                                                                   -- HASH_PARTITION_EXCHANGE [$$313]  |PARTITIONED|
+                                                                                                                    project ([$$318, $$320, $$313])
                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                      assign [$$320, $$315, $$313, $$318] <- [$$420, $$422, $$427, $$416]
                                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                                        exchange
                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                          replicate
                                                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                                                            exchange
                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                              assign [$$427, $$416] <- [$$422.getField("y_id"), $$422.getField("b")]
                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                project ([$$420, $$422])
                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                  assign [$$420, $$422] <- [$$405, $$411]
                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                    exchange
                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                      replicate
                                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                                        exchange
                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                          -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                          data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                            exchange
                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                              empty-tuple-source
                                                                                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                          exchange
                                                                                                           -- HASH_PARTITION_EXCHANGE [$$392, $$391]  |PARTITIONED|
+                                                                                                            assign [$$452] <- [true]
                                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                                              project ([$$174, $$392, $$391])
                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                exchange
                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                  join (eq($$194, $$166))
                                                                                                                   -- HYBRID_HASH_JOIN [$$166][$$194]  |PARTITIONED|
+                                                                                                                    exchange
                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                      project ([$$174, $$392, $$391, $$166])
                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                        exchange
                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                          join (eq($$210, $$385))
                                                                                                                           -- HYBRID_HASH_JOIN [$$385][$$210]  |PARTITIONED|
+                                                                                                                            exchange
                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                              project ([$$392, $$391, $$385])
                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                exchange
                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                  join (eq($$384, $$385))
                                                                                                                                   -- HYBRID_HASH_JOIN [$$385][$$384]  |PARTITIONED|
+                                                                                                                                    exchange
                                                                                                                                     -- HASH_PARTITION_EXCHANGE [$$385]  |PARTITIONED|
-                                                                                                                                      -- PRE_CLUSTERED_GROUP_BY[$$393]  |PARTITIONED|
-                                                                                                                                              {
+                                                                                                                                      group by ([$$392 := $$393]) decor ([$$385]) {
+                                                                                                                                                aggregate [] <- []
                                                                                                                                                 -- AGGREGATE  |LOCAL|
+                                                                                                                                                  select (not(is-missing($$397)))
                                                                                                                                                   -- STREAM_SELECT  |LOCAL|
+                                                                                                                                                    nested tuple source
                                                                                                                                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                                                              }
+                                                                                                                                             }
+                                                                                                                                      -- PRE_CLUSTERED_GROUP_BY[$$393]  |PARTITIONED|
+                                                                                                                                        exchange
                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                          project ([$$385, $$397, $$393])
                                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                            exchange
                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                              left outer join (eq($$393, $$396))
                                                                                                                                               -- HYBRID_HASH_JOIN [$$393][$$396]  |PARTITIONED|
+                                                                                                                                                exchange
                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                  replicate
                                                                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                                                                    exchange
                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                      replicate
                                                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                                                        exchange
                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                          project ([$$385, $$393])
                                                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                            assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                                                                                              exchange
                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                                                                data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                  exchange
                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                    empty-tuple-source
                                                                                                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                exchange
                                                                                                                                                 -- HASH_PARTITION_EXCHANGE [$$396]  |PARTITIONED|
+                                                                                                                                                  assign [$$397] <- [true]
                                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                                    project ([$$396])
                                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                      exchange
                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                        join (eq($$400, $$401))
                                                                                                                                                         -- HYBRID_HASH_JOIN [$$401][$$400]  |PARTITIONED|
+                                                                                                                                                          exchange
                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                            project ([$$396, $$401])
                                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                              select ($$402)
                                                                                                                                                               -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                                project ([$$402, $$396, $$401])
                                                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                  exchange
                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                    -- PRE_CLUSTERED_GROUP_BY[$$403, $$405]  |PARTITIONED|
-                                                                                                                                                                            {
+                                                                                                                                                                    group by ([$$396 := $$403; $$404 := $$405]) decor ([$$401]) {
+                                                                                                                                                                              aggregate [$$402] <- [non-empty-stream()]
                                                                                                                                                                               -- AGGREGATE  |LOCAL|
+                                                                                                                                                                                select (not(is-missing($$415)))
                                                                                                                                                                                 -- STREAM_SELECT  |LOCAL|
+                                                                                                                                                                                  nested tuple source
                                                                                                                                                                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                                                                                            }
+                                                                                                                                                                           }
+                                                                                                                                                                    -- PRE_CLUSTERED_GROUP_BY[$$403, $$405]  |PARTITIONED|
+                                                                                                                                                                      exchange
                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                        order (ASC, $$403) (ASC, $$405)
                                                                                                                                                                         -- STABLE_SORT [$$403(ASC), $$405(ASC)]  |PARTITIONED|
+                                                                                                                                                                          exchange
                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                            project ([$$401, $$415, $$403, $$405])
                                                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                              exchange
                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                left outer join (and(eq($$403, $$413), eq($$405, $$414)))
                                                                                                                                                                                 -- HYBRID_HASH_JOIN [$$403, $$405][$$413, $$414]  |PARTITIONED|
+                                                                                                                                                                                  exchange
                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                    replicate
                                                                                                                                                                                     -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                      exchange
                                                                                                                                                                                       -- HASH_PARTITION_EXCHANGE [$$403, $$405]  |PARTITIONED|
+                                                                                                                                                                                        project ([$$401, $$403, $$405])
                                                                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                          exchange
                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                            join (eq($$409, $$408))
                                                                                                                                                                                             -- HYBRID_HASH_JOIN [$$408][$$409]  |PARTITIONED|
+                                                                                                                                                                                              exchange
                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                replicate
                                                                                                                                                                                                 -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                  exchange
                                                                                                                                                                                                   -- HASH_PARTITION_EXCHANGE [$$408]  |PARTITIONED|
+                                                                                                                                                                                                    project ([$$408, $$403])
                                                                                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                      assign [$$408, $$403] <- [$$385, $$393]
                                                                                                                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                        exchange
                                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                          replicate
                                                                                                                                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                            exchange
                                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                              project ([$$385, $$393])
                                                                                                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                  exchange
                                                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                                    -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                                                                                                                    data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                                                                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                      exchange
                                                                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                        empty-tuple-source
                                                                                                                                                                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                                              exchange
                                                                                                                                                                                               -- HASH_PARTITION_EXCHANGE [$$409]  |PARTITIONED|
+                                                                                                                                                                                                project ([$$401, $$405, $$409])
                                                                                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                  select (eq($$411.getField("to_u"), "aaaaa"))
                                                                                                                                                                                                   -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                                                                    assign [$$409, $$401] <- [$$411.getField("y_id"), $$411.getField("a")]
                                                                                                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                      exchange
                                                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                        replicate
                                                                                                                                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                          exchange
                                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                            -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                                                                            data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                              exchange
                                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                empty-tuple-source
                                                                                                                                                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                                  exchange
                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                    assign [$$415] <- [true]
                                                                                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                      project ([$$413, $$414])
                                                                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                        select (eq($$416, $$417))
                                                                                                                                                                                         -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                                                          project ([$$413, $$414, $$416, $$417])
                                                                                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                            unnest $$417 <- scan-collection($$418)
                                                                                                                                                                                             -- UNNEST  |PARTITIONED|
+                                                                                                                                                                                              exchange
                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                -- PRE_CLUSTERED_GROUP_BY[$$419, $$420]  |PARTITIONED|
-                                                                                                                                                                                                        {
+                                                                                                                                                                                                group by ([$$413 := $$419; $$414 := $$420]) decor ([$$416]) {
+                                                                                                                                                                                                          aggregate [$$418] <- [listify($$450)]
                                                                                                                                                                                                           -- AGGREGATE  |LOCAL|
+                                                                                                                                                                                                            aggregate [$$450] <- [agg-sql-max($$432)]
                                                                                                                                                                                                             -- AGGREGATE  |LOCAL|
+                                                                                                                                                                                                              select (not(is-missing($$431)))
                                                                                                                                                                                                               -- STREAM_SELECT  |LOCAL|
+                                                                                                                                                                                                                nested tuple source
                                                                                                                                                                                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                                                                                                                        }
+                                                                                                                                                                                                       }
+                                                                                                                                                                                                -- PRE_CLUSTERED_GROUP_BY[$$419, $$420]  |PARTITIONED|
+                                                                                                                                                                                                  exchange
                                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                    order (ASC, $$419) (ASC, $$420)
                                                                                                                                                                                                     -- STABLE_SORT [$$419(ASC), $$420(ASC)]  |PARTITIONED|
+                                                                                                                                                                                                      exchange
                                                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                        project ([$$416, $$432, $$431, $$419, $$420])
                                                                                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                          exchange
                                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                            left outer join (and(eq($$419, $$429), eq($$420, $$430)))
                                                                                                                                                                                                             -- HYBRID_HASH_JOIN [$$419, $$420][$$429, $$430]  |PARTITIONED|
+                                                                                                                                                                                                              exchange
                                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                replicate
                                                                                                                                                                                                                 -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                  exchange
                                                                                                                                                                                                                   -- HASH_PARTITION_EXCHANGE [$$419, $$420]  |PARTITIONED|
+                                                                                                                                                                                                                    project ([$$416, $$419, $$420])
                                                                                                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                      exchange
                                                                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                        join (eq($$427, $$428))
                                                                                                                                                                                                                         -- HYBRID_HASH_JOIN [$$428][$$427]  |PARTITIONED|
+                                                                                                                                                                                                                          exchange
                                                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                            project ([$$419, $$428])
                                                                                                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                              assign [$$419, $$428] <- [$$403, $$408]
                                                                                                                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                exchange
                                                                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                  replicate
                                                                                                                                                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                                     -- HASH_PARTITION_EXCHANGE [$$408]  |PARTITIONED|
+                                                                                                                                                                                                                                      project ([$$408, $$403])
                                                                                                                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                        assign [$$408, $$403] <- [$$385, $$393]
                                                                                                                                                                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                          exchange
                                                                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                            replicate
                                                                                                                                                                                                                                             -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                              exchange
                                                                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                project ([$$385, $$393])
                                                                                                                                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                                  assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                                                                      -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                                                                                                                                                      data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                                                                                                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                                                        exchange
                                                                                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                          empty-tuple-source
                                                                                                                                                                                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                                                                          exchange
                                                                                                                                                                                                                           -- HASH_PARTITION_EXCHANGE [$$427]  |PARTITIONED|
+                                                                                                                                                                                                                            project ([$$416, $$420, $$427])
                                                                                                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                              select (eq($$422.getField("to_u"), "aaaaa"))
                                                                                                                                                                                                                               -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                                                                                                exchange
                                                                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                  replicate
                                                                                                                                                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                      assign [$$427, $$416] <- [$$422.getField("y_id"), $$422.getField("b")]
                                                                                                                                                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                        project ([$$420, $$422])
                                                                                                                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                          assign [$$420, $$422] <- [$$405, $$411]
                                                                                                                                                                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                            exchange
                                                                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                              replicate
                                                                                                                                                                                                                                               -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                                exchange
                                                                                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                                                                  -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                                                                                                                  data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                                                                                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                      empty-tuple-source
                                                                                                                                                                                                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                                                              exchange
                                                                                                                                                                                                               -- HASH_PARTITION_EXCHANGE [$$429, $$430]  |PARTITIONED|
+                                                                                                                                                                                                                assign [$$431] <- [true]
                                                                                                                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                  project ([$$432, $$429, $$430])
                                                                                                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                      join (eq($$436, $$437))
                                                                                                                                                                                                                       -- HYBRID_HASH_JOIN [$$437][$$436]  |PARTITIONED|
+                                                                                                                                                                                                                        exchange
                                                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                          project ([$$432, $$429, $$430, $$437])
                                                                                                                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                            exchange
                                                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                              join (eq($$438, $$439))
                                                                                                                                                                                                                               -- HYBRID_HASH_JOIN [$$439][$$438]  |PARTITIONED|
+                                                                                                                                                                                                                                exchange
                                                                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                  replicate
                                                                                                                                                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                      project ([$$429, $$430, $$439])
                                                                                                                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                        exchange
                                                                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                          join (eq($$442, $$439))
                                                                                                                                                                                                                                           -- HYBRID_HASH_JOIN [$$439][$$442]  |PARTITIONED|
+                                                                                                                                                                                                                                            exchange
                                                                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                              project ([$$429, $$439])
                                                                                                                                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                                assign [$$429, $$439] <- [$$403, $$408]
                                                                                                                                                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                                  exchange
                                                                                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                    replicate
                                                                                                                                                                                                                                                     -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                                      exchange
                                                                                                                                                                                                                                                       -- HASH_PARTITION_EXCHANGE [$$408]  |PARTITIONED|
+                                                                                                                                                                                                                                                        project ([$$408, $$403])
                                                                                                                                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                                          assign [$$408, $$403] <- [$$385, $$393]
                                                                                                                                                                                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                                            exchange
                                                                                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                              replicate
                                                                                                                                                                                                                                                               -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                                                exchange
                                                                                                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                                  project ([$$385, $$393])
                                                                                                                                                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                                                    assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                                                                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                                                      exchange
                                                                                                                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                                                                                        -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                                                                                                                                                                        data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                                                                                                                                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                                                                          exchange
                                                                                                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                                            empty-tuple-source
                                                                                                                                                                                                                                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                                                                                            exchange
                                                                                                                                                                                                                                             -- HASH_PARTITION_EXCHANGE [$$442]  |PARTITIONED|
+                                                                                                                                                                                                                                              project ([$$430, $$442])
                                                                                                                                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                                select (eq($$444.getField("to_u"), "aaaaa"))
                                                                                                                                                                                                                                                 -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                                                                                                                  exchange
                                                                                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                    replicate
                                                                                                                                                                                                                                                     -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                                      exchange
                                                                                                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                        assign [$$442] <- [$$444.getField("y_id")]
                                                                                                                                                                                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                                          project ([$$430, $$444])
                                                                                                                                                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                                            assign [$$430, $$444] <- [$$405, $$411]
                                                                                                                                                                                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                                              exchange
                                                                                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                                replicate
                                                                                                                                                                                                                                                                 -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                                                  exchange
                                                                                                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                                                                                    -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                                                                                                                                    data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                                                                                                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                                                                      exchange
                                                                                                                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                                        empty-tuple-source
                                                                                                                                                                                                                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                                                                                exchange
                                                                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                  replicate
                                                                                                                                                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                                     -- HASH_PARTITION_EXCHANGE [$$438]  |PARTITIONED|
+                                                                                                                                                                                                                                      project ([$$432, $$437, $$438])
                                                                                                                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                        select (eq($$435.getField("to_u"), "aaaaa"))
                                                                                                                                                                                                                                         -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                                                                                                          assign [$$438, $$437, $$432] <- [$$435.getField("y_id"), $$435.getField("a"), $$435.getField("b")]
                                                                                                                                                                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                            exchange
                                                                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                              replicate
                                                                                                                                                                                                                                               -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                                exchange
                                                                                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                  project ([$$435])
                                                                                                                                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                                    assign [$$441, $$435] <- [$$405, $$411]
                                                                                                                                                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                                      exchange
                                                                                                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                        replicate
                                                                                                                                                                                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                                          exchange
                                                                                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                                                                            -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                                                                                                                            data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                                                                                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                                                              exchange
                                                                                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                                empty-tuple-source
                                                                                                                                                                                                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                                                                        exchange
                                                                                                                                                                                                                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                          unnest $$436 <- scan-collection(array: [ 66, 67, 26, 12, 13 ])
                                                                                                                                                                                                                           -- UNNEST  |UNPARTITIONED|
+                                                                                                                                                                                                                            empty-tuple-source
                                                                                                                                                                                                                             -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                                                                                                                                          exchange
                                                                                                                                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                                                                                            unnest $$400 <- scan-collection(array: [ 66, 67, 26, 12, 13 ])
                                                                                                                                                             -- UNNEST  |UNPARTITIONED|
+                                                                                                                                                              empty-tuple-source
                                                                                                                                                               -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                                                                                                                    exchange
                                                                                                                                     -- HASH_PARTITION_EXCHANGE [$$384]  |PARTITIONED|
+                                                                                                                                      project ([$$391, $$384])
                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                        assign [$$391, $$386, $$384] <- [$$430, $$444, $$442]
                                                                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                                                                          exchange
                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                            replicate
                                                                                                                                             -- REPLICATE  |PARTITIONED|
+                                                                                                                                              exchange
                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                assign [$$442] <- [$$444.getField("y_id")]
                                                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                                                  project ([$$430, $$444])
                                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                    assign [$$430, $$444] <- [$$405, $$411]
                                                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                                                      exchange
                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                        replicate
                                                                                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                                                                                          exchange
                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                            -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                            data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                              exchange
                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                empty-tuple-source
                                                                                                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                            exchange
                                                                                                                             -- HASH_PARTITION_EXCHANGE [$$210]  |PARTITIONED|
+                                                                                                                              project ([$$174, $$166, $$210])
                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                assign [$$166, $$210, $$174] <- [$$L.getField("posi"), $$L.getField("y_id"), $$L.getField("b")]
                                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                                  project ([$$L])
                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                    assign [$$L] <- [$$435]
                                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                                      exchange
                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                        replicate
                                                                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                                                                          exchange
                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                            project ([$$435])
                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                              assign [$$441, $$435] <- [$$405, $$411]
                                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                                exchange
                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                  replicate
                                                                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                                                                    exchange
                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                      -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                      data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                        exchange
                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                          empty-tuple-source
                                                                                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                    exchange
                                                                                                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                                                      unnest $$194 <- scan-collection(array: [ "a", "b" ])
                                                                                                                       -- UNNEST  |UNPARTITIONED|
+                                                                                                                        empty-tuple-source
                                                                                                                         -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                                      exchange
                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                        unnest $$195 <- scan-collection(array: [ "a", "b" ])
                                                         -- UNNEST  |UNPARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                              exchange
                                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                unnest $$196 <- scan-collection(array: [ 66, 67, 12, 13 ])
                                                 -- UNNEST  |UNPARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query_issue849-2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query_issue849-2.plan
index e0059ed..e9062bc 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query_issue849-2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query_issue849-2.plan
@@ -1,32 +1,32 @@
--- COMMIT  |PARTITIONED|
-  -- STREAM_PROJECT  |PARTITIONED|
-    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-      -- INSERT_DELETE  |PARTITIONED|
-        -- HASH_PARTITION_EXCHANGE [$$3]  |PARTITIONED|
-          -- ASSIGN  |UNPARTITIONED|
-            -- ASSIGN  |UNPARTITIONED|
-              -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
--- COMMIT  |PARTITIONED|
-  -- STREAM_PROJECT  |PARTITIONED|
-    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-      -- INSERT_DELETE  |PARTITIONED|
-        -- HASH_PARTITION_EXCHANGE [$$3]  |PARTITIONED|
-          -- ASSIGN  |UNPARTITIONED|
-            -- ASSIGN  |UNPARTITIONED|
-              -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+distribute result [$$43]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$43])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$43] <- [{"x": $$x, "y": $$40}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$x, $$40])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$44, $$46))
             -- HYBRID_HASH_JOIN [$$44][$$46]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (test.s)  |PARTITIONED|
+                data-scan []<-[$$44, $$x] <- test.s
+                -- DATASOURCE_SCAN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$46]  |PARTITIONED|
+                project ([$$40, $$46])
                 -- STREAM_PROJECT  |UNPARTITIONED|
+                  assign [$$40, $$46] <- [$$z.getField("c"), $$z.getField("a")]
                   -- ASSIGN  |UNPARTITIONED|
+                    unnest $$z <- scan-collection(unordered-list-constructor({"a": 1, "c": 1}, {"a": 2, "c": 2}, {"a": 1, "c": null}))
                     -- UNNEST  |UNPARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query_issue849.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query_issue849.plan
index 5d16539..9309ea2 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/query_issue849.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/query_issue849.plan
@@ -1,33 +1,34 @@
--- COMMIT  |PARTITIONED|
-  -- STREAM_PROJECT  |PARTITIONED|
-    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-      -- INSERT_DELETE  |PARTITIONED|
-        -- HASH_PARTITION_EXCHANGE [$$3]  |PARTITIONED|
-          -- ASSIGN  |UNPARTITIONED|
-            -- ASSIGN  |UNPARTITIONED|
-              -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
--- COMMIT  |PARTITIONED|
-  -- STREAM_PROJECT  |PARTITIONED|
-    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-      -- INSERT_DELETE  |PARTITIONED|
-        -- HASH_PARTITION_EXCHANGE [$$3]  |PARTITIONED|
-          -- ASSIGN  |UNPARTITIONED|
-            -- ASSIGN  |UNPARTITIONED|
-              -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+distribute result [$$42]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$42])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$42] <- [{"x": $$x, "y": $$44}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$x, $$44])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$45, $$44))
             -- HYBRID_HASH_JOIN [$$45][$$44]  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$45]  |PARTITIONED|
+                assign [$$45] <- [$$x.getField(0)]
                 -- ASSIGN  |UNPARTITIONED|
+                  unnest $$x <- scan-collection(multiset: {{ { "a": 1 }, { "a": 2 } }})
                   -- UNNEST  |UNPARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$44])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- DATASOURCE_SCAN (test.s)  |PARTITIONED|
+                    data-scan []<-[$$44, $$z] <- test.s
+                    -- DATASOURCE_SCAN  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/remove_listify.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/remove_listify.plan
index 96d4248..a0d4bac 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/remove_listify.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/remove_listify.plan
@@ -1,36 +1,69 @@
+distribute result [$$130]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$130])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$130] <- [{"f1": $$139, "counts": get-item($$128, 0)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$128, $$139])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- PRE_CLUSTERED_GROUP_BY[$$141]  |PARTITIONED|
-                    {
+            group by ([$$146 := $$134]) decor ([$$139]) {
+                      aggregate [$$128] <- [listify({"counts": $$136})]
                       -- AGGREGATE  |LOCAL|
+                        aggregate [$$136] <- [agg-sql-count(1)]
                         -- AGGREGATE  |LOCAL|
+                          select (and(ge($$132, numeric-subtract($$140, 5)), le($$132, $$140), not(is-missing($$145))))
                           -- STREAM_SELECT  |LOCAL|
+                            assign [$$132] <- [$$106.getField("f2")]
                             -- ASSIGN  |LOCAL|
+                              nested tuple source
                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                    }
+                   }
+            -- PRE_CLUSTERED_GROUP_BY[$$134]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- STABLE_SORT [$$141(ASC)]  |PARTITIONED|
-                  -- HASH_PARTITION_EXCHANGE [$$141]  |PARTITIONED|
+                order (ASC, $$134)
+                -- STABLE_SORT [$$134(ASC)]  |PARTITIONED|
+                  exchange
+                  -- HASH_PARTITION_EXCHANGE [$$134]  |PARTITIONED|
+                    project ([$$139, $$140, $$145, $$106, $$134])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- HYBRID_HASH_JOIN [$$146][$$148]  |PARTITIONED|
-                          -- HASH_PARTITION_EXCHANGE [$$146]  |PARTITIONED|
+                        left outer join (eq($$141, $$139))
+                        -- HYBRID_HASH_JOIN [$$139][$$141]  |PARTITIONED|
+                          exchange
+                          -- HASH_PARTITION_EXCHANGE [$$139]  |PARTITIONED|
+                            project ([$$139, $$140, $$134])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$140, $$139] <- [$$b.getField("f2"), $$b.getField("f1")]
                               -- ASSIGN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                  data-scan []<-[$$134, $$b] <- test.collection1
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                          -- HASH_PARTITION_EXCHANGE [$$148]  |PARTITIONED|
+                          exchange
+                          -- HASH_PARTITION_EXCHANGE [$$141]  |PARTITIONED|
+                            project ([$$145, $$106, $$141])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$145, $$106] <- [true, {"f1": $$141, "f2": $$b.getField("f2")}]
                               -- ASSIGN  |PARTITIONED|
+                                assign [$$141] <- [$$b.getField("f1")]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$b])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                      data-scan []<-[$$135, $$b] <- test.collection1
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                          empty-tuple-source
+                                          -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rightouterjoin/roj-01-core.1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rightouterjoin/roj-01-core.1.plan
index 2a8e400..b8aec69 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rightouterjoin/roj-01-core.1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rightouterjoin/roj-01-core.1.plan
@@ -1,28 +1,56 @@
+distribute result [$$83]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$83])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$83] <- [{"t0_unique1": $#1, "t1_unique1": $#2}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$#1(ASC), $#2(ASC) ]  |PARTITIONED|
+          order (ASC, $#1) (ASC, $#2)
           -- STABLE_SORT [$#1(ASC), $#2(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$#1, $#2])
               -- STREAM_PROJECT  |PARTITIONED|
+                assign [$#2, $#1] <- [if-missing($$90, null), if-missing($$92, null)]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$90, $$92])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      left outer join (eq($$86, $$85))
                       -- HYBRID_HASH_JOIN [$$85][$$86]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$90, $$85])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$90] <- [$$tenk.getField(0)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                                unnest-map [$$85, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 0, 1, $$98, true, false, false)
+                                -- BTREE_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    assign [$$98] <- [4]
                                     -- ASSIGN  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$92, $$86])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$92] <- [{"unique1": $$tenk.getField(0), "unique2": $$86}.getField(0)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                                unnest-map [$$86, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 0, 1, $$101, true, false, false)
+                                -- BTREE_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    assign [$$101] <- [2]
                                     -- ASSIGN  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rightouterjoin/roj-01-core.2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rightouterjoin/roj-01-core.2.plan
index 2555179..e6025e8 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rightouterjoin/roj-01-core.2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rightouterjoin/roj-01-core.2.plan
@@ -1,44 +1,88 @@
+distribute result [$$140]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$140])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$140] <- [{"t0_unique1": $#1, "t1_unique1": $#2, "t2_unique1": $#3}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$#1(ASC), $#2(ASC), $#3(ASC) ]  |PARTITIONED|
+          order (ASC, $#1) (ASC, $#2) (ASC, $#3)
           -- STABLE_SORT [$#1(ASC), $#2(ASC), $#3(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$#1, $#2, $#3])
               -- STREAM_PROJECT  |PARTITIONED|
+                assign [$#3, $#2, $#1] <- [if-missing($$151, null), if-missing($$155, null), if-missing($$154, null)]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$151, $$155, $$154])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      left outer join (eq($$143, $$142))
                       -- HYBRID_HASH_JOIN [$$142][$$143]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$151, $$142])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$151] <- [$$tenk.getField(0)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                                unnest-map [$$142, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 0, 1, $$165, true, false, false)
+                                -- BTREE_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    assign [$$165] <- [6]
                                     -- ASSIGN  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$155, $$154, $$143])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$154, $$155] <- [$$123.getField(1).getField(0), $$123.getField(0).getField(0)]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$143, $$123])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$123] <- [{"$6": $$107, "$8": $$115}]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$143, $$107, $$115])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      left outer join (eq($$144, $$143))
                                       -- HYBRID_HASH_JOIN [$$143][$$144]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$143, $$107])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$107] <- [{"unique1": $$tenk.getField(0), "unique2": $$143}]
                                             -- ASSIGN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                                                unnest-map [$$143, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 0, 1, $$168, true, false, false)
+                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    assign [$$168] <- [4]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$115, $$144])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$115] <- [{"unique1": $$tenk.getField(0), "unique2": $$144}]
                                             -- ASSIGN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- BTREE_SEARCH (test.tenk.tenk)  |PARTITIONED|
+                                                unnest-map [$$144, $$tenk] <- index-search("tenk", 0, "test", "tenk", false, false, 0, 1, $$171, true, false, false)
+                                                -- BTREE_SEARCH  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    assign [$$171] <- [2]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/rtree-sidx-idxonly-01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/rtree-sidx-idxonly-01.plan
index 30be777..24e1d20 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/rtree-sidx-idxonly-01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/rtree-sidx-idxonly-01.plan
@@ -1,15 +1,30 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (st-intersects($$geo.getField(1), OGCPolygon: POLYGON ((1 1, 5 1, 5 5, 1 5, 1 1))))
       -- STREAM_SELECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (IndexGeoJSON.Geometries.Geometries)  |PARTITIONED|
+          unnest-map [$$17, $$geo] <- index-search("Geometries", 0, "IndexGeoJSON", "Geometries", false, false, 1, $$27, 1, $$27, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$27)
               -- STABLE_SORT [$$27(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$27])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- RTREE_SEARCH (IndexGeoJSON.Geometries.geomIndex)  |PARTITIONED|
+                      unnest-map [$$23, $$24, $$25, $$26, $$27] <- index-search("geomIndex", 1, "IndexGeoJSON", "Geometries", false, false, 4, $$19, $$20, $$21, $$22)
+                      -- RTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$19, $$20, $$21, $$22] <- [1.0, 1.0, 5.0, 5.0]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/rtree-sidx-idxonly-02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/rtree-sidx-idxonly-02.plan
index 30be777..c1f313b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/rtree-sidx-idxonly-02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/rtree-sidx-idxonly-02.plan
@@ -1,15 +1,30 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (st-contains($$geo.getField(1), OGCPolygon: POLYGON ((1 1, 5 1, 5 5, 1 5, 1 1))))
       -- STREAM_SELECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (IndexGeoJSON.Geometries.Geometries)  |PARTITIONED|
+          unnest-map [$$17, $$geo] <- index-search("Geometries", 0, "IndexGeoJSON", "Geometries", false, false, 1, $$27, 1, $$27, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$27)
               -- STABLE_SORT [$$27(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$27])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- RTREE_SEARCH (IndexGeoJSON.Geometries.geomIndex)  |PARTITIONED|
+                      unnest-map [$$23, $$24, $$25, $$26, $$27] <- index-search("geomIndex", 1, "IndexGeoJSON", "Geometries", false, false, 4, $$19, $$20, $$21, $$22)
+                      -- RTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$19, $$20, $$21, $$22] <- [1.0, 1.0, 5.0, 5.0]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/rtree-sidx-idxonly-03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/rtree-sidx-idxonly-03.plan
index 30be777..867dbc5 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/rtree-sidx-idxonly-03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/rtree-sidx-idxonly-03.plan
@@ -1,15 +1,30 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (st-crosses($$geo.getField(1), OGCPolygon: POLYGON ((1 1, 5 1, 5 5, 1 5, 1 1))))
       -- STREAM_SELECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (IndexGeoJSON.Geometries.Geometries)  |PARTITIONED|
+          unnest-map [$$17, $$geo] <- index-search("Geometries", 0, "IndexGeoJSON", "Geometries", false, false, 1, $$27, 1, $$27, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$27)
               -- STABLE_SORT [$$27(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$27])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- RTREE_SEARCH (IndexGeoJSON.Geometries.geomIndex)  |PARTITIONED|
+                      unnest-map [$$23, $$24, $$25, $$26, $$27] <- index-search("geomIndex", 1, "IndexGeoJSON", "Geometries", false, false, 4, $$19, $$20, $$21, $$22)
+                      -- RTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$19, $$20, $$21, $$22] <- [1.0, 1.0, 5.0, 5.0]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/rtree-sidx-idxonly-04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/rtree-sidx-idxonly-04.plan
index 30be777..c5e4892 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/rtree-sidx-idxonly-04.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/rtree-sidx-idxonly-04.plan
@@ -1,15 +1,30 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (st-overlaps($$geo.getField(1), OGCPolygon: POLYGON ((1 1, 5 1, 5 5, 1 5, 1 1))))
       -- STREAM_SELECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (IndexGeoJSON.Geometries.Geometries)  |PARTITIONED|
+          unnest-map [$$17, $$geo] <- index-search("Geometries", 0, "IndexGeoJSON", "Geometries", false, false, 1, $$27, 1, $$27, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$27)
               -- STABLE_SORT [$$27(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$27])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- RTREE_SEARCH (IndexGeoJSON.Geometries.geomIndex)  |PARTITIONED|
+                      unnest-map [$$23, $$24, $$25, $$26, $$27] <- index-search("geomIndex", 1, "IndexGeoJSON", "Geometries", false, false, 4, $$19, $$20, $$21, $$22)
+                      -- RTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$19, $$20, $$21, $$22] <- [1.0, 1.0, 5.0, 5.0]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/rtree-sidx-idxonly-05.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/rtree-sidx-idxonly-05.plan
index 30be777..3feb2cd 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/rtree-sidx-idxonly-05.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/rtree-sidx-idxonly-05.plan
@@ -1,15 +1,30 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (st-touches($$geo.getField(1), OGCPolygon: POLYGON ((1 1, 5 1, 5 5, 1 5, 1 1))))
       -- STREAM_SELECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (IndexGeoJSON.Geometries.Geometries)  |PARTITIONED|
+          unnest-map [$$17, $$geo] <- index-search("Geometries", 0, "IndexGeoJSON", "Geometries", false, false, 1, $$27, 1, $$27, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$27)
               -- STABLE_SORT [$$27(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$27])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- RTREE_SEARCH (IndexGeoJSON.Geometries.geomIndex)  |PARTITIONED|
+                      unnest-map [$$23, $$24, $$25, $$26, $$27] <- index-search("geomIndex", 1, "IndexGeoJSON", "Geometries", false, false, 4, $$19, $$20, $$21, $$22)
+                      -- RTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$19, $$20, $$21, $$22] <- [1.0, 1.0, 5.0, 5.0]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/rtree-sidx-idxonly-06.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/rtree-sidx-idxonly-06.plan
index 30be777..649c780 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/rtree-sidx-idxonly-06.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/rtree-sidx-idxonly-06.plan
@@ -1,15 +1,30 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (st-within($$geo.getField(1), OGCPolygon: POLYGON ((1 1, 5 1, 5 5, 1 5, 1 1))))
       -- STREAM_SELECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (IndexGeoJSON.Geometries.Geometries)  |PARTITIONED|
+          unnest-map [$$17, $$geo] <- index-search("Geometries", 0, "IndexGeoJSON", "Geometries", false, false, 1, $$27, 1, $$27, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$27)
               -- STABLE_SORT [$$27(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$27])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- RTREE_SEARCH (IndexGeoJSON.Geometries.geomIndex)  |PARTITIONED|
+                      unnest-map [$$23, $$24, $$25, $$26, $$27] <- index-search("geomIndex", 1, "IndexGeoJSON", "Geometries", false, false, 4, $$19, $$20, $$21, $$22)
+                      -- RTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$19, $$20, $$21, $$22] <- [1.0, 1.0, 5.0, 5.0]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/rtree-sidx-idxonly-07.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/rtree-sidx-idxonly-07.plan
index 30be777..12c2bb3 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/rtree-sidx-idxonly-07.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/rtree-sidx-idxonly-07.plan
@@ -1,15 +1,30 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (st-disjoint($$geo.getField(1), OGCPolygon: POLYGON ((1 1, 5 1, 5 5, 1 5, 1 1))))
       -- STREAM_SELECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- BTREE_SEARCH (IndexGeoJSON.Geometries.Geometries)  |PARTITIONED|
+          unnest-map [$$17, $$geo] <- index-search("Geometries", 0, "IndexGeoJSON", "Geometries", false, false, 1, $$27, 1, $$27, true, true, true)
+          -- BTREE_SEARCH  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$27)
               -- STABLE_SORT [$$27(ASC)]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$27])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- RTREE_SEARCH (IndexGeoJSON.Geometries.geomIndex)  |PARTITIONED|
+                      unnest-map [$$23, $$24, $$25, $$26, $$27] <- index-search("geomIndex", 1, "IndexGeoJSON", "Geometries", false, false, 4, $$19, $$20, $$21, $$22)
+                      -- RTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          assign [$$19, $$20, $$21, $$22] <- [1.0, 1.0, 5.0, 5.0]
                           -- ASSIGN  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/skip-rtree-sidx-01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/skip-rtree-sidx-01.plan
index 7cd72c2..09f1c85 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/skip-rtree-sidx-01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/skip-rtree-sidx-01.plan
@@ -1,8 +1,16 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (st-intersects($$geo.getField(1), OGCPolygon: POLYGON ((1 1, 5 1, 5 5, 1 5, 1 1))))
       -- STREAM_SELECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (IndexGeoJSON.Geometries)  |PARTITIONED|
+          data-scan []<-[$$17, $$geo] <- IndexGeoJSON.Geometries
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/skip-rtree-sidx-02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/skip-rtree-sidx-02.plan
index 7cd72c2..afa948d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/skip-rtree-sidx-02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/skip-rtree-sidx-02.plan
@@ -1,8 +1,16 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (st-contains($$geo.getField(1), OGCPolygon: POLYGON ((1 1, 5 1, 5 5, 1 5, 1 1))))
       -- STREAM_SELECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (IndexGeoJSON.Geometries)  |PARTITIONED|
+          data-scan []<-[$$17, $$geo] <- IndexGeoJSON.Geometries
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/skip-rtree-sidx-03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/skip-rtree-sidx-03.plan
index 7cd72c2..bdcc72d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/skip-rtree-sidx-03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/skip-rtree-sidx-03.plan
@@ -1,8 +1,16 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (st-crosses($$geo.getField(1), OGCPolygon: POLYGON ((1 1, 5 1, 5 5, 1 5, 1 1))))
       -- STREAM_SELECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (IndexGeoJSON.Geometries)  |PARTITIONED|
+          data-scan []<-[$$17, $$geo] <- IndexGeoJSON.Geometries
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/skip-rtree-sidx-04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/skip-rtree-sidx-04.plan
index 7cd72c2..de5d14e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/skip-rtree-sidx-04.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/skip-rtree-sidx-04.plan
@@ -1,8 +1,16 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (st-overlaps($$geo.getField(1), OGCPolygon: POLYGON ((1 1, 5 1, 5 5, 1 5, 1 1))))
       -- STREAM_SELECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (IndexGeoJSON.Geometries)  |PARTITIONED|
+          data-scan []<-[$$17, $$geo] <- IndexGeoJSON.Geometries
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/skip-rtree-sidx-05.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/skip-rtree-sidx-05.plan
index 7cd72c2..9375213 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/skip-rtree-sidx-05.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/skip-rtree-sidx-05.plan
@@ -1,8 +1,16 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (st-touches($$geo.getField(1), OGCPolygon: POLYGON ((1 1, 5 1, 5 5, 1 5, 1 1))))
       -- STREAM_SELECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (IndexGeoJSON.Geometries)  |PARTITIONED|
+          data-scan []<-[$$17, $$geo] <- IndexGeoJSON.Geometries
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/skip-rtree-sidx-06.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/skip-rtree-sidx-06.plan
index 7cd72c2..6eec130 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/skip-rtree-sidx-06.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/skip-rtree-sidx-06.plan
@@ -1,8 +1,16 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (st-within($$geo.getField(1), OGCPolygon: POLYGON ((1 1, 5 1, 5 5, 1 5, 1 1))))
       -- STREAM_SELECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (IndexGeoJSON.Geometries)  |PARTITIONED|
+          data-scan []<-[$$17, $$geo] <- IndexGeoJSON.Geometries
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/skip-rtree-sidx-07.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/skip-rtree-sidx-07.plan
index 7cd72c2..50a9f95 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/skip-rtree-sidx-07.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-geometry/skip-rtree-sidx-07.plan
@@ -1,8 +1,16 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (st-disjoint($$geo.getField(1), OGCPolygon: POLYGON ((1 1, 5 1, 5 5, 1 5, 1 1))))
       -- STREAM_SELECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (IndexGeoJSON.Geometries)  |PARTITIONED|
+          data-scan []<-[$$17, $$geo] <- IndexGeoJSON.Geometries
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01_ps.plan
index 582253a..893833c 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01_ps.plan
@@ -1,133 +1,260 @@
+distribute result [$$50]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$50])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$50] <- [{"tweetid1": $$61, "loc1": $$93, "nearby-message": $$49}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$61)
           -- STABLE_SORT [$$61(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$61(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$97
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- PRE_CLUSTERED_GROUP_BY[$$94]  |PARTITIONED|
-                              {
+                      group by ([$$61 := $$94]) decor ([$$93]) {
+                                aggregate [$$49] <- [listify({"tweetid2": $$55, "loc2": $$56})]
                                 -- AGGREGATE  |LOCAL|
+                                  select (not(is-missing($$55)))
                                   -- STREAM_SELECT  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- PRE_CLUSTERED_GROUP_BY[$$94]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$94) (ASC, $$55)
                           -- STABLE_SORT [$$94(ASC), $$55(ASC)]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$94]  |PARTITIONED|
+                              union ($$90, $$73, $$55) ($$92, $$75, $$56) ($$53, $$53, $$93) ($$54, $$54, $$94)
                               -- UNION_ALL  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$90, $$92, $$53, $$54])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    select (spatial-intersect($$92, $$n)) retain-untrue ($$55 <- MISSING)
                                     -- STREAM_SELECT  |PARTITIONED|
+                                      project ([$$54, $$53, $$n, $$73, $$90, $$92])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$92] <- [$$91.getField(2)]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                            left-outer-unnest-map [$$90, $$91] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$73, 1, $$73, true, true, true)
+                                            -- BTREE_SEARCH  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$54, $$53, $$n, $$73])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    split ($$74)
                                                     -- SPLIT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        project ([$$54, $$53, $$n, $$69, $$70, $$73, $$74])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- RTREE_SEARCH (test.TweetMessages.twmSndLocIx)  |PARTITIONED|
+                                                            left-outer-unnest-map [$$69, $$70, $$71, $$72, $$73, $$74] <- index-search("twmSndLocIx", 1, "test", "TweetMessages", true, true, 4, $$65, $$66, $$67, $$68)
+                                                            -- RTREE_SEARCH  |PARTITIONED|
+                                                              exchange
                                                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                assign [$$65, $$66, $$67, $$68] <- [create-mbr($$n, 2, 0), create-mbr($$n, 2, 1), create-mbr($$n, 2, 2), create-mbr($$n, 2, 3)]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  assign [$$n] <- [create-circle($$53, 0.5)]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    project ([$$54, $$53])
                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                      assign [$$53] <- [$$t1.getField(2)]
                                                                       -- ASSIGN  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                          -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                          unnest-map [$$54, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$62, true, false, false)
+                                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              assign [$$62] <- [10]
                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                empty-tuple-source
                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$73, $$75, $$53, $$54])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    select (spatial-intersect($$75, $$n)) retain-untrue ($$55 <- MISSING)
                                     -- STREAM_SELECT  |PARTITIONED|
+                                      project ([$$54, $$53, $$n, $$73, $$75])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$75] <- [create-point($$69, $$70)]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$54, $$53, $$n, $$69, $$70, $$73])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              split ($$74)
                                               -- SPLIT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  project ([$$54, $$53, $$n, $$69, $$70, $$73, $$74])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- RTREE_SEARCH (test.TweetMessages.twmSndLocIx)  |PARTITIONED|
+                                                      left-outer-unnest-map [$$69, $$70, $$71, $$72, $$73, $$74] <- index-search("twmSndLocIx", 1, "test", "TweetMessages", true, true, 4, $$65, $$66, $$67, $$68)
+                                                      -- RTREE_SEARCH  |PARTITIONED|
+                                                        exchange
                                                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                          assign [$$65, $$66, $$67, $$68] <- [create-mbr($$n, 2, 0), create-mbr($$n, 2, 1), create-mbr($$n, 2, 2), create-mbr($$n, 2, 3)]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            assign [$$n] <- [create-circle($$53, 0.5)]
                                                             -- ASSIGN  |PARTITIONED|
+                                                              project ([$$54, $$53])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$53] <- [$$t1.getField(2)]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                    unnest-map [$$54, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$62, true, false, false)
+                                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        assign [$$62] <- [10]
                                                                         -- ASSIGN  |PARTITIONED|
+                                                                          empty-tuple-source
                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$97] <- [agg-range-map($$95, $$96)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$95, $$96] <- [agg-local-sampling($$61), agg-null-writer($$61)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$61])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- PRE_CLUSTERED_GROUP_BY[$$94]  |PARTITIONED|
-                                        {
+                                group by ([$$61 := $$94]) decor ([$$93]) {
+                                          aggregate [$$49] <- [listify({"tweetid2": $$55, "loc2": $$56})]
                                           -- AGGREGATE  |LOCAL|
+                                            select (not(is-missing($$55)))
                                             -- STREAM_SELECT  |LOCAL|
+                                              nested tuple source
                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- PRE_CLUSTERED_GROUP_BY[$$94]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$94) (ASC, $$55)
                                     -- STABLE_SORT [$$94(ASC), $$55(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$94]  |PARTITIONED|
+                                        union ($$90, $$73, $$55) ($$92, $$75, $$56) ($$53, $$53, $$93) ($$54, $$54, $$94)
                                         -- UNION_ALL  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$90, $$92, $$53, $$54])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              select (spatial-intersect($$92, $$n)) retain-untrue ($$55 <- MISSING)
                                               -- STREAM_SELECT  |PARTITIONED|
+                                                project ([$$54, $$53, $$n, $$73, $$90, $$92])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$92] <- [$$91.getField(2)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                      left-outer-unnest-map [$$90, $$91] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$73, 1, $$73, true, true, true)
+                                                      -- BTREE_SEARCH  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          project ([$$54, $$53, $$n, $$73])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              split ($$74)
                                                               -- SPLIT  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  project ([$$54, $$53, $$n, $$69, $$70, $$73, $$74])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- RTREE_SEARCH (test.TweetMessages.twmSndLocIx)  |PARTITIONED|
+                                                                      left-outer-unnest-map [$$69, $$70, $$71, $$72, $$73, $$74] <- index-search("twmSndLocIx", 1, "test", "TweetMessages", true, true, 4, $$65, $$66, $$67, $$68)
+                                                                      -- RTREE_SEARCH  |PARTITIONED|
+                                                                        exchange
                                                                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                          assign [$$65, $$66, $$67, $$68] <- [create-mbr($$n, 2, 0), create-mbr($$n, 2, 1), create-mbr($$n, 2, 2), create-mbr($$n, 2, 3)]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            assign [$$n] <- [create-circle($$53, 0.5)]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              project ([$$54, $$53])
                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                assign [$$53] <- [$$t1.getField(2)]
                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                    -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                                    unnest-map [$$54, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$62, true, false, false)
+                                                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                        assign [$$62] <- [10]
                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                          empty-tuple-source
                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$73, $$75, $$53, $$54])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              select (spatial-intersect($$75, $$n)) retain-untrue ($$55 <- MISSING)
                                               -- STREAM_SELECT  |PARTITIONED|
+                                                project ([$$54, $$53, $$n, $$73, $$75])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$75] <- [create-point($$69, $$70)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$54, $$53, $$n, $$69, $$70, $$73])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        split ($$74)
                                                         -- SPLIT  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            project ([$$54, $$53, $$n, $$69, $$70, $$73, $$74])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- RTREE_SEARCH (test.TweetMessages.twmSndLocIx)  |PARTITIONED|
+                                                                left-outer-unnest-map [$$69, $$70, $$71, $$72, $$73, $$74] <- index-search("twmSndLocIx", 1, "test", "TweetMessages", true, true, 4, $$65, $$66, $$67, $$68)
+                                                                -- RTREE_SEARCH  |PARTITIONED|
+                                                                  exchange
                                                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                    assign [$$65, $$66, $$67, $$68] <- [create-mbr($$n, 2, 0), create-mbr($$n, 2, 1), create-mbr($$n, 2, 2), create-mbr($$n, 2, 3)]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      assign [$$n] <- [create-circle($$53, 0.5)]
                                                                       -- ASSIGN  |PARTITIONED|
+                                                                        project ([$$54, $$53])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          assign [$$53] <- [$$t1.getField(2)]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                              -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                              unnest-map [$$54, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$62, true, false, false)
+                                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  assign [$$62] <- [10]
                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                    empty-tuple-source
                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02.plan
index b6e4dbc..9b559fb 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02.plan
@@ -1,37 +1,71 @@
+distribute result [$$54]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$54])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$54] <- [{"tweetid1": $$66, "loc1": $$57, "nearby-message": $$53}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$66(ASC) ]  |PARTITIONED|
-          -- PRE_CLUSTERED_GROUP_BY[$$58]  |PARTITIONED|
-                  {
+          group by ([$$66 := $$58]) decor ([$$57]) {
+                    aggregate [$$53] <- [listify({"tweetid2": $$59, "loc2": $$61})]
                     -- AGGREGATE  |LOCAL|
+                      select (not(is-missing($$59)))
                       -- STREAM_SELECT  |LOCAL|
+                        nested tuple source
                         -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- PRE_CLUSTERED_GROUP_BY[$$58]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$58) (ASC, $$59)
               -- STABLE_SORT [$$58(ASC), $$59(ASC)]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$58]  |PARTITIONED|
+                  project ([$$57, $$59, $$61, $$58])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    select (and(spatial-intersect($$61, $$n), neq($$58, $$59))) retain-untrue ($$59 <- MISSING)
                     -- STREAM_SELECT  |PARTITIONED|
+                      project ([$$57, $$58, $$n, $$59, $$61])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$61] <- [$$t2.getField(2)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$57, $$58, $$n, $$59, $$t2])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                              left-outer-unnest-map [$$59, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$78, 1, $$78, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  order (ASC, $$78)
                                   -- STABLE_SORT [$$78(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$57, $$58, $$n, $$78])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- RTREE_SEARCH (test.TweetMessages.twmSndLocIx)  |PARTITIONED|
+                                          left-outer-unnest-map [$$74, $$75, $$76, $$77, $$78] <- index-search("twmSndLocIx", 1, "test", "TweetMessages", true, true, 4, $$70, $$71, $$72, $$73)
+                                          -- RTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                              assign [$$70, $$71, $$72, $$73] <- [create-mbr($$n, 2, 0), create-mbr($$n, 2, 1), create-mbr($$n, 2, 2), create-mbr($$n, 2, 3)]
                                               -- ASSIGN  |PARTITIONED|
+                                                assign [$$n] <- [create-circle($$57, 0.5)]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  project ([$$58, $$57])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    assign [$$57] <- [$$t1.getField(2)]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                        unnest-map [$$58, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$67, true, false, false)
+                                                        -- BTREE_SEARCH  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            assign [$$67] <- [10]
                                                             -- ASSIGN  |PARTITIONED|
+                                                              empty-tuple-source
                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02_ps.plan
index e183f09..7bf35d8 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02_ps.plan
@@ -1,83 +1,160 @@
+distribute result [$$54]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$54])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$54] <- [{"tweetid1": $$66, "loc1": $$57, "nearby-message": $$53}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$66)
           -- STABLE_SORT [$$66(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$66(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$81
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- PRE_CLUSTERED_GROUP_BY[$$58]  |PARTITIONED|
-                              {
+                      group by ([$$66 := $$58]) decor ([$$57]) {
+                                aggregate [$$53] <- [listify({"tweetid2": $$59, "loc2": $$61})]
                                 -- AGGREGATE  |LOCAL|
+                                  select (not(is-missing($$59)))
                                   -- STREAM_SELECT  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- PRE_CLUSTERED_GROUP_BY[$$58]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$58) (ASC, $$59)
                           -- STABLE_SORT [$$58(ASC), $$59(ASC)]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$58]  |PARTITIONED|
+                              project ([$$57, $$59, $$61, $$58])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                select (and(spatial-intersect($$61, $$n), neq($$58, $$59))) retain-untrue ($$59 <- MISSING)
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  project ([$$57, $$58, $$n, $$59, $$61])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$61] <- [$$t2.getField(2)]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$57, $$58, $$n, $$59, $$t2])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                          left-outer-unnest-map [$$59, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$78, 1, $$78, true, true, true)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              order (ASC, $$78)
                                               -- STABLE_SORT [$$78(ASC)]  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  project ([$$57, $$58, $$n, $$78])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- RTREE_SEARCH (test.TweetMessages.twmSndLocIx)  |PARTITIONED|
+                                                      left-outer-unnest-map [$$74, $$75, $$76, $$77, $$78] <- index-search("twmSndLocIx", 1, "test", "TweetMessages", true, true, 4, $$70, $$71, $$72, $$73)
+                                                      -- RTREE_SEARCH  |PARTITIONED|
+                                                        exchange
                                                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                          assign [$$70, $$71, $$72, $$73] <- [create-mbr($$n, 2, 0), create-mbr($$n, 2, 1), create-mbr($$n, 2, 2), create-mbr($$n, 2, 3)]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            assign [$$n] <- [create-circle($$57, 0.5)]
                                                             -- ASSIGN  |PARTITIONED|
+                                                              project ([$$58, $$57])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$57] <- [$$t1.getField(2)]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                    unnest-map [$$58, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$67, true, false, false)
+                                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        assign [$$67] <- [10]
                                                                         -- ASSIGN  |PARTITIONED|
+                                                                          empty-tuple-source
                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$81] <- [agg-range-map($$79, $$80)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$79, $$80] <- [agg-local-sampling($$66), agg-null-writer($$66)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$66])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- PRE_CLUSTERED_GROUP_BY[$$58]  |PARTITIONED|
-                                        {
+                                group by ([$$66 := $$58]) decor ([$$57]) {
+                                          aggregate [$$53] <- [listify({"tweetid2": $$59, "loc2": $$61})]
                                           -- AGGREGATE  |LOCAL|
+                                            select (not(is-missing($$59)))
                                             -- STREAM_SELECT  |LOCAL|
+                                              nested tuple source
                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- PRE_CLUSTERED_GROUP_BY[$$58]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$58) (ASC, $$59)
                                     -- STABLE_SORT [$$58(ASC), $$59(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$58]  |PARTITIONED|
+                                        project ([$$57, $$59, $$61, $$58])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          select (and(spatial-intersect($$61, $$n), neq($$58, $$59))) retain-untrue ($$59 <- MISSING)
                                           -- STREAM_SELECT  |PARTITIONED|
+                                            project ([$$57, $$58, $$n, $$59, $$61])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$61] <- [$$t2.getField(2)]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$57, $$58, $$n, $$59, $$t2])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                    left-outer-unnest-map [$$59, $$t2] <- index-search("TweetMessages", 0, "test", "TweetMessages", true, false, 1, $$78, 1, $$78, true, true, true)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        order (ASC, $$78)
                                                         -- STABLE_SORT [$$78(ASC)]  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            project ([$$57, $$58, $$n, $$78])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- RTREE_SEARCH (test.TweetMessages.twmSndLocIx)  |PARTITIONED|
+                                                                left-outer-unnest-map [$$74, $$75, $$76, $$77, $$78] <- index-search("twmSndLocIx", 1, "test", "TweetMessages", true, true, 4, $$70, $$71, $$72, $$73)
+                                                                -- RTREE_SEARCH  |PARTITIONED|
+                                                                  exchange
                                                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                    assign [$$70, $$71, $$72, $$73] <- [create-mbr($$n, 2, 0), create-mbr($$n, 2, 1), create-mbr($$n, 2, 2), create-mbr($$n, 2, 3)]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      assign [$$n] <- [create-circle($$57, 0.5)]
                                                                       -- ASSIGN  |PARTITIONED|
+                                                                        project ([$$58, $$57])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          assign [$$57] <- [$$t1.getField(2)]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                              -- BTREE_SEARCH (test.TweetMessages.TweetMessages)  |PARTITIONED|
+                                                                              unnest-map [$$58, $$t1] <- index-search("TweetMessages", 0, "test", "TweetMessages", false, false, 0, 1, $$67, true, false, false)
+                                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  assign [$$67] <- [10]
                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                    empty-tuple-source
                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-join/spatial-intersect-point_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-join/spatial-intersect-point_02.plan
index c992324..25d37eb 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-join/spatial-intersect-point_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-join/spatial-intersect-point_02.plan
@@ -1,23 +1,46 @@
+distribute result [$$27]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$27])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$27] <- [{"a": $$a, "b": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (spatial-intersect($$30, $$b.getField(1)))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$a, $$30, $$b])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- BTREE_SEARCH (test.MyData2.MyData2)  |PARTITIONED|
+                unnest-map [$$29, $$b] <- index-search("MyData2", 0, "test", "MyData2", true, false, 1, $$40, 1, $$40, true, true, true)
+                -- BTREE_SEARCH  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    order (ASC, $$40)
                     -- STABLE_SORT [$$40(ASC)]  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$a, $$30, $$40])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- RTREE_SEARCH (test.MyData2.rtree_index)  |PARTITIONED|
+                            unnest-map [$$36, $$37, $$38, $$39, $$40] <- index-search("rtree_index", 1, "test", "MyData2", true, true, 4, $$32, $$33, $$34, $$35)
+                            -- RTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                assign [$$32, $$33, $$34, $$35] <- [create-mbr($$30, 2, 0), create-mbr($$30, 2, 1), create-mbr($$30, 2, 2), create-mbr($$30, 2, 3)]
                                 -- ASSIGN  |PARTITIONED|
+                                  assign [$$30] <- [$$a.getField(1)]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$a])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (test.MyData1)  |PARTITIONED|
+                                        data-scan []<-[$$28, $$a] <- test.MyData1
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-join/spatial-intersect-point_03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-join/spatial-intersect-point_03.plan
index e5d716f..31be7fc 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-join/spatial-intersect-point_03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index-join/spatial-intersect-point_03.plan
@@ -1,23 +1,46 @@
+distribute result [$$27]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$27])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$27] <- [{"a": $$a, "b": $$b}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$a, $$b])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (spatial-intersect($$30, $$b.getField(1)))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$a, $$30, $$b])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- BTREE_SEARCH (test.MyData.MyData)  |PARTITIONED|
+                unnest-map [$$29, $$b] <- index-search("MyData", 0, "test", "MyData", true, false, 1, $$40, 1, $$40, true, true, true)
+                -- BTREE_SEARCH  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    order (ASC, $$40)
                     -- STABLE_SORT [$$40(ASC)]  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$a, $$30, $$40])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- RTREE_SEARCH (test.MyData.rtree_index)  |PARTITIONED|
+                            unnest-map [$$36, $$37, $$38, $$39, $$40] <- index-search("rtree_index", 1, "test", "MyData", true, true, 4, $$32, $$33, $$34, $$35)
+                            -- RTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                assign [$$32, $$33, $$34, $$35] <- [create-mbr($$30, 2, 0), create-mbr($$30, 2, 1), create-mbr($$30, 2, 2), create-mbr($$30, 2, 3)]
                                 -- ASSIGN  |PARTITIONED|
+                                  assign [$$30] <- [$$a.getField(1)]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$a])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (test.MyData)  |PARTITIONED|
+                                        data-scan []<-[$$28, $$a] <- test.MyData
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index/rtree-sidx-idxonly-01-disable-idxonly.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index/rtree-sidx-idxonly-01-disable-idxonly.plan
index 50ddb2c..2547fae 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index/rtree-sidx-idxonly-01-disable-idxonly.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index/rtree-sidx-idxonly-01-disable-idxonly.plan
@@ -1,20 +1,40 @@
+distribute result [$$50]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$50])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$50] <- [{"$1": $$53}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$53] <- [agg-sql-sum($$54)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$54] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (spatial-intersect($$x.getField(8), polygon: [ point: { x: 0.0, y: 0.0 }, point: { x: 2.0, y: 2.0 }, point: { x: 0.0, y: 2.0 }, point: { x: 2.0, y: 0.0 } ]))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$x])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- BTREE_SEARCH (test.Fragile_raw.Fragile_raw)  |PARTITIONED|
+                    unnest-map [$$52, $$x] <- index-search("Fragile_raw", 0, "test", "Fragile_raw", false, false, 1, $$63, 1, $$63, true, true, true)
+                    -- BTREE_SEARCH  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        order (ASC, $$63)
                         -- STABLE_SORT [$$63(ASC)]  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$63])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- RTREE_SEARCH (test.Fragile_raw.cfLocation)  |PARTITIONED|
+                                unnest-map [$$59, $$60, $$61, $$62, $$63] <- index-search("cfLocation", 1, "test", "Fragile_raw", false, false, 4, $$55, $$56, $$57, $$58)
+                                -- RTREE_SEARCH  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    assign [$$55, $$56, $$57, $$58] <- [0.0, 0.0, 2.0, 2.0]
                                     -- ASSIGN  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index/rtree-sidx-idxonly-01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index/rtree-sidx-idxonly-01.plan
index a87edbc..2dbe7c4 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index/rtree-sidx-idxonly-01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/rtree-index/rtree-sidx-idxonly-01.plan
@@ -1,37 +1,74 @@
+distribute result [$$50]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$50])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$50] <- [{"$1": $$53}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$53] <- [agg-sql-sum($$54)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$54] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                union
                 -- UNION_ALL  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      select (spatial-intersect($$73.getField(8), polygon: [ point: { x: 0.0, y: 0.0 }, point: { x: 2.0, y: 2.0 }, point: { x: 0.0, y: 2.0 }, point: { x: 2.0, y: 0.0 } ]))
                       -- STREAM_SELECT  |PARTITIONED|
+                        project ([$$73])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.Fragile_raw.Fragile_raw)  |PARTITIONED|
+                            unnest-map [$$72, $$73] <- index-search("Fragile_raw", 0, "test", "Fragile_raw", false, false, 1, $$63, 1, $$63, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                split ($$64)
                                 -- SPLIT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$59, $$60, $$63, $$64])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- RTREE_SEARCH (test.Fragile_raw.cfLocation)  |PARTITIONED|
+                                        unnest-map [$$59, $$60, $$61, $$62, $$63, $$64] <- index-search("cfLocation", 1, "test", "Fragile_raw", false, false, 4, $$55, $$56, $$57, $$58)
+                                        -- RTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            assign [$$55, $$56, $$57, $$58] <- [0.0, 0.0, 2.0, 2.0]
                                             -- ASSIGN  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      select (spatial-intersect(create-point($$59, $$60), polygon: [ point: { x: 0.0, y: 0.0 }, point: { x: 2.0, y: 2.0 }, point: { x: 0.0, y: 2.0 }, point: { x: 2.0, y: 0.0 } ]))
                       -- STREAM_SELECT  |PARTITIONED|
+                        project ([$$59, $$60])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            split ($$64)
                             -- SPLIT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$59, $$60, $$63, $$64])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- RTREE_SEARCH (test.Fragile_raw.cfLocation)  |PARTITIONED|
+                                    unnest-map [$$59, $$60, $$61, $$62, $$63, $$64] <- index-search("cfLocation", 1, "test", "Fragile_raw", false, false, 4, $$55, $$56, $$57, $$58)
+                                    -- RTREE_SEARCH  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        assign [$$55, $$56, $$57, $$58] <- [0.0, 0.0, 2.0, 2.0]
                                         -- ASSIGN  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/skip-index/skip-ngram-index_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/skip-index/skip-ngram-index_ps.plan
index 93ca5bd..d6a002c 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/skip-index/skip-ngram-index_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/skip-index/skip-ngram-index_ps.plan
@@ -1,28 +1,56 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$o])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$15)
         -- STABLE_SORT [$$15(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$15(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$20
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (contains($$o.getField(2), "Multimedia"))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                        data-scan []<-[$$15, $$o] <- test.DBLP
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$20] <- [agg-range-map($$18, $$19)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$18, $$19] <- [agg-local-sampling($$15), agg-null-writer($$15)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$15])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (contains($$o.getField(2), "Multimedia"))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                  data-scan []<-[$$15, $$o] <- test.DBLP
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/skip-index/skip-secondary-btree-index-2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/skip-index/skip-secondary-btree-index-2.plan
index 74f6ebd..4ba5004 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/skip-index/skip-secondary-btree-index-2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/skip-index/skip-secondary-btree-index-2.plan
@@ -1,17 +1,34 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$emp])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (and(ge($$17, "Max"), le($$17, "Roger")))
       -- STREAM_SELECT  |PARTITIONED|
+        assign [$$17] <- [$$emp.getField(1)]
         -- ASSIGN  |PARTITIONED|
+          project ([$$emp])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- BTREE_SEARCH (test.testdst.testdst)  |PARTITIONED|
+              unnest-map [$$18, $$emp] <- index-search("testdst", 0, "test", "testdst", false, false, 1, $$21, 1, $$21, true, true, true)
+              -- BTREE_SEARCH  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  order (ASC, $$21)
                   -- STABLE_SORT [$$21(ASC)]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$21])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (test.testdst.sec_Idx)  |PARTITIONED|
+                          unnest-map [$$20, $$21] <- index-search("sec_Idx", 0, "test", "testdst", false, false, 0, 1, $$19, true, true, false)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              assign [$$19] <- ["Roger"]
                               -- ASSIGN  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/skip-index/skip-secondary-btree-index-3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/skip-index/skip-secondary-btree-index-3.plan
index 4a65a41..1a1d2ec 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/skip-index/skip-secondary-btree-index-3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/skip-index/skip-secondary-btree-index-3.plan
@@ -1,15 +1,30 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$emp])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        join (eq($$18, $$15))
         -- HYBRID_HASH_JOIN [$$15][$$18]  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            assign [$$15] <- [$$emp.getField(1)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$emp])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+                  data-scan []<-[$$17, $$emp] <- test.testdst
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+          exchange
           -- BROADCAST_EXCHANGE  |PARTITIONED|
+            unnest $$18 <- scan-collection(array: [ "Roger", "Max" ])
             -- UNNEST  |UNPARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/spatial_join/spatial_intersect_dynamic_partitioning.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/spatial_join/spatial_intersect_dynamic_partitioning.plan
index ce4f736..66df922 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/spatial_join/spatial_intersect_dynamic_partitioning.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/spatial_join/spatial_intersect_dynamic_partitioning.plan
@@ -1,156 +1,312 @@
+distribute result [$$46]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$46])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$46] <- [{"$1": $$51}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$51] <- [agg-sql-sum($$52)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$52] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                join (eq($$60, reference-tile($$49, $$50, $$57, 100, 100, $$61)))
                 -- NESTED_LOOP  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    join (spatial-intersect($$49, $$50))
                     -- SPATIAL_JOIN [$$60, $$49] [$$61, $$50]  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        order (ASC, $$60) (ASC, $$49)
                         -- STABLE_SORT [$$60(ASC), $$49(ASC)]  |PARTITIONED|
+                          exchange
                           -- HASH_PARTITION_EXCHANGE [$$60]  |PARTITIONED|
+                            project ([$$49, $$60])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              unnest $$60 <- spatial-tile($$49, $$58, 100, 100)
                               -- UNNEST  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  join (true)
                                   -- NESTED_LOOP  |PARTITIONED|
+                                    exchange
                                     -- RANDOM_PARTITION_EXCHANGE  |PARTITIONED|
+                                      replicate
                                       -- REPLICATE  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$49])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$49] <- [$$ps.getField(1)]
                                             -- ASSIGN  |PARTITIONED|
+                                              project ([$$ps])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- DATASOURCE_SCAN (test.ParkSet)  |PARTITIONED|
+                                                  data-scan []<-[$$47, $$ps] <- test.ParkSet
+                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$58])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$58] <- [$$57]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$57])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$57] <- [get-intersection($$54, $$56)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                      join (true)
                                                       -- NESTED_LOOP  |UNPARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                          aggregate [$$54] <- [agg-global-union_mbr($$53)]
                                                           -- AGGREGATE  |UNPARTITIONED|
+                                                            exchange
                                                             -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                                                              aggregate [$$53] <- [agg-local-union_mbr($$49)]
                                                               -- AGGREGATE  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  replicate
                                                                   -- REPLICATE  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      project ([$$49])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        assign [$$49] <- [$$ps.getField(1)]
                                                                         -- ASSIGN  |PARTITIONED|
+                                                                          project ([$$ps])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                              -- DATASOURCE_SCAN (test.ParkSet)  |PARTITIONED|
+                                                                              data-scan []<-[$$47, $$ps] <- test.ParkSet
+                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  empty-tuple-source
                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                          aggregate [$$56] <- [agg-global-union_mbr($$55)]
                                                           -- AGGREGATE  |UNPARTITIONED|
+                                                            exchange
                                                             -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                                                              aggregate [$$55] <- [agg-local-union_mbr($$50)]
                                                               -- AGGREGATE  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  replicate
                                                                   -- REPLICATE  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      project ([$$50])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        assign [$$50] <- [$$ls.getField(1)]
                                                                         -- ASSIGN  |PARTITIONED|
+                                                                          project ([$$ls])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                              -- DATASOURCE_SCAN (test.LakeSet)  |PARTITIONED|
+                                                                              data-scan []<-[$$48, $$ls] <- test.LakeSet
+                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  empty-tuple-source
                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        order (ASC, $$61) (ASC, $$50)
                         -- STABLE_SORT [$$61(ASC), $$50(ASC)]  |PARTITIONED|
+                          exchange
                           -- HASH_PARTITION_EXCHANGE [$$61]  |PARTITIONED|
+                            project ([$$50, $$61])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              unnest $$61 <- spatial-tile($$50, $$59, 100, 100)
                               -- UNNEST  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  join (true)
                                   -- NESTED_LOOP  |PARTITIONED|
+                                    exchange
                                     -- RANDOM_PARTITION_EXCHANGE  |PARTITIONED|
+                                      replicate
                                       -- REPLICATE  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$50])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$50] <- [$$ls.getField(1)]
                                             -- ASSIGN  |PARTITIONED|
+                                              project ([$$ls])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- DATASOURCE_SCAN (test.LakeSet)  |PARTITIONED|
+                                                  data-scan []<-[$$48, $$ls] <- test.LakeSet
+                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$59])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$59] <- [$$57]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$57])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$57] <- [get-intersection($$54, $$56)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                      join (true)
                                                       -- NESTED_LOOP  |UNPARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                          aggregate [$$54] <- [agg-global-union_mbr($$53)]
                                                           -- AGGREGATE  |UNPARTITIONED|
+                                                            exchange
                                                             -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                                                              aggregate [$$53] <- [agg-local-union_mbr($$49)]
                                                               -- AGGREGATE  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  replicate
                                                                   -- REPLICATE  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      project ([$$49])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        assign [$$49] <- [$$ps.getField(1)]
                                                                         -- ASSIGN  |PARTITIONED|
+                                                                          project ([$$ps])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                              -- DATASOURCE_SCAN (test.ParkSet)  |PARTITIONED|
+                                                                              data-scan []<-[$$47, $$ps] <- test.ParkSet
+                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  empty-tuple-source
                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                          aggregate [$$56] <- [agg-global-union_mbr($$55)]
                                                           -- AGGREGATE  |UNPARTITIONED|
+                                                            exchange
                                                             -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                                                              aggregate [$$55] <- [agg-local-union_mbr($$50)]
                                                               -- AGGREGATE  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  replicate
                                                                   -- REPLICATE  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      project ([$$50])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        assign [$$50] <- [$$ls.getField(1)]
                                                                         -- ASSIGN  |PARTITIONED|
+                                                                          project ([$$ls])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                              -- DATASOURCE_SCAN (test.LakeSet)  |PARTITIONED|
+                                                                              data-scan []<-[$$48, $$ls] <- test.LakeSet
+                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  empty-tuple-source
                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$57])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$57] <- [get-intersection($$54, $$56)]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                              join (true)
                               -- NESTED_LOOP  |UNPARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                  aggregate [$$54] <- [agg-global-union_mbr($$53)]
                                   -- AGGREGATE  |UNPARTITIONED|
+                                    exchange
                                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                                      aggregate [$$53] <- [agg-local-union_mbr($$49)]
                                       -- AGGREGATE  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          replicate
                                           -- REPLICATE  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$49])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$49] <- [$$ps.getField(1)]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  project ([$$ps])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.ParkSet)  |PARTITIONED|
+                                                      data-scan []<-[$$47, $$ps] <- test.ParkSet
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                  aggregate [$$56] <- [agg-global-union_mbr($$55)]
                                   -- AGGREGATE  |UNPARTITIONED|
+                                    exchange
                                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                                      aggregate [$$55] <- [agg-local-union_mbr($$50)]
                                       -- AGGREGATE  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          replicate
                                           -- REPLICATE  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$50])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$50] <- [$$ls.getField(1)]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  project ([$$ls])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.LakeSet)  |PARTITIONED|
+                                                      data-scan []<-[$$48, $$ls] <- test.LakeSet
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/spatial_join/spatial_intersect_static_partitioning.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/spatial_join/spatial_intersect_static_partitioning.plan
index ce2f6e6..e0b7960 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/spatial_join/spatial_intersect_static_partitioning.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/spatial_join/spatial_intersect_static_partitioning.plan
@@ -1,32 +1,64 @@
+distribute result [$$46]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$46])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$46] <- [{"$1": $$51}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$51] <- [agg-sql-sum($$52)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$52] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (eq($$53, reference-tile($$49, $$50, rectangle: { p1: point: { x: -180.0, y: -83.0 }, p2: point: { x: 180.0, y: 90.0 }}, 10, 10, $$54)))
               -- STREAM_SELECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  join (spatial-intersect($$49, $$50))
                   -- SPATIAL_JOIN [$$53, $$49] [$$54, $$50]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$53) (ASC, $$49)
                       -- STABLE_SORT [$$53(ASC), $$49(ASC)]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$53]  |PARTITIONED|
+                          unnest $$53 <- spatial-tile($$49, rectangle: { p1: point: { x: -180.0, y: -83.0 }, p2: point: { x: 180.0, y: 90.0 }}, 10, 10)
                           -- UNNEST  |PARTITIONED|
+                            project ([$$49])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$49] <- [$$ps.getField(1)]
                               -- ASSIGN  |PARTITIONED|
+                                project ([$$ps])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (test.ParkSet)  |PARTITIONED|
+                                    data-scan []<-[$$47, $$ps] <- test.ParkSet
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$54) (ASC, $$50)
                       -- STABLE_SORT [$$54(ASC), $$50(ASC)]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$54]  |PARTITIONED|
+                          unnest $$54 <- spatial-tile($$50, rectangle: { p1: point: { x: -180.0, y: -83.0 }, p2: point: { x: 180.0, y: 90.0 }}, 10, 10)
                           -- UNNEST  |PARTITIONED|
+                            project ([$$50])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$50] <- [$$ls.getField(1)]
                               -- ASSIGN  |PARTITIONED|
+                                project ([$$ls])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (test.LakeSet)  |PARTITIONED|
+                                    data-scan []<-[$$48, $$ls] <- test.LakeSet
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/spatial_join/st_distance_static_partitioning.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/spatial_join/st_distance_static_partitioning.plan
index f66785b..25398dc 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/spatial_join/st_distance_static_partitioning.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/spatial_join/st_distance_static_partitioning.plan
@@ -1,34 +1,68 @@
+distribute result [$$47]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$47])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$47] <- [{"$1": $$51}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$51] <- [agg-sql-sum($$61)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$61] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(lt(st-distance($$54, $$55), 1), eq($$62, reference-tile($$56, $$57, rectangle: { p1: point: { x: -180.0, y: -83.0 }, p2: point: { x: 180.0, y: 90.0 }}, 10, 10, $$63))))
               -- STREAM_SELECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  join (spatial-intersect($$56, $$57))
                   -- SPATIAL_JOIN [$$62, $$56] [$$63, $$57]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$62) (ASC, $$56)
                       -- STABLE_SORT [$$62(ASC), $$56(ASC)]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$62]  |PARTITIONED|
+                          unnest $$62 <- spatial-tile($$56, rectangle: { p1: point: { x: -180.0, y: -83.0 }, p2: point: { x: 180.0, y: 90.0 }}, 10, 10)
                           -- UNNEST  |PARTITIONED|
+                            assign [$$56] <- [st-mbr-enlarge($$54, 1)]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$54])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$54] <- [$$ps.getField(1)]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$ps])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.ParkSet)  |PARTITIONED|
+                                      data-scan []<-[$$48, $$ps] <- test.ParkSet
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$63) (ASC, $$57)
                       -- STABLE_SORT [$$63(ASC), $$57(ASC)]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$63]  |PARTITIONED|
+                          unnest $$63 <- spatial-tile($$57, rectangle: { p1: point: { x: -180.0, y: -83.0 }, p2: point: { x: 180.0, y: 90.0 }}, 10, 10)
                           -- UNNEST  |PARTITIONED|
+                            assign [$$57] <- [st-mbr($$55)]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$55])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$55] <- [$$ls.getField(1)]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$ls])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.LakeSet)  |PARTITIONED|
+                                      data-scan []<-[$$49, $$ls] <- test.LakeSet
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/spatial_join/st_intersects_static_partitioning.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/spatial_join/st_intersects_static_partitioning.plan
index 43d8da6..f5e0ec1 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/spatial_join/st_intersects_static_partitioning.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/spatial_join/st_intersects_static_partitioning.plan
@@ -1,34 +1,68 @@
+distribute result [$$46]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$46])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$46] <- [{"$1": $$49}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$49] <- [agg-sql-sum($$54)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$54] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(st-intersects($$50, $$51), eq($$55, reference-tile($$52, $$53, rectangle: { p1: point: { x: -180.0, y: -83.0 }, p2: point: { x: 180.0, y: 90.0 }}, 10, 10, $$56))))
               -- STREAM_SELECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  join (spatial-intersect($$52, $$53))
                   -- SPATIAL_JOIN [$$55, $$52] [$$56, $$53]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$55) (ASC, $$52)
                       -- STABLE_SORT [$$55(ASC), $$52(ASC)]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$55]  |PARTITIONED|
+                          unnest $$55 <- spatial-tile($$52, rectangle: { p1: point: { x: -180.0, y: -83.0 }, p2: point: { x: 180.0, y: 90.0 }}, 10, 10)
                           -- UNNEST  |PARTITIONED|
+                            assign [$$52] <- [st-mbr($$50)]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$50])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$50] <- [$$ps.getField(1)]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$ps])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.ParkSet)  |PARTITIONED|
+                                      data-scan []<-[$$47, $$ps] <- test.ParkSet
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$56) (ASC, $$53)
                       -- STABLE_SORT [$$56(ASC), $$53(ASC)]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$56]  |PARTITIONED|
+                          unnest $$56 <- spatial-tile($$53, rectangle: { p1: point: { x: -180.0, y: -83.0 }, p2: point: { x: 180.0, y: 90.0 }}, 10, 10)
                           -- UNNEST  |PARTITIONED|
+                            assign [$$53] <- [st-mbr($$51)]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$51])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$51] <- [$$ls.getField(1)]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$ls])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.LakeSet)  |PARTITIONED|
+                                      data-scan []<-[$$48, $$ls] <- test.LakeSet
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/split-materialization.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/split-materialization.plan
index 56d5533..9c780b5 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/split-materialization.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/split-materialization.plan
@@ -1,31 +1,62 @@
+distribute result [$$86]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$86])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$86] <- [{"user1": {"id": $$91, "name": $$97}, "user2": {"id": $$92, "name": $$98}}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$91(ASC), $$92(ASC) ]  |PARTITIONED|
+          order (ASC, $$91) (ASC, $$92)
           -- STABLE_SORT [$$91(ASC), $$92(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              join (lt($$91, $$92))
               -- NESTED_LOOP  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$91, $$97])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$91, $$97] <- [$$92, $$98]
                     -- ASSIGN  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        replicate
                         -- REPLICATE  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$92, $$98])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              select (lt(count($$d.getField(4)), 2))
                               -- STREAM_SELECT  |PARTITIONED|
+                                assign [$$98] <- [$$d.getField(2)]
                                 -- ASSIGN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (TinySocial.FacebookUsers)  |PARTITIONED|
+                                    data-scan []<-[$$92, $$d] <- TinySocial.FacebookUsers
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$92, $$98])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (lt(count($$d.getField(4)), 2))
                         -- STREAM_SELECT  |PARTITIONED|
+                          assign [$$98] <- [$$d.getField(2)]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (TinySocial.FacebookUsers)  |PARTITIONED|
+                              data-scan []<-[$$92, $$d] <- TinySocial.FacebookUsers
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/split-materialization_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/split-materialization_ps.plan
index 8ba2609..6625240 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/split-materialization_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/split-materialization_ps.plan
@@ -1,67 +1,134 @@
+distribute result [$$86]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$86])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$86] <- [{"user1": {"id": $$91, "name": $$97}, "user2": {"id": $$92, "name": $$98}}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$91) (ASC, $$92)
           -- STABLE_SORT [$$91(ASC), $$92(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$91(ASC), $$92(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$102
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (lt($$91, $$92))
                       -- NESTED_LOOP  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$91, $$97])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$91, $$97] <- [$$92, $$98]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                replicate
                                 -- REPLICATE  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$92, $$98])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      select (lt(count($$d.getField(4)), 2))
                                       -- STREAM_SELECT  |PARTITIONED|
+                                        assign [$$98] <- [$$d.getField(2)]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (TinySocial.FacebookUsers)  |PARTITIONED|
+                                            data-scan []<-[$$92, $$d] <- TinySocial.FacebookUsers
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$92, $$98])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                select (lt(count($$d.getField(4)), 2))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  assign [$$98] <- [$$d.getField(2)]
                                   -- ASSIGN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (TinySocial.FacebookUsers)  |PARTITIONED|
+                                      data-scan []<-[$$92, $$d] <- TinySocial.FacebookUsers
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$102] <- [agg-range-map($$99, $$100, $$101)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$99, $$100, $$101] <- [agg-local-sampling($$91, $$92), agg-null-writer($$91), agg-null-writer($$92)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$91, $$92])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                join (lt($$91, $$92))
                                 -- NESTED_LOOP  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$91, $$97])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$91, $$97] <- [$$92, $$98]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          replicate
                                           -- REPLICATE  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$92, $$98])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                select (lt(count($$d.getField(4)), 2))
                                                 -- STREAM_SELECT  |PARTITIONED|
+                                                  assign [$$98] <- [$$d.getField(2)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (TinySocial.FacebookUsers)  |PARTITIONED|
+                                                      data-scan []<-[$$92, $$d] <- TinySocial.FacebookUsers
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                  exchange
                                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                    replicate
                                     -- REPLICATE  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$92, $$98])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          select (lt(count($$d.getField(4)), 2))
                                           -- STREAM_SELECT  |PARTITIONED|
+                                            assign [$$98] <- [$$d.getField(2)]
                                             -- ASSIGN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- DATASOURCE_SCAN (TinySocial.FacebookUsers)  |PARTITIONED|
+                                                data-scan []<-[$$92, $$d] <- TinySocial.FacebookUsers
+                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/statement-params/statement-params-01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/statement-params/statement-params-01.plan
index e800b4e..3ab38ae 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/statement-params/statement-params-01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/statement-params/statement-params-01.plan
@@ -1,17 +1,34 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"c_id": $$17}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$17])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$t.getField("c_s"), "hello"))
           -- STREAM_SELECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+              unnest-map [$$17, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$23, 1, $$23, true, true, true)
+              -- BTREE_SEARCH  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  order (ASC, $$23)
                   -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$23])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (test.TestOpen.idx_s)  |PARTITIONED|
+                          unnest-map [$$22, $$23] <- index-search("idx_s", 0, "test", "TestOpen", false, false, 1, $$20, 1, $$21, true, true, true)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              assign [$$20, $$21] <- ["hello", "hello"]
                               -- ASSIGN  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/statement-params/statement-params-02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/statement-params/statement-params-02.plan
index e800b4e..3ab38ae 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/statement-params/statement-params-02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/statement-params/statement-params-02.plan
@@ -1,17 +1,34 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"c_id": $$17}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$17])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$t.getField("c_s"), "hello"))
           -- STREAM_SELECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+              unnest-map [$$17, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$23, 1, $$23, true, true, true)
+              -- BTREE_SEARCH  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  order (ASC, $$23)
                   -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$23])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (test.TestOpen.idx_s)  |PARTITIONED|
+                          unnest-map [$$22, $$23] <- index-search("idx_s", 0, "test", "TestOpen", false, false, 1, $$20, 1, $$21, true, true, true)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              assign [$$20, $$21] <- ["hello", "hello"]
                               -- ASSIGN  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/statement-params/statement-params-03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/statement-params/statement-params-03.plan
index e800b4e..3ab38ae 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/statement-params/statement-params-03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/statement-params/statement-params-03.plan
@@ -1,17 +1,34 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"c_id": $$17}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$17])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$t.getField("c_s"), "hello"))
           -- STREAM_SELECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- BTREE_SEARCH (test.TestOpen.TestOpen)  |PARTITIONED|
+              unnest-map [$$17, $$t] <- index-search("TestOpen", 0, "test", "TestOpen", false, false, 1, $$23, 1, $$23, true, true, true)
+              -- BTREE_SEARCH  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  order (ASC, $$23)
                   -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$23])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- BTREE_SEARCH (test.TestOpen.idx_s)  |PARTITIONED|
+                          unnest-map [$$22, $$23] <- index-search("idx_s", 0, "test", "TestOpen", false, false, 1, $$20, 1, $$21, true, true, true)
+                          -- BTREE_SEARCH  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              assign [$$20, $$21] <- ["hello", "hello"]
                               -- ASSIGN  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/statement-params/statement-params-index-01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/statement-params/statement-params-index-01.plan
index 0d47f5c..a5620bb 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/statement-params/statement-params-index-01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/statement-params/statement-params-index-01.plan
@@ -1,19 +1,38 @@
+distribute result [$$26]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$26])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$26] <- [{"id": $$29, "fname": $$28, "lname": $$32, "age": $$33}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$29(ASC) ]  |PARTITIONED|
+          select (eq($$28, "Julio"))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$29, $$33, $$32, $$28])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$33, $$32, $$28] <- [$$l.getField(3), $$l.getField(2), $$l.getField(1)]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.employee.employee)  |PARTITIONED|
+                  unnest-map [$$29, $$l] <- index-search("employee", 0, "test", "employee", false, false, 1, $$37, 1, $$37, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$37)
                       -- STABLE_SORT [$$37(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$37])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.employee.idx_employee_fname)  |PARTITIONED|
+                              unnest-map [$$36, $$37] <- index-search("idx_employee_fname", 0, "test", "employee", false, false, 1, $$34, 1, $$35, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  assign [$$34, $$35] <- ["Julio", "Julio"]
                                   -- ASSIGN  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/statement-params/statement-params-index-02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/statement-params/statement-params-index-02.plan
index 3febc19..a9d3ae6 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/statement-params/statement-params-index-02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/statement-params/statement-params-index-02.plan
@@ -1,30 +1,60 @@
+distribute result [$$26]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$26])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$26] <- [{"id": $$30, "fname": $$28, "lname": $$29, "age": $$33}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$30(ASC) ]  |PARTITIONED|
+          select (and(eq($$29, "Isa"), eq($$28, "Julio")))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$30, $$33, $$28, $$29])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$33, $$28, $$29] <- [$$l.getField(3), $$l.getField(1), $$l.getField(2)]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.employee.employee)  |PARTITIONED|
+                  unnest-map [$$30, $$l] <- index-search("employee", 0, "test", "employee", false, false, 1, $$42, 1, $$42, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      intersect [$$42] <- [[$$37], [$$41]]
                       -- INTERSECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$37)
                           -- STABLE_SORT [$$37(ASC)]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$37])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.employee.idx_employee_fname)  |PARTITIONED|
+                                  unnest-map [$$36, $$37] <- index-search("idx_employee_fname", 0, "test", "employee", false, false, 1, $$34, 1, $$35, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      assign [$$34, $$35] <- ["Julio", "Julio"]
                                       -- ASSIGN  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$41)
                           -- STABLE_SORT [$$41(ASC)]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$41])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (test.employee.idx_employee_lname)  |PARTITIONED|
+                                  unnest-map [$$40, $$41] <- index-search("idx_employee_lname", 0, "test", "employee", false, false, 1, $$38, 1, $$39, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      assign [$$38, $$39] <- ["Isa", "Isa"]
                                       -- ASSIGN  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/exists.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/exists.plan
index b81c831..1cd998a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/exists.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/exists.plan
@@ -1,74 +1,136 @@
+distribute result [$$161]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$161])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$161] <- [{"cntrycode": $$cntrycode, "numcust": $$164, "totacctbal": $$165}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$cntrycode(ASC) ]  |PARTITIONED|
-          -- SORT_GROUP_BY[$$187]  |PARTITIONED|
-                  {
+          group by ([$$cntrycode := $$187]) decor ([]) {
+                    aggregate [$$164, $$165] <- [agg-sql-sum($$185), agg-global-sql-sum($$186)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- SORT_GROUP_BY[$$187]  |PARTITIONED|
+            exchange
             -- HASH_PARTITION_EXCHANGE [$$187]  |PARTITIONED|
-              -- SORT_GROUP_BY[$$162]  |PARTITIONED|
-                      {
+              group by ([$$187 := $$162]) decor ([]) {
+                        aggregate [$$185, $$186] <- [agg-sql-count($$122), agg-local-sql-sum($$173)]
                         -- AGGREGATE  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SORT_GROUP_BY[$$162]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$122, $$173, $$162])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$162] <- [substring($$175, 0, 2)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$122, $$173, $$175])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (neq($$163, 0))
                         -- STREAM_SELECT  |PARTITIONED|
+                          project ([$$163, $$122, $$173, $$175])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- SORT_GROUP_BY[$$184]  |PARTITIONED|
-                                      {
+                              group by ([$$180 := $$184]) decor ([$$122; $$173; $$175]) {
+                                        aggregate [$$163] <- [agg-sum($$183)]
                                         -- AGGREGATE  |LOCAL|
+                                          nested tuple source
                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                      }
+                                     }
+                              -- SORT_GROUP_BY[$$184]  |PARTITIONED|
+                                exchange
                                 -- HASH_PARTITION_EXCHANGE [$$184]  |PARTITIONED|
-                                  -- PRE_CLUSTERED_GROUP_BY[$$178]  |PARTITIONED|
-                                          {
+                                  group by ([$$184 := $$178]) decor ([$$122; $$173; $$175]) {
+                                            aggregate [$$183] <- [agg-count({"o": $$o})]
                                             -- AGGREGATE  |LOCAL|
+                                              select (not(is-missing($$179)))
                                               -- STREAM_SELECT  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                         }
+                                  -- PRE_CLUSTERED_GROUP_BY[$$178]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$178)
                                       -- STABLE_SORT [$$178(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$122, $$173, $$175, $$o, $$179, $$178])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              left outer join (eq($$171, $$174))
                                               -- HYBRID_HASH_JOIN [$$174][$$171]  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$174]  |PARTITIONED|
+                                                  running-aggregate [$$178] <- [create-query-uid()]
                                                   -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                    project ([$$122, $$173, $$175, $$174])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        join (gt($$173, $$170))
                                                         -- NESTED_LOOP  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            assign [$$122] <- [{"c_acctbal": $$173, "c_custkey": $$174, "cntrycode": substring($$175, 0, 2)}]
                                                             -- ASSIGN  |PARTITIONED|
+                                                              project ([$$175, $$174, $$173])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$175, $$174, $$173] <- [$$Customer.getField(4), $$Customer.getField(0), $$Customer.getField(5)]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (test.Customer)  |PARTITIONED|
+                                                                    data-scan []<-[$$Customer] <- test.Customer
+                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        empty-tuple-source
                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                          exchange
                                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                            project ([$$170])
                                                             -- STREAM_PROJECT  |UNPARTITIONED|
+                                                              assign [$$170] <- [get-item($$136, 0)]
                                                               -- ASSIGN  |UNPARTITIONED|
+                                                                aggregate [$$136] <- [listify($$182)]
                                                                 -- AGGREGATE  |UNPARTITIONED|
+                                                                  aggregate [$$182] <- [agg-global-sql-avg($$188)]
                                                                   -- AGGREGATE  |UNPARTITIONED|
+                                                                    exchange
                                                                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                                                                      aggregate [$$188] <- [agg-local-sql-avg($$176)]
                                                                       -- AGGREGATE  |PARTITIONED|
+                                                                        select (gt($$176, 0.0))
                                                                         -- STREAM_SELECT  |PARTITIONED|
+                                                                          project ([$$176])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            assign [$$176] <- [$$168.getField(5)]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                -- DATASOURCE_SCAN (test.Customer)  |PARTITIONED|
+                                                                                data-scan []<-[$$168] <- test.Customer
+                                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    empty-tuple-source
                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$171]  |PARTITIONED|
+                                                  assign [$$179, $$171] <- [true, $$o.getField(1)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.Orders)  |PARTITIONED|
+                                                      data-scan []<-[$$o] <- test.Orders
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/exists_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/exists_ps.plan
index 2cccba4..d31762a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/exists_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/exists_ps.plan
@@ -1,157 +1,290 @@
+distribute result [$$161]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$161])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$161] <- [{"cntrycode": $$cntrycode, "numcust": $$164, "totacctbal": $$165}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$cntrycode)
           -- STABLE_SORT [$$cntrycode(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$cntrycode(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$192
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- SORT_GROUP_BY[$$187]  |PARTITIONED|
-                              {
+                      group by ([$$cntrycode := $$187]) decor ([]) {
+                                aggregate [$$164, $$165] <- [agg-sql-sum($$185), agg-global-sql-sum($$186)]
                                 -- AGGREGATE  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- SORT_GROUP_BY[$$187]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$187]  |PARTITIONED|
-                          -- SORT_GROUP_BY[$$162]  |PARTITIONED|
-                                  {
+                          group by ([$$187 := $$162]) decor ([]) {
+                                    aggregate [$$185, $$186] <- [agg-sql-count($$122), agg-local-sql-sum($$173)]
                                     -- AGGREGATE  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                  }
+                                 }
+                          -- SORT_GROUP_BY[$$162]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$122, $$173, $$162])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$162] <- [substring($$175, 0, 2)]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$122, $$173, $$175])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    select (neq($$163, 0))
                                     -- STREAM_SELECT  |PARTITIONED|
+                                      project ([$$163, $$122, $$173, $$175])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- SORT_GROUP_BY[$$184]  |PARTITIONED|
-                                                  {
+                                          group by ([$$180 := $$184]) decor ([$$122; $$173; $$175]) {
+                                                    aggregate [$$163] <- [agg-sum($$183)]
                                                     -- AGGREGATE  |LOCAL|
+                                                      nested tuple source
                                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                  }
+                                                 }
+                                          -- SORT_GROUP_BY[$$184]  |PARTITIONED|
+                                            exchange
                                             -- HASH_PARTITION_EXCHANGE [$$184]  |PARTITIONED|
-                                              -- PRE_CLUSTERED_GROUP_BY[$$178]  |PARTITIONED|
-                                                      {
+                                              group by ([$$184 := $$178]) decor ([$$122; $$173; $$175]) {
+                                                        aggregate [$$183] <- [agg-count({"o": $$o})]
                                                         -- AGGREGATE  |LOCAL|
+                                                          select (not(is-missing($$179)))
                                                           -- STREAM_SELECT  |LOCAL|
+                                                            nested tuple source
                                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                      }
+                                                     }
+                                              -- PRE_CLUSTERED_GROUP_BY[$$178]  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  order (ASC, $$178)
                                                   -- STABLE_SORT [$$178(ASC)]  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      project ([$$122, $$173, $$175, $$o, $$179, $$178])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          left outer join (eq($$171, $$174))
                                                           -- HYBRID_HASH_JOIN [$$174][$$171]  |PARTITIONED|
+                                                            exchange
                                                             -- HASH_PARTITION_EXCHANGE [$$174]  |PARTITIONED|
+                                                              running-aggregate [$$178] <- [create-query-uid()]
                                                               -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                                project ([$$122, $$173, $$175, $$174])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    join (gt($$173, $$170))
                                                                     -- NESTED_LOOP  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        assign [$$122] <- [{"c_acctbal": $$173, "c_custkey": $$174, "cntrycode": substring($$175, 0, 2)}]
                                                                         -- ASSIGN  |PARTITIONED|
+                                                                          project ([$$175, $$174, $$173])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            assign [$$175, $$174, $$173] <- [$$Customer.getField(4), $$Customer.getField(0), $$Customer.getField(5)]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                -- DATASOURCE_SCAN (test.Customer)  |PARTITIONED|
+                                                                                data-scan []<-[$$Customer] <- test.Customer
+                                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    empty-tuple-source
                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                      exchange
                                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                        project ([$$170])
                                                                         -- STREAM_PROJECT  |UNPARTITIONED|
+                                                                          assign [$$170] <- [get-item($$136, 0)]
                                                                           -- ASSIGN  |UNPARTITIONED|
+                                                                            aggregate [$$136] <- [listify($$182)]
                                                                             -- AGGREGATE  |UNPARTITIONED|
+                                                                              aggregate [$$182] <- [agg-global-sql-avg($$188)]
                                                                               -- AGGREGATE  |UNPARTITIONED|
+                                                                                exchange
                                                                                 -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                                                                                  aggregate [$$188] <- [agg-local-sql-avg($$176)]
                                                                                   -- AGGREGATE  |PARTITIONED|
+                                                                                    select (gt($$176, 0.0))
                                                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                                                      project ([$$176])
                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                        assign [$$176] <- [$$168.getField(5)]
                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                            -- DATASOURCE_SCAN (test.Customer)  |PARTITIONED|
+                                                                                            data-scan []<-[$$168] <- test.Customer
+                                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                              exchange
                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                empty-tuple-source
                                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                            exchange
                                                             -- HASH_PARTITION_EXCHANGE [$$171]  |PARTITIONED|
+                                                              assign [$$179, $$171] <- [true, $$o.getField(1)]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- DATASOURCE_SCAN (test.Orders)  |PARTITIONED|
+                                                                  data-scan []<-[$$o] <- test.Orders
+                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      empty-tuple-source
                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$192] <- [agg-range-map($$190, $$191)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$190, $$191] <- [agg-local-sampling($$cntrycode), agg-null-writer($$cntrycode)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$cntrycode])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- SORT_GROUP_BY[$$187]  |PARTITIONED|
-                                        {
+                                group by ([$$cntrycode := $$187]) decor ([]) {
+                                          aggregate [$$164, $$165] <- [agg-sql-sum($$185), agg-global-sql-sum($$186)]
                                           -- AGGREGATE  |LOCAL|
+                                            nested tuple source
                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- SORT_GROUP_BY[$$187]  |PARTITIONED|
+                                  exchange
                                   -- HASH_PARTITION_EXCHANGE [$$187]  |PARTITIONED|
-                                    -- SORT_GROUP_BY[$$162]  |PARTITIONED|
-                                            {
+                                    group by ([$$187 := $$162]) decor ([]) {
+                                              aggregate [$$185, $$186] <- [agg-sql-count($$122), agg-local-sql-sum($$173)]
                                               -- AGGREGATE  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                            }
+                                           }
+                                    -- SORT_GROUP_BY[$$162]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$122, $$173, $$162])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$162] <- [substring($$175, 0, 2)]
                                           -- ASSIGN  |PARTITIONED|
+                                            project ([$$122, $$173, $$175])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              select (neq($$163, 0))
                                               -- STREAM_SELECT  |PARTITIONED|
+                                                project ([$$163, $$122, $$173, $$175])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- SORT_GROUP_BY[$$184]  |PARTITIONED|
-                                                            {
+                                                    group by ([$$180 := $$184]) decor ([$$122; $$173; $$175]) {
+                                                              aggregate [$$163] <- [agg-sum($$183)]
                                                               -- AGGREGATE  |LOCAL|
+                                                                nested tuple source
                                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                            }
+                                                           }
+                                                    -- SORT_GROUP_BY[$$184]  |PARTITIONED|
+                                                      exchange
                                                       -- HASH_PARTITION_EXCHANGE [$$184]  |PARTITIONED|
-                                                        -- PRE_CLUSTERED_GROUP_BY[$$178]  |PARTITIONED|
-                                                                {
+                                                        group by ([$$184 := $$178]) decor ([$$122; $$173; $$175]) {
+                                                                  aggregate [$$183] <- [agg-count({"o": $$o})]
                                                                   -- AGGREGATE  |LOCAL|
+                                                                    select (not(is-missing($$179)))
                                                                     -- STREAM_SELECT  |LOCAL|
+                                                                      nested tuple source
                                                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                }
+                                                               }
+                                                        -- PRE_CLUSTERED_GROUP_BY[$$178]  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            order (ASC, $$178)
                                                             -- STABLE_SORT [$$178(ASC)]  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                project ([$$122, $$173, $$175, $$o, $$179, $$178])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    left outer join (eq($$171, $$174))
                                                                     -- HYBRID_HASH_JOIN [$$174][$$171]  |PARTITIONED|
+                                                                      exchange
                                                                       -- HASH_PARTITION_EXCHANGE [$$174]  |PARTITIONED|
+                                                                        running-aggregate [$$178] <- [create-query-uid()]
                                                                         -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                                          project ([$$122, $$173, $$175, $$174])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              join (gt($$173, $$170))
                                                                               -- NESTED_LOOP  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  assign [$$122] <- [{"c_acctbal": $$173, "c_custkey": $$174, "cntrycode": substring($$175, 0, 2)}]
                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                    project ([$$175, $$174, $$173])
                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                      assign [$$175, $$174, $$173] <- [$$Customer.getField(4), $$Customer.getField(0), $$Customer.getField(5)]
                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                        exchange
                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                          -- DATASOURCE_SCAN (test.Customer)  |PARTITIONED|
+                                                                                          data-scan []<-[$$Customer] <- test.Customer
+                                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                            exchange
                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                              empty-tuple-source
                                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                exchange
                                                                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                  project ([$$170])
                                                                                   -- STREAM_PROJECT  |UNPARTITIONED|
+                                                                                    assign [$$170] <- [get-item($$136, 0)]
                                                                                     -- ASSIGN  |UNPARTITIONED|
+                                                                                      aggregate [$$136] <- [listify($$182)]
                                                                                       -- AGGREGATE  |UNPARTITIONED|
+                                                                                        aggregate [$$182] <- [agg-global-sql-avg($$188)]
                                                                                         -- AGGREGATE  |UNPARTITIONED|
+                                                                                          exchange
                                                                                           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                                                                                            aggregate [$$188] <- [agg-local-sql-avg($$176)]
                                                                                             -- AGGREGATE  |PARTITIONED|
+                                                                                              select (gt($$176, 0.0))
                                                                                               -- STREAM_SELECT  |PARTITIONED|
+                                                                                                project ([$$176])
                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                  assign [$$176] <- [$$168.getField(5)]
                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                    exchange
                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                      -- DATASOURCE_SCAN (test.Customer)  |PARTITIONED|
+                                                                                                      data-scan []<-[$$168] <- test.Customer
+                                                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                        exchange
                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                          empty-tuple-source
                                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                      exchange
                                                                       -- HASH_PARTITION_EXCHANGE [$$171]  |PARTITIONED|
+                                                                        assign [$$179, $$171] <- [true, $$o.getField(1)]
                                                                         -- ASSIGN  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                            -- DATASOURCE_SCAN (test.Orders)  |PARTITIONED|
+                                                                            data-scan []<-[$$o] <- test.Orders
+                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                empty-tuple-source
                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in.plan
index bac3df2..4c4c598 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in.plan
@@ -1,35 +1,67 @@
+distribute result [$$44]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$44])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$44] <- [{"customer_name": $$50}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$50(ASC) ]  |PARTITIONED|
+          order (ASC, $$50)
           -- STABLE_SORT [$$50(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$50])
               -- STREAM_PROJECT  |PARTITIONED|
+                select ($$38)
                 -- STREAM_SELECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- PRE_CLUSTERED_GROUP_BY[$$45]  |PARTITIONED|
-                            {
+                    group by ([$$50 := $$45]) decor ([]) {
+                              aggregate [$$38] <- [non-empty-stream()]
                               -- AGGREGATE  |LOCAL|
+                                select (not(is-missing($$49)))
                                 -- STREAM_SELECT  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                            }
+                           }
+                    -- PRE_CLUSTERED_GROUP_BY[$$45]  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$49, $$45])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            left outer join (eq($$45, $$34))
                             -- HYBRID_HASH_JOIN [$$45][$$34]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$45])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  select (eq($$c.getField("c_nationkey"), 5))
                                   -- STREAM_SELECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                      data-scan []<-[$$45, $$c] <- test.Customers
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$34]  |PARTITIONED|
+                                project ([$$49, $$34])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  assign [$$49, $$34] <- [true, $$o.getField("o_custkey")]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$o])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (test.Orders)  |PARTITIONED|
+                                        data-scan []<-[$$46, $$o] <- test.Orders
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_1.plan
index fd9c4a4..0067e4f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_1.plan
@@ -1,17 +1,34 @@
+distribute result [$$20]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$20(ASC) ]  |PARTITIONED|
+    order (ASC, $$20)
     -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$20])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$21, $$15))
             -- HYBRID_HASH_JOIN [$$15][$$21]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$20, $$15])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$15] <- [$$c.getField(1)]
                   -- ASSIGN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (tpch.Customer)  |PARTITIONED|
+                      data-scan []<-[$$20, $$c] <- tpch.Customer
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                unnest $$21 <- scan-collection(array: [ "Customer#000000003", "Customer#000000002", "Customer#000000001" ])
                 -- UNNEST  |UNPARTITIONED|
+                  empty-tuple-source
                   -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_1_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_1_ps.plan
index 0eb2166..9e2e716 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_1_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_1_ps.plan
@@ -1,41 +1,82 @@
+distribute result [$$20]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    order (ASC, $$20)
     -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+      exchange
       -- RANGE_PARTITION_EXCHANGE [$$20(ASC)]  |PARTITIONED|
+        forward: shared-variable = $$25
         -- FORWARD  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            replicate
             -- REPLICATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$20])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    join (eq($$21, $$15))
                     -- HYBRID_HASH_JOIN [$$15][$$21]  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$20, $$15])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$15] <- [$$c.getField(1)]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (tpch.Customer)  |PARTITIONED|
+                              data-scan []<-[$$20, $$c] <- tpch.Customer
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      exchange
                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                        unnest $$21 <- scan-collection(array: [ "Customer#000000003", "Customer#000000002", "Customer#000000001" ])
                         -- UNNEST  |UNPARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+          exchange
           -- BROADCAST_EXCHANGE  |PARTITIONED|
+            aggregate [$$25] <- [agg-range-map($$23, $$24)]
             -- AGGREGATE  |UNPARTITIONED|
+              exchange
               -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                aggregate [$$23, $$24] <- [agg-local-sampling($$20), agg-null-writer($$20)]
                 -- AGGREGATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$20])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            join (eq($$21, $$15))
                             -- HYBRID_HASH_JOIN [$$15][$$21]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$20, $$15])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  assign [$$15] <- [$$c.getField(1)]
                                   -- ASSIGN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (tpch.Customer)  |PARTITIONED|
+                                      data-scan []<-[$$20, $$c] <- tpch.Customer
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                unnest $$21 <- scan-collection(array: [ "Customer#000000003", "Customer#000000002", "Customer#000000001" ])
                                 -- UNNEST  |UNPARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_2.plan
index 22ea58a..56fd8b6 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_2.plan
@@ -1,28 +1,53 @@
+distribute result [$$25]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$25(ASC) ]  |PARTITIONED|
+    project ([$$25])
     -- STREAM_PROJECT  |PARTITIONED|
+      select ($$17)
       -- STREAM_SELECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- PRE_CLUSTERED_GROUP_BY[$$21]  |PARTITIONED|
-                  {
+          group by ([$$25 := $$21]) decor ([]) {
+                    aggregate [$$17] <- [non-empty-stream()]
                     -- AGGREGATE  |LOCAL|
+                      select (not(is-missing($$24)))
                       -- STREAM_SELECT  |LOCAL|
+                        nested tuple source
                         -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- PRE_CLUSTERED_GROUP_BY[$$21]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$21)
               -- STABLE_SORT [$$21(ASC)]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$21]  |PARTITIONED|
+                  project ([$$24, $$21])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      left outer join (eq($$22, $#1))
                       -- HYBRID_HASH_JOIN [$$22][$#1]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$22]  |PARTITIONED|
+                          project ([$$21, $$22])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$22] <- [$$c.getField(1)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (tpch.Customer)  |PARTITIONED|
+                                data-scan []<-[$$21, $$c] <- tpch.Customer
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$#1]  |PARTITIONED|
+                          assign [$$24] <- [true]
                           -- ASSIGN  |UNPARTITIONED|
+                            unnest $#1 <- scan-collection(array: [ "Customer#000000001", "Customer#000000002", "Customer#000000003" ])
                             -- UNNEST  |UNPARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_2_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_2_ps.plan
index 84a9315..31965a7 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_2_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_2_ps.plan
@@ -1,67 +1,128 @@
+distribute result [$$25]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    order (ASC, $$25)
     -- STABLE_SORT [$$25(ASC)]  |PARTITIONED|
+      exchange
       -- RANGE_PARTITION_EXCHANGE [$$25(ASC)]  |PARTITIONED|
+        forward: shared-variable = $$28
         -- FORWARD  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            replicate
             -- REPLICATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$25])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select ($$17)
                   -- STREAM_SELECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- PRE_CLUSTERED_GROUP_BY[$$21]  |PARTITIONED|
-                              {
+                      group by ([$$25 := $$21]) decor ([]) {
+                                aggregate [$$17] <- [non-empty-stream()]
                                 -- AGGREGATE  |LOCAL|
+                                  select (not(is-missing($$24)))
                                   -- STREAM_SELECT  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- PRE_CLUSTERED_GROUP_BY[$$21]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$21)
                           -- STABLE_SORT [$$21(ASC)]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$21]  |PARTITIONED|
+                              project ([$$24, $$21])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  left outer join (eq($$22, $#1))
                                   -- HYBRID_HASH_JOIN [$$22][$#1]  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$22]  |PARTITIONED|
+                                      project ([$$21, $$22])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$22] <- [$$c.getField(1)]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (tpch.Customer)  |PARTITIONED|
+                                            data-scan []<-[$$21, $$c] <- tpch.Customer
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$#1]  |PARTITIONED|
+                                      assign [$$24] <- [true]
                                       -- ASSIGN  |UNPARTITIONED|
+                                        unnest $#1 <- scan-collection(array: [ "Customer#000000001", "Customer#000000002", "Customer#000000003" ])
                                         -- UNNEST  |UNPARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+          exchange
           -- BROADCAST_EXCHANGE  |PARTITIONED|
+            aggregate [$$28] <- [agg-range-map($$26, $$27)]
             -- AGGREGATE  |UNPARTITIONED|
+              exchange
               -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                aggregate [$$26, $$27] <- [agg-local-sampling($$25), agg-null-writer($$25)]
                 -- AGGREGATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$25])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          select ($$17)
                           -- STREAM_SELECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- PRE_CLUSTERED_GROUP_BY[$$21]  |PARTITIONED|
-                                      {
+                              group by ([$$25 := $$21]) decor ([]) {
+                                        aggregate [$$17] <- [non-empty-stream()]
                                         -- AGGREGATE  |LOCAL|
+                                          select (not(is-missing($$24)))
                                           -- STREAM_SELECT  |LOCAL|
+                                            nested tuple source
                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                      }
+                                     }
+                              -- PRE_CLUSTERED_GROUP_BY[$$21]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  order (ASC, $$21)
                                   -- STABLE_SORT [$$21(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$21]  |PARTITIONED|
+                                      project ([$$24, $$21])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          left outer join (eq($$22, $#1))
                                           -- HYBRID_HASH_JOIN [$$22][$#1]  |PARTITIONED|
+                                            exchange
                                             -- HASH_PARTITION_EXCHANGE [$$22]  |PARTITIONED|
+                                              project ([$$21, $$22])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$22] <- [$$c.getField(1)]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (tpch.Customer)  |PARTITIONED|
+                                                    data-scan []<-[$$21, $$c] <- tpch.Customer
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                            exchange
                                             -- HASH_PARTITION_EXCHANGE [$#1]  |PARTITIONED|
+                                              assign [$$24] <- [true]
                                               -- ASSIGN  |UNPARTITIONED|
+                                                unnest $#1 <- scan-collection(array: [ "Customer#000000001", "Customer#000000002", "Customer#000000003" ])
                                                 -- UNNEST  |UNPARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_3.plan
index fd9c4a4..0067e4f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_3.plan
@@ -1,17 +1,34 @@
+distribute result [$$20]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$20(ASC) ]  |PARTITIONED|
+    order (ASC, $$20)
     -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$20])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$21, $$15))
             -- HYBRID_HASH_JOIN [$$15][$$21]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$20, $$15])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$15] <- [$$c.getField(1)]
                   -- ASSIGN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (tpch.Customer)  |PARTITIONED|
+                      data-scan []<-[$$20, $$c] <- tpch.Customer
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                unnest $$21 <- scan-collection(array: [ "Customer#000000003", "Customer#000000002", "Customer#000000001" ])
                 -- UNNEST  |UNPARTITIONED|
+                  empty-tuple-source
                   -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_3_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_3_ps.plan
index 0eb2166..9e2e716 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_3_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_3_ps.plan
@@ -1,41 +1,82 @@
+distribute result [$$20]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    order (ASC, $$20)
     -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+      exchange
       -- RANGE_PARTITION_EXCHANGE [$$20(ASC)]  |PARTITIONED|
+        forward: shared-variable = $$25
         -- FORWARD  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            replicate
             -- REPLICATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$20])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    join (eq($$21, $$15))
                     -- HYBRID_HASH_JOIN [$$15][$$21]  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$20, $$15])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$15] <- [$$c.getField(1)]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (tpch.Customer)  |PARTITIONED|
+                              data-scan []<-[$$20, $$c] <- tpch.Customer
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      exchange
                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                        unnest $$21 <- scan-collection(array: [ "Customer#000000003", "Customer#000000002", "Customer#000000001" ])
                         -- UNNEST  |UNPARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+          exchange
           -- BROADCAST_EXCHANGE  |PARTITIONED|
+            aggregate [$$25] <- [agg-range-map($$23, $$24)]
             -- AGGREGATE  |UNPARTITIONED|
+              exchange
               -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                aggregate [$$23, $$24] <- [agg-local-sampling($$20), agg-null-writer($$20)]
                 -- AGGREGATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$20])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            join (eq($$21, $$15))
                             -- HYBRID_HASH_JOIN [$$15][$$21]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$20, $$15])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  assign [$$15] <- [$$c.getField(1)]
                                   -- ASSIGN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (tpch.Customer)  |PARTITIONED|
+                                      data-scan []<-[$$20, $$c] <- tpch.Customer
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                unnest $$21 <- scan-collection(array: [ "Customer#000000003", "Customer#000000002", "Customer#000000001" ])
                                 -- UNNEST  |UNPARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_4.plan
index 5815097..c7ca6af 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_4.plan
@@ -1,28 +1,53 @@
+distribute result [$$24]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$24(ASC) ]  |PARTITIONED|
+    project ([$$24])
     -- STREAM_PROJECT  |PARTITIONED|
+      select ($$16)
       -- STREAM_SELECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- PRE_CLUSTERED_GROUP_BY[$$20]  |PARTITIONED|
-                  {
+          group by ([$$24 := $$20]) decor ([]) {
+                    aggregate [$$16] <- [non-empty-stream()]
                     -- AGGREGATE  |LOCAL|
+                      select (not(is-missing($$23)))
                       -- STREAM_SELECT  |LOCAL|
+                        nested tuple source
                         -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- PRE_CLUSTERED_GROUP_BY[$$20]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$20)
               -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$20]  |PARTITIONED|
+                  project ([$$23, $$20])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      left outer join (eq($$21, $#1))
                       -- HYBRID_HASH_JOIN [$$21][$#1]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$21]  |PARTITIONED|
+                          project ([$$20, $$21])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$21] <- [$$c.getField(1)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (tpch.Customer)  |PARTITIONED|
+                                data-scan []<-[$$20, $$c] <- tpch.Customer
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$#1]  |PARTITIONED|
+                          assign [$$23] <- [true]
                           -- ASSIGN  |UNPARTITIONED|
+                            unnest $#1 <- scan-collection(cast(array: [ "Customer#000000001", "Customer#000000002", "Customer#000000003" ]))
                             -- UNNEST  |UNPARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_4_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_4_ps.plan
index f7af324..cf90355 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_4_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_4_ps.plan
@@ -1,67 +1,128 @@
+distribute result [$$24]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    order (ASC, $$24)
     -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+      exchange
       -- RANGE_PARTITION_EXCHANGE [$$24(ASC)]  |PARTITIONED|
+        forward: shared-variable = $$27
         -- FORWARD  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            replicate
             -- REPLICATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$24])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select ($$16)
                   -- STREAM_SELECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- PRE_CLUSTERED_GROUP_BY[$$20]  |PARTITIONED|
-                              {
+                      group by ([$$24 := $$20]) decor ([]) {
+                                aggregate [$$16] <- [non-empty-stream()]
                                 -- AGGREGATE  |LOCAL|
+                                  select (not(is-missing($$23)))
                                   -- STREAM_SELECT  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- PRE_CLUSTERED_GROUP_BY[$$20]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$20)
                           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$20]  |PARTITIONED|
+                              project ([$$23, $$20])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  left outer join (eq($$21, $#1))
                                   -- HYBRID_HASH_JOIN [$$21][$#1]  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$21]  |PARTITIONED|
+                                      project ([$$20, $$21])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$21] <- [$$c.getField(1)]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (tpch.Customer)  |PARTITIONED|
+                                            data-scan []<-[$$20, $$c] <- tpch.Customer
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$#1]  |PARTITIONED|
+                                      assign [$$23] <- [true]
                                       -- ASSIGN  |UNPARTITIONED|
+                                        unnest $#1 <- scan-collection(cast(array: [ "Customer#000000001", "Customer#000000002", "Customer#000000003" ]))
                                         -- UNNEST  |UNPARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+          exchange
           -- BROADCAST_EXCHANGE  |PARTITIONED|
+            aggregate [$$27] <- [agg-range-map($$25, $$26)]
             -- AGGREGATE  |UNPARTITIONED|
+              exchange
               -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                aggregate [$$25, $$26] <- [agg-local-sampling($$24), agg-null-writer($$24)]
                 -- AGGREGATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$24])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          select ($$16)
                           -- STREAM_SELECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- PRE_CLUSTERED_GROUP_BY[$$20]  |PARTITIONED|
-                                      {
+                              group by ([$$24 := $$20]) decor ([]) {
+                                        aggregate [$$16] <- [non-empty-stream()]
                                         -- AGGREGATE  |LOCAL|
+                                          select (not(is-missing($$23)))
                                           -- STREAM_SELECT  |LOCAL|
+                                            nested tuple source
                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                      }
+                                     }
+                              -- PRE_CLUSTERED_GROUP_BY[$$20]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  order (ASC, $$20)
                                   -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$20]  |PARTITIONED|
+                                      project ([$$23, $$20])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          left outer join (eq($$21, $#1))
                                           -- HYBRID_HASH_JOIN [$$21][$#1]  |PARTITIONED|
+                                            exchange
                                             -- HASH_PARTITION_EXCHANGE [$$21]  |PARTITIONED|
+                                              project ([$$20, $$21])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$21] <- [$$c.getField(1)]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (tpch.Customer)  |PARTITIONED|
+                                                    data-scan []<-[$$20, $$c] <- tpch.Customer
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                            exchange
                                             -- HASH_PARTITION_EXCHANGE [$#1]  |PARTITIONED|
+                                              assign [$$23] <- [true]
                                               -- ASSIGN  |UNPARTITIONED|
+                                                unnest $#1 <- scan-collection(cast(array: [ "Customer#000000001", "Customer#000000002", "Customer#000000003" ]))
                                                 -- UNNEST  |UNPARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_5.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_5.plan
index fd9c4a4..0067e4f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_5.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_5.plan
@@ -1,17 +1,34 @@
+distribute result [$$20]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$20(ASC) ]  |PARTITIONED|
+    order (ASC, $$20)
     -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$20])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$21, $$15))
             -- HYBRID_HASH_JOIN [$$15][$$21]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$20, $$15])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$15] <- [$$c.getField(1)]
                   -- ASSIGN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (tpch.Customer)  |PARTITIONED|
+                      data-scan []<-[$$20, $$c] <- tpch.Customer
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                unnest $$21 <- scan-collection(array: [ "Customer#000000003", "Customer#000000002", "Customer#000000001" ])
                 -- UNNEST  |UNPARTITIONED|
+                  empty-tuple-source
                   -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_5_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_5_ps.plan
index 0eb2166..9e2e716 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_5_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_5_ps.plan
@@ -1,41 +1,82 @@
+distribute result [$$20]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    order (ASC, $$20)
     -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+      exchange
       -- RANGE_PARTITION_EXCHANGE [$$20(ASC)]  |PARTITIONED|
+        forward: shared-variable = $$25
         -- FORWARD  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            replicate
             -- REPLICATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$20])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    join (eq($$21, $$15))
                     -- HYBRID_HASH_JOIN [$$15][$$21]  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$20, $$15])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$15] <- [$$c.getField(1)]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (tpch.Customer)  |PARTITIONED|
+                              data-scan []<-[$$20, $$c] <- tpch.Customer
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      exchange
                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                        unnest $$21 <- scan-collection(array: [ "Customer#000000003", "Customer#000000002", "Customer#000000001" ])
                         -- UNNEST  |UNPARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+          exchange
           -- BROADCAST_EXCHANGE  |PARTITIONED|
+            aggregate [$$25] <- [agg-range-map($$23, $$24)]
             -- AGGREGATE  |UNPARTITIONED|
+              exchange
               -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                aggregate [$$23, $$24] <- [agg-local-sampling($$20), agg-null-writer($$20)]
                 -- AGGREGATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$20])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            join (eq($$21, $$15))
                             -- HYBRID_HASH_JOIN [$$15][$$21]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$20, $$15])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  assign [$$15] <- [$$c.getField(1)]
                                   -- ASSIGN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (tpch.Customer)  |PARTITIONED|
+                                      data-scan []<-[$$20, $$c] <- tpch.Customer
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                unnest $$21 <- scan-collection(array: [ "Customer#000000003", "Customer#000000002", "Customer#000000001" ])
                                 -- UNNEST  |UNPARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_6.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_6.plan
index 22ea58a..56fd8b6 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_6.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_6.plan
@@ -1,28 +1,53 @@
+distribute result [$$25]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$25(ASC) ]  |PARTITIONED|
+    project ([$$25])
     -- STREAM_PROJECT  |PARTITIONED|
+      select ($$17)
       -- STREAM_SELECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- PRE_CLUSTERED_GROUP_BY[$$21]  |PARTITIONED|
-                  {
+          group by ([$$25 := $$21]) decor ([]) {
+                    aggregate [$$17] <- [non-empty-stream()]
                     -- AGGREGATE  |LOCAL|
+                      select (not(is-missing($$24)))
                       -- STREAM_SELECT  |LOCAL|
+                        nested tuple source
                         -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- PRE_CLUSTERED_GROUP_BY[$$21]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$21)
               -- STABLE_SORT [$$21(ASC)]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$21]  |PARTITIONED|
+                  project ([$$24, $$21])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      left outer join (eq($$22, $#1))
                       -- HYBRID_HASH_JOIN [$$22][$#1]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$22]  |PARTITIONED|
+                          project ([$$21, $$22])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$22] <- [$$c.getField(1)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (tpch.Customer)  |PARTITIONED|
+                                data-scan []<-[$$21, $$c] <- tpch.Customer
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$#1]  |PARTITIONED|
+                          assign [$$24] <- [true]
                           -- ASSIGN  |UNPARTITIONED|
+                            unnest $#1 <- scan-collection(array: [ "Customer#000000001", "Customer#000000002", "Customer#000000003" ])
                             -- UNNEST  |UNPARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_6_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_6_ps.plan
index 84a9315..31965a7 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_6_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_as_or_6_ps.plan
@@ -1,67 +1,128 @@
+distribute result [$$25]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    order (ASC, $$25)
     -- STABLE_SORT [$$25(ASC)]  |PARTITIONED|
+      exchange
       -- RANGE_PARTITION_EXCHANGE [$$25(ASC)]  |PARTITIONED|
+        forward: shared-variable = $$28
         -- FORWARD  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            replicate
             -- REPLICATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$25])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select ($$17)
                   -- STREAM_SELECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- PRE_CLUSTERED_GROUP_BY[$$21]  |PARTITIONED|
-                              {
+                      group by ([$$25 := $$21]) decor ([]) {
+                                aggregate [$$17] <- [non-empty-stream()]
                                 -- AGGREGATE  |LOCAL|
+                                  select (not(is-missing($$24)))
                                   -- STREAM_SELECT  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- PRE_CLUSTERED_GROUP_BY[$$21]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$21)
                           -- STABLE_SORT [$$21(ASC)]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$21]  |PARTITIONED|
+                              project ([$$24, $$21])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  left outer join (eq($$22, $#1))
                                   -- HYBRID_HASH_JOIN [$$22][$#1]  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$22]  |PARTITIONED|
+                                      project ([$$21, $$22])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$22] <- [$$c.getField(1)]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (tpch.Customer)  |PARTITIONED|
+                                            data-scan []<-[$$21, $$c] <- tpch.Customer
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$#1]  |PARTITIONED|
+                                      assign [$$24] <- [true]
                                       -- ASSIGN  |UNPARTITIONED|
+                                        unnest $#1 <- scan-collection(array: [ "Customer#000000001", "Customer#000000002", "Customer#000000003" ])
                                         -- UNNEST  |UNPARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+          exchange
           -- BROADCAST_EXCHANGE  |PARTITIONED|
+            aggregate [$$28] <- [agg-range-map($$26, $$27)]
             -- AGGREGATE  |UNPARTITIONED|
+              exchange
               -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                aggregate [$$26, $$27] <- [agg-local-sampling($$25), agg-null-writer($$25)]
                 -- AGGREGATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$25])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          select ($$17)
                           -- STREAM_SELECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- PRE_CLUSTERED_GROUP_BY[$$21]  |PARTITIONED|
-                                      {
+                              group by ([$$25 := $$21]) decor ([]) {
+                                        aggregate [$$17] <- [non-empty-stream()]
                                         -- AGGREGATE  |LOCAL|
+                                          select (not(is-missing($$24)))
                                           -- STREAM_SELECT  |LOCAL|
+                                            nested tuple source
                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                      }
+                                     }
+                              -- PRE_CLUSTERED_GROUP_BY[$$21]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  order (ASC, $$21)
                                   -- STABLE_SORT [$$21(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$21]  |PARTITIONED|
+                                      project ([$$24, $$21])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          left outer join (eq($$22, $#1))
                                           -- HYBRID_HASH_JOIN [$$22][$#1]  |PARTITIONED|
+                                            exchange
                                             -- HASH_PARTITION_EXCHANGE [$$22]  |PARTITIONED|
+                                              project ([$$21, $$22])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$22] <- [$$c.getField(1)]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (tpch.Customer)  |PARTITIONED|
+                                                    data-scan []<-[$$21, $$c] <- tpch.Customer
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                            exchange
                                             -- HASH_PARTITION_EXCHANGE [$#1]  |PARTITIONED|
+                                              assign [$$24] <- [true]
                                               -- ASSIGN  |UNPARTITIONED|
+                                                unnest $#1 <- scan-collection(array: [ "Customer#000000001", "Customer#000000002", "Customer#000000003" ])
                                                 -- UNNEST  |UNPARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_correlated.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_correlated.plan
index 42c8f8f..d9910ff 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_correlated.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_correlated.plan
@@ -1,33 +1,63 @@
+distribute result [$$47]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$47])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$47] <- [{"customer_name": $$55}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$55(ASC) ]  |PARTITIONED|
+          order (ASC, $$55)
           -- STABLE_SORT [$$55(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$55])
               -- STREAM_PROJECT  |PARTITIONED|
+                select ($$41)
                 -- STREAM_SELECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- PRE_CLUSTERED_GROUP_BY[$$49]  |PARTITIONED|
-                            {
+                    group by ([$$55 := $$49]) decor ([]) {
+                              aggregate [$$41] <- [non-empty-stream()]
                               -- AGGREGATE  |LOCAL|
+                                select (and(eq($$49, $$48), not(is-missing($$54))))
                                 -- STREAM_SELECT  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                            }
+                           }
+                    -- PRE_CLUSTERED_GROUP_BY[$$49]  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        left outer join (eq($$49, $$48))
                         -- HYBRID_HASH_JOIN [$$49][$$48]  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$49])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              select (eq($$c.getField("c_nationkey"), 5))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                  data-scan []<-[$$49, $$c] <- test.Customers
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- HASH_PARTITION_EXCHANGE [$$48]  |PARTITIONED|
+                            project ([$$48, $$54])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$54, $$48] <- [true, $$o.getField("o_custkey")]
                               -- ASSIGN  |PARTITIONED|
+                                project ([$$o])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (test.Orders)  |PARTITIONED|
+                                    data-scan []<-[$$50, $$o] <- test.Orders
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                        empty-tuple-source
+                                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_correlated_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_correlated_ps.plan
index 85eb2da..84282f8 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_correlated_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_correlated_ps.plan
@@ -1,70 +1,134 @@
+distribute result [$$47]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$47])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$47] <- [{"customer_name": $$55}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$55)
           -- STABLE_SORT [$$55(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$55(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$58
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$55])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select ($$41)
                         -- STREAM_SELECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- PRE_CLUSTERED_GROUP_BY[$$49]  |PARTITIONED|
-                                    {
+                            group by ([$$55 := $$49]) decor ([]) {
+                                      aggregate [$$41] <- [non-empty-stream()]
                                       -- AGGREGATE  |LOCAL|
+                                        select (and(eq($$49, $$48), not(is-missing($$54))))
                                         -- STREAM_SELECT  |LOCAL|
+                                          nested tuple source
                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                    }
+                                   }
+                            -- PRE_CLUSTERED_GROUP_BY[$$49]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                left outer join (eq($$49, $$48))
                                 -- HYBRID_HASH_JOIN [$$49][$$48]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$49])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      select (eq($$c.getField("c_nationkey"), 5))
                                       -- STREAM_SELECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                          data-scan []<-[$$49, $$c] <- test.Customers
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                  exchange
                                   -- HASH_PARTITION_EXCHANGE [$$48]  |PARTITIONED|
+                                    project ([$$48, $$54])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$54, $$48] <- [true, $$o.getField("o_custkey")]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$o])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (test.Orders)  |PARTITIONED|
+                                            data-scan []<-[$$50, $$o] <- test.Orders
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$58] <- [agg-range-map($$56, $$57)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$56, $$57] <- [agg-local-sampling($$55), agg-null-writer($$55)]
                       -- AGGREGATE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$55])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                select ($$41)
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- PRE_CLUSTERED_GROUP_BY[$$49]  |PARTITIONED|
-                                            {
+                                    group by ([$$55 := $$49]) decor ([]) {
+                                              aggregate [$$41] <- [non-empty-stream()]
                                               -- AGGREGATE  |LOCAL|
+                                                select (and(eq($$49, $$48), not(is-missing($$54))))
                                                 -- STREAM_SELECT  |LOCAL|
+                                                  nested tuple source
                                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                            }
+                                           }
+                                    -- PRE_CLUSTERED_GROUP_BY[$$49]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        left outer join (eq($$49, $$48))
                                         -- HYBRID_HASH_JOIN [$$49][$$48]  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$49])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              select (eq($$c.getField("c_nationkey"), 5))
                                               -- STREAM_SELECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                                  data-scan []<-[$$49, $$c] <- test.Customers
+                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                          exchange
                                           -- HASH_PARTITION_EXCHANGE [$$48]  |PARTITIONED|
+                                            project ([$$48, $$54])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$54, $$48] <- [true, $$o.getField("o_custkey")]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$o])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (test.Orders)  |PARTITIONED|
+                                                    data-scan []<-[$$50, $$o] <- test.Orders
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                                        empty-tuple-source
+                                                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_let_3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_let_3.plan
index ec77d62..f500649 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_let_3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_let_3.plan
@@ -1,74 +1,139 @@
+distribute result [$$90]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$90])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$90] <- [{"cid": $$101, "pid": $$97, "ts": $$93}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$101(ASC) ]  |PARTITIONED|
+          order (ASC, $$101)
           -- STABLE_SORT [$$101(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$101, $$97, $$93])
               -- STREAM_PROJECT  |PARTITIONED|
+                select ($$84)
                 -- STREAM_SELECT  |PARTITIONED|
+                  project ([$$84, $$97, $$101, $$93])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- PRE_CLUSTERED_GROUP_BY[$$104]  |PARTITIONED|
-                              {
+                      group by ([$$106 := $$104]) decor ([$$97; $$101; $$93]) {
+                                aggregate [$$84] <- [non-empty-stream()]
                                 -- AGGREGATE  |LOCAL|
+                                  select (not(is-missing($$105)))
                                   -- STREAM_SELECT  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- PRE_CLUSTERED_GROUP_BY[$$104]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$104)
                           -- STABLE_SORT [$$104(ASC)]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$104]  |PARTITIONED|
+                              project ([$$101, $$97, $$93, $$105, $$104])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  left outer join (eq($$97, $$pid))
                                   -- HYBRID_HASH_JOIN [$$97][$$pid]  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$97]  |PARTITIONED|
+                                      select (ge($$93, 2000))
                                       -- STREAM_SELECT  |PARTITIONED|
+                                        running-aggregate [$$104] <- [create-query-uid()]
                                         -- RUNNING_AGGREGATE  |PARTITIONED|
+                                          project ([$$101, $$97, $$93])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$93, $$97] <- [$$i1.getField("ts"), $$i1.getField("pid")]
                                             -- ASSIGN  |PARTITIONED|
+                                              project ([$$101, $$i1])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                unnest $$i1 <- scan-collection($$98)
                                                 -- UNNEST  |PARTITIONED|
+                                                  project ([$$101, $$98])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    assign [$$101, $$98] <- [$$c1.getField("cid"), $$c1.getField("items")]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      project ([$$c1])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$c1] <- [$$c2]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            replicate
                                                             -- REPLICATE  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                project ([$$c2])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (test.cart)  |PARTITIONED|
+                                                                    data-scan []<-[$$95, $$c2] <- test.cart
+                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        empty-tuple-source
                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      assign [$$105] <- [true]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$pid])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          select (gt($$96, 1))
                                           -- STREAM_SELECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- SORT_GROUP_BY[$$108]  |PARTITIONED|
-                                                      {
+                                              group by ([$$pid := $$108]) decor ([]) {
+                                                        aggregate [$$96] <- [agg-sql-sum($$107)]
                                                         -- AGGREGATE  |LOCAL|
+                                                          nested tuple source
                                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                      }
+                                                     }
+                                              -- SORT_GROUP_BY[$$108]  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$108]  |PARTITIONED|
-                                                  -- SORT_GROUP_BY[$$92]  |PARTITIONED|
-                                                          {
+                                                  group by ([$$108 := $$92]) decor ([]) {
+                                                            aggregate [$$107] <- [agg-sql-count(1)]
                                                             -- AGGREGATE  |LOCAL|
+                                                              nested tuple source
                                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                          }
+                                                         }
+                                                  -- SORT_GROUP_BY[$$92]  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      project ([$$92])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        select (ge($$i2.getField("ts"), 2000))
                                                         -- STREAM_SELECT  |PARTITIONED|
+                                                          assign [$$92] <- [$$i2.getField("pid")]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            project ([$$i2])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              unnest $$i2 <- scan-collection($$99)
                                                               -- UNNEST  |PARTITIONED|
+                                                                project ([$$99])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  assign [$$99] <- [$$c2.getField("items")]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      replicate
                                                                       -- REPLICATE  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          project ([$$c2])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                              -- DATASOURCE_SCAN (test.cart)  |PARTITIONED|
+                                                                              data-scan []<-[$$95, $$c2] <- test.cart
+                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                                                                  empty-tuple-source
+                                                                                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_let_4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_let_4.plan
index ee9243d..a66a3c7 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_let_4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_let_4.plan
@@ -1,74 +1,139 @@
+distribute result [$$100]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$100])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$100] <- [{"cid": $$120, "pid": $$116, "ts": $$103}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$120(ASC) ]  |PARTITIONED|
+          order (ASC, $$120)
           -- STABLE_SORT [$$120(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$120, $$116, $$103])
               -- STREAM_PROJECT  |PARTITIONED|
+                select ($$94)
                 -- STREAM_SELECT  |PARTITIONED|
+                  project ([$$94, $$116, $$103, $$120])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- PRE_CLUSTERED_GROUP_BY[$$123]  |PARTITIONED|
-                              {
+                      group by ([$$125 := $$123]) decor ([$$116; $$103; $$120]) {
+                                aggregate [$$94] <- [non-empty-stream()]
                                 -- AGGREGATE  |LOCAL|
+                                  select (not(is-missing($$124)))
                                   -- STREAM_SELECT  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- PRE_CLUSTERED_GROUP_BY[$$123]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$123)
                           -- STABLE_SORT [$$123(ASC)]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$123]  |PARTITIONED|
+                              project ([$$120, $$116, $$103, $$124, $$123])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  left outer join (eq($$116, $$108))
                                   -- HYBRID_HASH_JOIN [$$116][$$108]  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$116]  |PARTITIONED|
+                                      select (ge($$103, 2000))
                                       -- STREAM_SELECT  |PARTITIONED|
+                                        running-aggregate [$$123] <- [create-query-uid()]
                                         -- RUNNING_AGGREGATE  |PARTITIONED|
+                                          project ([$$120, $$116, $$103])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$103, $$116] <- [$$i1.getField("ts"), $$i1.getField("pid")]
                                             -- ASSIGN  |PARTITIONED|
+                                              project ([$$120, $$i1])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                unnest $$i1 <- scan-collection($$117)
                                                 -- UNNEST  |PARTITIONED|
+                                                  project ([$$120, $$117])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    assign [$$120, $$117] <- [$$c1.getField("cid"), $$c1.getField("items")]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      project ([$$c1])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$c1] <- [$$113]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            replicate
                                                             -- REPLICATE  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                project ([$$113])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (test.cart)  |PARTITIONED|
+                                                                    data-scan []<-[$$114, $$113] <- test.cart
+                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        empty-tuple-source
                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      assign [$$124] <- [true]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$108])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          select (gt($$109, 1))
                                           -- STREAM_SELECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- SORT_GROUP_BY[$$127]  |PARTITIONED|
-                                                      {
+                                              group by ([$$108 := $$127]) decor ([]) {
+                                                        aggregate [$$109] <- [agg-sql-sum($$126)]
                                                         -- AGGREGATE  |LOCAL|
+                                                          nested tuple source
                                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                      }
+                                                     }
+                                              -- SORT_GROUP_BY[$$127]  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$127]  |PARTITIONED|
-                                                  -- SORT_GROUP_BY[$$110]  |PARTITIONED|
-                                                          {
+                                                  group by ([$$127 := $$110]) decor ([]) {
+                                                            aggregate [$$126] <- [agg-sql-count(1)]
                                                             -- AGGREGATE  |LOCAL|
+                                                              nested tuple source
                                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                          }
+                                                         }
+                                                  -- SORT_GROUP_BY[$$110]  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      project ([$$110])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        select (ge($$111.getField("ts"), 2000))
                                                         -- STREAM_SELECT  |PARTITIONED|
+                                                          assign [$$110] <- [$$111.getField("pid")]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            project ([$$111])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              unnest $$111 <- scan-collection($$118)
                                                               -- UNNEST  |PARTITIONED|
+                                                                project ([$$118])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  assign [$$118] <- [$$113.getField("items")]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      replicate
                                                                       -- REPLICATE  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          project ([$$113])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                              -- DATASOURCE_SCAN (test.cart)  |PARTITIONED|
+                                                                              data-scan []<-[$$114, $$113] <- test.cart
+                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  empty-tuple-source
                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_let_5.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_let_5.plan
index c670194..84f514c 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_let_5.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_let_5.plan
@@ -1,74 +1,139 @@
+distribute result [$$100]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$100])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$100] <- [{"cid": $$120, "pid": $$116, "ts": $$103}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$120(ASC) ]  |PARTITIONED|
+          order (ASC, $$120)
           -- STABLE_SORT [$$120(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$120, $$116, $$103])
               -- STREAM_PROJECT  |PARTITIONED|
+                select ($$94)
                 -- STREAM_SELECT  |PARTITIONED|
+                  project ([$$94, $$116, $$103, $$120])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- PRE_CLUSTERED_GROUP_BY[$$123]  |PARTITIONED|
-                              {
+                      group by ([$$125 := $$123]) decor ([$$116; $$103; $$120]) {
+                                aggregate [$$94] <- [non-empty-stream()]
                                 -- AGGREGATE  |LOCAL|
+                                  select (not(is-missing($$124)))
                                   -- STREAM_SELECT  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- PRE_CLUSTERED_GROUP_BY[$$123]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$123)
                           -- STABLE_SORT [$$123(ASC)]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$123]  |PARTITIONED|
+                              project ([$$120, $$116, $$103, $$124, $$123])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  left outer join (eq($$116, $$108))
                                   -- HYBRID_HASH_JOIN [$$116][$$108]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      select (ge($$103, 2000))
                                       -- STREAM_SELECT  |PARTITIONED|
+                                        running-aggregate [$$123] <- [create-query-uid()]
                                         -- RUNNING_AGGREGATE  |PARTITIONED|
+                                          project ([$$120, $$116, $$103])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$103, $$116] <- [$$i1.getField("ts"), $$i1.getField("pid")]
                                             -- ASSIGN  |PARTITIONED|
+                                              project ([$$120, $$i1])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                unnest $$i1 <- scan-collection($$117)
                                                 -- UNNEST  |PARTITIONED|
+                                                  project ([$$120, $$117])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    assign [$$120, $$117] <- [$$c1.getField("cid"), $$c1.getField("items")]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      project ([$$c1])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$c1] <- [$$113]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            replicate
                                                             -- REPLICATE  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                project ([$$113])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (test.cart)  |PARTITIONED|
+                                                                    data-scan []<-[$$114, $$113] <- test.cart
+                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        empty-tuple-source
                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                      assign [$$124] <- [true]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$108])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          select (gt($$109, 1))
                                           -- STREAM_SELECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- SORT_GROUP_BY[$$127]  |PARTITIONED|
-                                                      {
+                                              group by ([$$108 := $$127]) decor ([]) {
+                                                        aggregate [$$109] <- [agg-sql-sum($$126)]
                                                         -- AGGREGATE  |LOCAL|
+                                                          nested tuple source
                                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                      }
+                                                     }
+                                              -- SORT_GROUP_BY[$$127]  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$127]  |PARTITIONED|
-                                                  -- SORT_GROUP_BY[$$110]  |PARTITIONED|
-                                                          {
+                                                  group by ([$$127 := $$110]) decor ([]) {
+                                                            aggregate [$$126] <- [agg-sql-count(1)]
                                                             -- AGGREGATE  |LOCAL|
+                                                              nested tuple source
                                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                          }
+                                                         }
+                                                  -- SORT_GROUP_BY[$$110]  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      project ([$$110])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        select (ge($$111.getField("ts"), 2000))
                                                         -- STREAM_SELECT  |PARTITIONED|
+                                                          assign [$$110] <- [$$111.getField("pid")]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            project ([$$111])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              unnest $$111 <- scan-collection($$118)
                                                               -- UNNEST  |PARTITIONED|
+                                                                project ([$$118])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  assign [$$118] <- [$$113.getField("items")]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      replicate
                                                                       -- REPLICATE  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          project ([$$113])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                              -- DATASOURCE_SCAN (test.cart)  |PARTITIONED|
+                                                                              data-scan []<-[$$114, $$113] <- test.cart
+                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  empty-tuple-source
                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_let_6.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_let_6.plan
index 512a0e7..8302690 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_let_6.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_let_6.plan
@@ -1,70 +1,131 @@
+distribute result [$$100]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$100])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$100] <- [{"cid": $$111, "pid": $$110, "ts": $$103}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$111(ASC) ]  |PARTITIONED|
+          order (ASC, $$111)
           -- STABLE_SORT [$$111(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$111, $$110, $$103])
               -- STREAM_PROJECT  |PARTITIONED|
+                select ($$94)
                 -- STREAM_SELECT  |PARTITIONED|
+                  project ([$$111, $$103, $$110, $$94])
                   -- STREAM_PROJECT  |PARTITIONED|
-                    -- SUBPLAN  |PARTITIONED|
-                            {
+                    subplan {
+                              aggregate [$$94] <- [non-empty-stream()]
                               -- AGGREGATE  |LOCAL|
+                                select (eq($$110, $#3))
                                 -- STREAM_SELECT  |LOCAL|
+                                  unnest $#3 <- scan-collection($$89)
                                   -- UNNEST  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                            }
+                           }
+                    -- SUBPLAN  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        join (true)
                         -- NESTED_LOOP  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            select (ge($$103, 2000))
                             -- STREAM_SELECT  |PARTITIONED|
+                              project ([$$111, $$103, $$110])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$103, $$110] <- [$$i1.getField("ts"), $$i1.getField("pid")]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$111, $$i1])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    unnest $$i1 <- scan-collection($$107)
                                     -- UNNEST  |PARTITIONED|
+                                      project ([$$111, $$107])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$111, $$107] <- [$$c1.getField("cid"), $$c1.getField("items")]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$c1])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$c1] <- [$$c2]
                                             -- ASSIGN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                replicate
                                                 -- REPLICATE  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$$c2])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.cart)  |PARTITIONED|
+                                                        data-scan []<-[$$105, $$c2] <- test.cart
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                            aggregate [$$89] <- [listify($$pid)]
                             -- AGGREGATE  |UNPARTITIONED|
+                              exchange
                               -- SORT_MERGE_EXCHANGE [$$pid(ASC) ]  |PARTITIONED|
+                                project ([$$pid])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  select (gt($$106, 1))
                                   -- STREAM_SELECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- SORT_GROUP_BY[$$117]  |PARTITIONED|
-                                              {
+                                      group by ([$$pid := $$117]) decor ([]) {
+                                                aggregate [$$106] <- [agg-sql-sum($$116)]
                                                 -- AGGREGATE  |LOCAL|
+                                                  nested tuple source
                                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                              }
+                                             }
+                                      -- SORT_GROUP_BY[$$117]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$117]  |PARTITIONED|
-                                          -- SORT_GROUP_BY[$$102]  |PARTITIONED|
-                                                  {
+                                          group by ([$$117 := $$102]) decor ([]) {
+                                                    aggregate [$$116] <- [agg-sql-count(1)]
                                                     -- AGGREGATE  |LOCAL|
+                                                      nested tuple source
                                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                  }
+                                                 }
+                                          -- SORT_GROUP_BY[$$102]  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$102])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                select (ge($$i2.getField("ts"), 2000))
                                                 -- STREAM_SELECT  |PARTITIONED|
+                                                  assign [$$102] <- [$$i2.getField("pid")]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$i2])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      unnest $$i2 <- scan-collection($$108)
                                                       -- UNNEST  |PARTITIONED|
+                                                        project ([$$108])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$108] <- [$$c2.getField("items")]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              replicate
                                                               -- REPLICATE  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  project ([$$c2])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- DATASOURCE_SCAN (test.cart)  |PARTITIONED|
+                                                                      data-scan []<-[$$105, $$c2] <- test.cart
+                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          empty-tuple-source
                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_let_7.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_let_7.plan
index 512a0e7..8302690 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_let_7.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_let_7.plan
@@ -1,70 +1,131 @@
+distribute result [$$100]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$100])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$100] <- [{"cid": $$111, "pid": $$110, "ts": $$103}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$111(ASC) ]  |PARTITIONED|
+          order (ASC, $$111)
           -- STABLE_SORT [$$111(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$111, $$110, $$103])
               -- STREAM_PROJECT  |PARTITIONED|
+                select ($$94)
                 -- STREAM_SELECT  |PARTITIONED|
+                  project ([$$111, $$103, $$110, $$94])
                   -- STREAM_PROJECT  |PARTITIONED|
-                    -- SUBPLAN  |PARTITIONED|
-                            {
+                    subplan {
+                              aggregate [$$94] <- [non-empty-stream()]
                               -- AGGREGATE  |LOCAL|
+                                select (eq($$110, $#3))
                                 -- STREAM_SELECT  |LOCAL|
+                                  unnest $#3 <- scan-collection($$89)
                                   -- UNNEST  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                            }
+                           }
+                    -- SUBPLAN  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        join (true)
                         -- NESTED_LOOP  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            select (ge($$103, 2000))
                             -- STREAM_SELECT  |PARTITIONED|
+                              project ([$$111, $$103, $$110])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$103, $$110] <- [$$i1.getField("ts"), $$i1.getField("pid")]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$111, $$i1])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    unnest $$i1 <- scan-collection($$107)
                                     -- UNNEST  |PARTITIONED|
+                                      project ([$$111, $$107])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$111, $$107] <- [$$c1.getField("cid"), $$c1.getField("items")]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$c1])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$c1] <- [$$c2]
                                             -- ASSIGN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                replicate
                                                 -- REPLICATE  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$$c2])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.cart)  |PARTITIONED|
+                                                        data-scan []<-[$$105, $$c2] <- test.cart
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                            aggregate [$$89] <- [listify($$pid)]
                             -- AGGREGATE  |UNPARTITIONED|
+                              exchange
                               -- SORT_MERGE_EXCHANGE [$$pid(ASC) ]  |PARTITIONED|
+                                project ([$$pid])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  select (gt($$106, 1))
                                   -- STREAM_SELECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- SORT_GROUP_BY[$$117]  |PARTITIONED|
-                                              {
+                                      group by ([$$pid := $$117]) decor ([]) {
+                                                aggregate [$$106] <- [agg-sql-sum($$116)]
                                                 -- AGGREGATE  |LOCAL|
+                                                  nested tuple source
                                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                              }
+                                             }
+                                      -- SORT_GROUP_BY[$$117]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$117]  |PARTITIONED|
-                                          -- SORT_GROUP_BY[$$102]  |PARTITIONED|
-                                                  {
+                                          group by ([$$117 := $$102]) decor ([]) {
+                                                    aggregate [$$116] <- [agg-sql-count(1)]
                                                     -- AGGREGATE  |LOCAL|
+                                                      nested tuple source
                                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                  }
+                                                 }
+                                          -- SORT_GROUP_BY[$$102]  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$102])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                select (ge($$i2.getField("ts"), 2000))
                                                 -- STREAM_SELECT  |PARTITIONED|
+                                                  assign [$$102] <- [$$i2.getField("pid")]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$i2])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      unnest $$i2 <- scan-collection($$108)
                                                       -- UNNEST  |PARTITIONED|
+                                                        project ([$$108])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$108] <- [$$c2.getField("items")]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              replicate
                                                               -- REPLICATE  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  project ([$$c2])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- DATASOURCE_SCAN (test.cart)  |PARTITIONED|
+                                                                      data-scan []<-[$$105, $$c2] <- test.cart
+                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          empty-tuple-source
                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_let_8.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_let_8.plan
index 878c508..1438ae5 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_let_8.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_let_8.plan
@@ -1,72 +1,135 @@
+distribute result [$$90]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$90])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$90] <- [{"cid": $$101, "pid": $$108, "ts": $$109}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$101(ASC) ]  |PARTITIONED|
+          order (ASC, $$101)
           -- STABLE_SORT [$$101(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$101, $$108, $$109])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (and(ge($$109, 2000), $$84))
                 -- STREAM_SELECT  |PARTITIONED|
+                  project ([$$84, $$108, $$109, $$101])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- PRE_CLUSTERED_GROUP_BY[$$94, $$i1, $$97, $$93, $$104]  |PARTITIONED|
-                              {
+                      group by ([$$106 := $$94; $$107 := $$i1; $$108 := $$97; $$109 := $$93; $$110 := $$104]) decor ([$$101]) {
+                                aggregate [$$84] <- [non-empty-stream()]
                                 -- AGGREGATE  |LOCAL|
+                                  select (not(is-missing($$105)))
                                   -- STREAM_SELECT  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- PRE_CLUSTERED_GROUP_BY[$$94, $$i1, $$97, $$93, $$104]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$94) (ASC, $$i1) (ASC, $$97) (ASC, $$93) (ASC, $$104)
                           -- STABLE_SORT [$$94(ASC), $$i1(ASC), $$97(ASC), $$93(ASC), $$104(ASC)]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$101, $$105, $$94, $$i1, $$97, $$93, $$104])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  left outer join (eq($$97, $$pid))
                                   -- HYBRID_HASH_JOIN [$$97][$$pid]  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$97]  |PARTITIONED|
+                                      window-aggregate [$$104] <- [row-number-impl()] partition [$$94, $$i1, $$97, $$93]
                                       -- WINDOW_STREAM  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          order (ASC, $$94) (ASC, $$i1) (ASC, $$97) (ASC, $$93)
                                           -- STABLE_SORT [$$94(ASC), $$i1(ASC), $$97(ASC), $$93(ASC)]  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$93, $$97] <- [$$i1.getField("ts"), $$i1.getField("pid")]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$94, $$101, $$i1])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  unnest $$i1 <- scan-collection($$98)
                                                   -- UNNEST  |PARTITIONED|
+                                                    project ([$$94, $$101, $$98])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      assign [$$101, $$98] <- [$$c1.getField("cid"), $$c1.getField("items")]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        project ([$$94, $$c1])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$94, $$c1] <- [$$95, $$c2]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              replicate
                                                               -- REPLICATE  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- DATASOURCE_SCAN (test.cart)  |PARTITIONED|
+                                                                  data-scan []<-[$$95, $$c2] <- test.cart
+                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      empty-tuple-source
                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      assign [$$105] <- [true]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$pid])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          select (gt($$96, 1))
                                           -- STREAM_SELECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- SORT_GROUP_BY[$$112]  |PARTITIONED|
-                                                      {
+                                              group by ([$$pid := $$112]) decor ([]) {
+                                                        aggregate [$$96] <- [agg-sql-sum($$111)]
                                                         -- AGGREGATE  |LOCAL|
+                                                          nested tuple source
                                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                      }
+                                                     }
+                                              -- SORT_GROUP_BY[$$112]  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$112]  |PARTITIONED|
-                                                  -- SORT_GROUP_BY[$$92]  |PARTITIONED|
-                                                          {
+                                                  group by ([$$112 := $$92]) decor ([]) {
+                                                            aggregate [$$111] <- [agg-sql-count(1)]
                                                             -- AGGREGATE  |LOCAL|
+                                                              nested tuple source
                                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                          }
+                                                         }
+                                                  -- SORT_GROUP_BY[$$92]  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      project ([$$92])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        select (ge($$i2.getField("ts"), 2000))
                                                         -- STREAM_SELECT  |PARTITIONED|
+                                                          assign [$$92] <- [$$i2.getField("pid")]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            project ([$$i2])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              unnest $$i2 <- scan-collection($$99)
                                                               -- UNNEST  |PARTITIONED|
+                                                                project ([$$99])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  assign [$$99] <- [$$c2.getField("items")]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    project ([$$c2])
                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        replicate
                                                                         -- REPLICATE  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                            -- DATASOURCE_SCAN (test.cart)  |PARTITIONED|
+                                                                            data-scan []<-[$$95, $$c2] <- test.cart
+                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                                                                empty-tuple-source
+                                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_ps.plan
index b92fa1f..636b3f7 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/in_ps.plan
@@ -1,74 +1,142 @@
+distribute result [$$44]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$44])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$44] <- [{"customer_name": $$50}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$50)
           -- STABLE_SORT [$$50(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$50(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$53
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$50])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select ($$38)
                         -- STREAM_SELECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- PRE_CLUSTERED_GROUP_BY[$$45]  |PARTITIONED|
-                                    {
+                            group by ([$$50 := $$45]) decor ([]) {
+                                      aggregate [$$38] <- [non-empty-stream()]
                                       -- AGGREGATE  |LOCAL|
+                                        select (not(is-missing($$49)))
                                         -- STREAM_SELECT  |LOCAL|
+                                          nested tuple source
                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                    }
+                                   }
+                            -- PRE_CLUSTERED_GROUP_BY[$$45]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$49, $$45])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    left outer join (eq($$45, $$34))
                                     -- HYBRID_HASH_JOIN [$$45][$$34]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$45])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          select (eq($$c.getField("c_nationkey"), 5))
                                           -- STREAM_SELECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                              data-scan []<-[$$45, $$c] <- test.Customers
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$34]  |PARTITIONED|
+                                        project ([$$49, $$34])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$49, $$34] <- [true, $$o.getField("o_custkey")]
                                           -- ASSIGN  |PARTITIONED|
+                                            project ([$$o])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- DATASOURCE_SCAN (test.Orders)  |PARTITIONED|
+                                                data-scan []<-[$$46, $$o] <- test.Orders
+                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$53] <- [agg-range-map($$51, $$52)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$51, $$52] <- [agg-local-sampling($$50), agg-null-writer($$50)]
                       -- AGGREGATE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$50])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                select ($$38)
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- PRE_CLUSTERED_GROUP_BY[$$45]  |PARTITIONED|
-                                            {
+                                    group by ([$$50 := $$45]) decor ([]) {
+                                              aggregate [$$38] <- [non-empty-stream()]
                                               -- AGGREGATE  |LOCAL|
+                                                select (not(is-missing($$49)))
                                                 -- STREAM_SELECT  |LOCAL|
+                                                  nested tuple source
                                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                            }
+                                           }
+                                    -- PRE_CLUSTERED_GROUP_BY[$$45]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$49, $$45])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            left outer join (eq($$45, $$34))
                                             -- HYBRID_HASH_JOIN [$$45][$$34]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$45])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  select (eq($$c.getField("c_nationkey"), 5))
                                                   -- STREAM_SELECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.Customers)  |PARTITIONED|
+                                                      data-scan []<-[$$45, $$c] <- test.Customers
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                              exchange
                                               -- HASH_PARTITION_EXCHANGE [$$34]  |PARTITIONED|
+                                                project ([$$49, $$34])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$49, $$34] <- [true, $$o.getField("o_custkey")]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$o])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.Orders)  |PARTITIONED|
+                                                        data-scan []<-[$$46, $$o] <- test.Orders
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/not_exists.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/not_exists.plan
index 5501c67..0e105a8 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/not_exists.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/not_exists.plan
@@ -1,74 +1,136 @@
+distribute result [$$162]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$162])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$162] <- [{"cntrycode": $$cntrycode, "numcust": $$165, "totacctbal": $$166}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$cntrycode(ASC) ]  |PARTITIONED|
-          -- SORT_GROUP_BY[$$188]  |PARTITIONED|
-                  {
+          group by ([$$cntrycode := $$188]) decor ([]) {
+                    aggregate [$$165, $$166] <- [agg-sql-sum($$186), agg-global-sql-sum($$187)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- SORT_GROUP_BY[$$188]  |PARTITIONED|
+            exchange
             -- HASH_PARTITION_EXCHANGE [$$188]  |PARTITIONED|
-              -- SORT_GROUP_BY[$$163]  |PARTITIONED|
-                      {
+              group by ([$$188 := $$163]) decor ([]) {
+                        aggregate [$$186, $$187] <- [agg-sql-count($$122), agg-local-sql-sum($$174)]
                         -- AGGREGATE  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SORT_GROUP_BY[$$163]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$122, $$174, $$163])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$163] <- [substring($$176, 0, 2)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$176, $$122, $$174])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (not(neq($$164, 0)))
                         -- STREAM_SELECT  |PARTITIONED|
+                          project ([$$164, $$176, $$122, $$174])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- SORT_GROUP_BY[$$185]  |PARTITIONED|
-                                      {
+                              group by ([$$181 := $$185]) decor ([$$176; $$122; $$174]) {
+                                        aggregate [$$164] <- [agg-sum($$184)]
                                         -- AGGREGATE  |LOCAL|
+                                          nested tuple source
                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                      }
+                                     }
+                              -- SORT_GROUP_BY[$$185]  |PARTITIONED|
+                                exchange
                                 -- HASH_PARTITION_EXCHANGE [$$185]  |PARTITIONED|
-                                  -- PRE_CLUSTERED_GROUP_BY[$$179]  |PARTITIONED|
-                                          {
+                                  group by ([$$185 := $$179]) decor ([$$176; $$122; $$174]) {
+                                            aggregate [$$184] <- [agg-count({"o": $$o})]
                                             -- AGGREGATE  |LOCAL|
+                                              select (not(is-missing($$180)))
                                               -- STREAM_SELECT  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                         }
+                                  -- PRE_CLUSTERED_GROUP_BY[$$179]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$179)
                                       -- STABLE_SORT [$$179(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$122, $$174, $$176, $$o, $$180, $$179])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              left outer join (eq($$172, $$175))
                                               -- HYBRID_HASH_JOIN [$$175][$$172]  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$175]  |PARTITIONED|
+                                                  running-aggregate [$$179] <- [create-query-uid()]
                                                   -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                    project ([$$122, $$174, $$176, $$175])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        join (gt($$174, $$171))
                                                         -- NESTED_LOOP  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            assign [$$122] <- [{"c_acctbal": $$174, "c_custkey": $$175, "cntrycode": substring($$176, 0, 2)}]
                                                             -- ASSIGN  |PARTITIONED|
+                                                              project ([$$176, $$175, $$174])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$176, $$175, $$174] <- [$$Customer.getField(4), $$Customer.getField(0), $$Customer.getField(5)]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (test.Customer)  |PARTITIONED|
+                                                                    data-scan []<-[$$Customer] <- test.Customer
+                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        empty-tuple-source
                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                          exchange
                                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                            project ([$$171])
                                                             -- STREAM_PROJECT  |UNPARTITIONED|
+                                                              assign [$$171] <- [get-item($$136, 0)]
                                                               -- ASSIGN  |UNPARTITIONED|
+                                                                aggregate [$$136] <- [listify($$183)]
                                                                 -- AGGREGATE  |UNPARTITIONED|
+                                                                  aggregate [$$183] <- [agg-global-sql-avg($$189)]
                                                                   -- AGGREGATE  |UNPARTITIONED|
+                                                                    exchange
                                                                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                                                                      aggregate [$$189] <- [agg-local-sql-avg($$177)]
                                                                       -- AGGREGATE  |PARTITIONED|
+                                                                        select (gt($$177, 0.0))
                                                                         -- STREAM_SELECT  |PARTITIONED|
+                                                                          project ([$$177])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            assign [$$177] <- [$$169.getField(5)]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                -- DATASOURCE_SCAN (test.Customer)  |PARTITIONED|
+                                                                                data-scan []<-[$$169] <- test.Customer
+                                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    empty-tuple-source
                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$172]  |PARTITIONED|
+                                                  assign [$$180, $$172] <- [true, $$o.getField(1)]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.Orders)  |PARTITIONED|
+                                                      data-scan []<-[$$o] <- test.Orders
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/not_exists_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/not_exists_ps.plan
index c8944e7..423e68f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/not_exists_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/not_exists_ps.plan
@@ -1,157 +1,290 @@
+distribute result [$$162]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$162])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$162] <- [{"cntrycode": $$cntrycode, "numcust": $$165, "totacctbal": $$166}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$cntrycode)
           -- STABLE_SORT [$$cntrycode(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$cntrycode(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$193
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- SORT_GROUP_BY[$$188]  |PARTITIONED|
-                              {
+                      group by ([$$cntrycode := $$188]) decor ([]) {
+                                aggregate [$$165, $$166] <- [agg-sql-sum($$186), agg-global-sql-sum($$187)]
                                 -- AGGREGATE  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- SORT_GROUP_BY[$$188]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$188]  |PARTITIONED|
-                          -- SORT_GROUP_BY[$$163]  |PARTITIONED|
-                                  {
+                          group by ([$$188 := $$163]) decor ([]) {
+                                    aggregate [$$186, $$187] <- [agg-sql-count($$122), agg-local-sql-sum($$174)]
                                     -- AGGREGATE  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                  }
+                                 }
+                          -- SORT_GROUP_BY[$$163]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$122, $$174, $$163])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$163] <- [substring($$176, 0, 2)]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$176, $$122, $$174])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    select (not(neq($$164, 0)))
                                     -- STREAM_SELECT  |PARTITIONED|
+                                      project ([$$164, $$176, $$122, $$174])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- SORT_GROUP_BY[$$185]  |PARTITIONED|
-                                                  {
+                                          group by ([$$181 := $$185]) decor ([$$176; $$122; $$174]) {
+                                                    aggregate [$$164] <- [agg-sum($$184)]
                                                     -- AGGREGATE  |LOCAL|
+                                                      nested tuple source
                                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                  }
+                                                 }
+                                          -- SORT_GROUP_BY[$$185]  |PARTITIONED|
+                                            exchange
                                             -- HASH_PARTITION_EXCHANGE [$$185]  |PARTITIONED|
-                                              -- PRE_CLUSTERED_GROUP_BY[$$179]  |PARTITIONED|
-                                                      {
+                                              group by ([$$185 := $$179]) decor ([$$176; $$122; $$174]) {
+                                                        aggregate [$$184] <- [agg-count({"o": $$o})]
                                                         -- AGGREGATE  |LOCAL|
+                                                          select (not(is-missing($$180)))
                                                           -- STREAM_SELECT  |LOCAL|
+                                                            nested tuple source
                                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                      }
+                                                     }
+                                              -- PRE_CLUSTERED_GROUP_BY[$$179]  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  order (ASC, $$179)
                                                   -- STABLE_SORT [$$179(ASC)]  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      project ([$$122, $$174, $$176, $$o, $$180, $$179])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          left outer join (eq($$172, $$175))
                                                           -- HYBRID_HASH_JOIN [$$175][$$172]  |PARTITIONED|
+                                                            exchange
                                                             -- HASH_PARTITION_EXCHANGE [$$175]  |PARTITIONED|
+                                                              running-aggregate [$$179] <- [create-query-uid()]
                                                               -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                                project ([$$122, $$174, $$176, $$175])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    join (gt($$174, $$171))
                                                                     -- NESTED_LOOP  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        assign [$$122] <- [{"c_acctbal": $$174, "c_custkey": $$175, "cntrycode": substring($$176, 0, 2)}]
                                                                         -- ASSIGN  |PARTITIONED|
+                                                                          project ([$$176, $$175, $$174])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            assign [$$176, $$175, $$174] <- [$$Customer.getField(4), $$Customer.getField(0), $$Customer.getField(5)]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                -- DATASOURCE_SCAN (test.Customer)  |PARTITIONED|
+                                                                                data-scan []<-[$$Customer] <- test.Customer
+                                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    empty-tuple-source
                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                      exchange
                                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                        project ([$$171])
                                                                         -- STREAM_PROJECT  |UNPARTITIONED|
+                                                                          assign [$$171] <- [get-item($$136, 0)]
                                                                           -- ASSIGN  |UNPARTITIONED|
+                                                                            aggregate [$$136] <- [listify($$183)]
                                                                             -- AGGREGATE  |UNPARTITIONED|
+                                                                              aggregate [$$183] <- [agg-global-sql-avg($$189)]
                                                                               -- AGGREGATE  |UNPARTITIONED|
+                                                                                exchange
                                                                                 -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                                                                                  aggregate [$$189] <- [agg-local-sql-avg($$177)]
                                                                                   -- AGGREGATE  |PARTITIONED|
+                                                                                    select (gt($$177, 0.0))
                                                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                                                      project ([$$177])
                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                        assign [$$177] <- [$$169.getField(5)]
                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                            -- DATASOURCE_SCAN (test.Customer)  |PARTITIONED|
+                                                                                            data-scan []<-[$$169] <- test.Customer
+                                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                              exchange
                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                empty-tuple-source
                                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                            exchange
                                                             -- HASH_PARTITION_EXCHANGE [$$172]  |PARTITIONED|
+                                                              assign [$$180, $$172] <- [true, $$o.getField(1)]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- DATASOURCE_SCAN (test.Orders)  |PARTITIONED|
+                                                                  data-scan []<-[$$o] <- test.Orders
+                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      empty-tuple-source
                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$193] <- [agg-range-map($$191, $$192)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$191, $$192] <- [agg-local-sampling($$cntrycode), agg-null-writer($$cntrycode)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$cntrycode])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- SORT_GROUP_BY[$$188]  |PARTITIONED|
-                                        {
+                                group by ([$$cntrycode := $$188]) decor ([]) {
+                                          aggregate [$$165, $$166] <- [agg-sql-sum($$186), agg-global-sql-sum($$187)]
                                           -- AGGREGATE  |LOCAL|
+                                            nested tuple source
                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- SORT_GROUP_BY[$$188]  |PARTITIONED|
+                                  exchange
                                   -- HASH_PARTITION_EXCHANGE [$$188]  |PARTITIONED|
-                                    -- SORT_GROUP_BY[$$163]  |PARTITIONED|
-                                            {
+                                    group by ([$$188 := $$163]) decor ([]) {
+                                              aggregate [$$186, $$187] <- [agg-sql-count($$122), agg-local-sql-sum($$174)]
                                               -- AGGREGATE  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                            }
+                                           }
+                                    -- SORT_GROUP_BY[$$163]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$122, $$174, $$163])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$163] <- [substring($$176, 0, 2)]
                                           -- ASSIGN  |PARTITIONED|
+                                            project ([$$176, $$122, $$174])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              select (not(neq($$164, 0)))
                                               -- STREAM_SELECT  |PARTITIONED|
+                                                project ([$$164, $$176, $$122, $$174])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- SORT_GROUP_BY[$$185]  |PARTITIONED|
-                                                            {
+                                                    group by ([$$181 := $$185]) decor ([$$176; $$122; $$174]) {
+                                                              aggregate [$$164] <- [agg-sum($$184)]
                                                               -- AGGREGATE  |LOCAL|
+                                                                nested tuple source
                                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                            }
+                                                           }
+                                                    -- SORT_GROUP_BY[$$185]  |PARTITIONED|
+                                                      exchange
                                                       -- HASH_PARTITION_EXCHANGE [$$185]  |PARTITIONED|
-                                                        -- PRE_CLUSTERED_GROUP_BY[$$179]  |PARTITIONED|
-                                                                {
+                                                        group by ([$$185 := $$179]) decor ([$$176; $$122; $$174]) {
+                                                                  aggregate [$$184] <- [agg-count({"o": $$o})]
                                                                   -- AGGREGATE  |LOCAL|
+                                                                    select (not(is-missing($$180)))
                                                                     -- STREAM_SELECT  |LOCAL|
+                                                                      nested tuple source
                                                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                }
+                                                               }
+                                                        -- PRE_CLUSTERED_GROUP_BY[$$179]  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            order (ASC, $$179)
                                                             -- STABLE_SORT [$$179(ASC)]  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                project ([$$122, $$174, $$176, $$o, $$180, $$179])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    left outer join (eq($$172, $$175))
                                                                     -- HYBRID_HASH_JOIN [$$175][$$172]  |PARTITIONED|
+                                                                      exchange
                                                                       -- HASH_PARTITION_EXCHANGE [$$175]  |PARTITIONED|
+                                                                        running-aggregate [$$179] <- [create-query-uid()]
                                                                         -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                                          project ([$$122, $$174, $$176, $$175])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              join (gt($$174, $$171))
                                                                               -- NESTED_LOOP  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  assign [$$122] <- [{"c_acctbal": $$174, "c_custkey": $$175, "cntrycode": substring($$176, 0, 2)}]
                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                    project ([$$176, $$175, $$174])
                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                      assign [$$176, $$175, $$174] <- [$$Customer.getField(4), $$Customer.getField(0), $$Customer.getField(5)]
                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                        exchange
                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                          -- DATASOURCE_SCAN (test.Customer)  |PARTITIONED|
+                                                                                          data-scan []<-[$$Customer] <- test.Customer
+                                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                            exchange
                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                              empty-tuple-source
                                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                exchange
                                                                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                  project ([$$171])
                                                                                   -- STREAM_PROJECT  |UNPARTITIONED|
+                                                                                    assign [$$171] <- [get-item($$136, 0)]
                                                                                     -- ASSIGN  |UNPARTITIONED|
+                                                                                      aggregate [$$136] <- [listify($$183)]
                                                                                       -- AGGREGATE  |UNPARTITIONED|
+                                                                                        aggregate [$$183] <- [agg-global-sql-avg($$189)]
                                                                                         -- AGGREGATE  |UNPARTITIONED|
+                                                                                          exchange
                                                                                           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                                                                                            aggregate [$$189] <- [agg-local-sql-avg($$177)]
                                                                                             -- AGGREGATE  |PARTITIONED|
+                                                                                              select (gt($$177, 0.0))
                                                                                               -- STREAM_SELECT  |PARTITIONED|
+                                                                                                project ([$$177])
                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                  assign [$$177] <- [$$169.getField(5)]
                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                    exchange
                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                      -- DATASOURCE_SCAN (test.Customer)  |PARTITIONED|
+                                                                                                      data-scan []<-[$$169] <- test.Customer
+                                                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                        exchange
                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                          empty-tuple-source
                                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                      exchange
                                                                       -- HASH_PARTITION_EXCHANGE [$$172]  |PARTITIONED|
+                                                                        assign [$$180, $$172] <- [true, $$o.getField(1)]
                                                                         -- ASSIGN  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                            -- DATASOURCE_SCAN (test.Orders)  |PARTITIONED|
+                                                                            data-scan []<-[$$o] <- test.Orders
+                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                empty-tuple-source
                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/query-ASTERIXDB-1572-2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/query-ASTERIXDB-1572-2.plan
index 7dfcb75..a9f7005 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/query-ASTERIXDB-1572-2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/query-ASTERIXDB-1572-2.plan
@@ -1,12 +1,24 @@
+distribute result [$$50]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$50])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$50] <- [{"st1": {"id": $$51}}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$51])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (or(and(eq($$51, 0), $$53), and($$53, eq($$51, 2))))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$53] <- [eq($$51, 1)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$51])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (sampdb.samptable)  |PARTITIONED|
+                  data-scan []<-[$$51, $$samptable] <- sampdb.samptable
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/query-ASTERIXDB-1572.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/query-ASTERIXDB-1572.plan
index bbafbac..645bba7 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/query-ASTERIXDB-1572.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/query-ASTERIXDB-1572.plan
@@ -1,29 +1,49 @@
+distribute result [$$54]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$54])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$54] <- [{"st1": {"id": $$55}}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$55])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (or(and($$33, $$37), and($$42, $$46)))
           -- STREAM_SELECT  |PARTITIONED|
-            -- SUBPLAN  |PARTITIONED|
-                    {
+            subplan {
+                      aggregate [$$46] <- [non-empty-stream()]
                       -- AGGREGATE  |LOCAL|
+                        select (eq($$55, 2))
                         -- STREAM_SELECT  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                    }
-              -- SUBPLAN  |PARTITIONED|
-                      {
+                   }
+            -- SUBPLAN  |PARTITIONED|
+              subplan {
+                        aggregate [$$37, $$42] <- [non-empty-stream(), non-empty-stream()]
                         -- AGGREGATE  |LOCAL|
+                          select (eq($$55, 1))
                           -- STREAM_SELECT  |LOCAL|
+                            nested tuple source
                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
-                -- SUBPLAN  |PARTITIONED|
-                        {
+                     }
+              -- SUBPLAN  |PARTITIONED|
+                subplan {
+                          aggregate [$$33] <- [non-empty-stream()]
                           -- AGGREGATE  |LOCAL|
+                            select (eq($$55, 0))
                             -- STREAM_SELECT  |LOCAL|
+                              nested tuple source
                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                        }
+                       }
+                -- SUBPLAN  |PARTITIONED|
+                  project ([$$55])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (sampdb.samptable)  |PARTITIONED|
+                      data-scan []<-[$$55, $$samptable] <- sampdb.samptable
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/query-ASTERIXDB-2815-2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/query-ASTERIXDB-2815-2.plan
index 897163e..c83fd58 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/query-ASTERIXDB-2815-2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/query-ASTERIXDB-2815-2.plan
@@ -1,72 +1,141 @@
+distribute result [$$76]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$76])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$76] <- [{"id": $$82, "ranks": array-sort($$72)}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$82(ASC) ]  |PARTITIONED|
+          order (ASC, $$82)
           -- STABLE_SORT [$$82(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$82, $$72])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- PRE_CLUSTERED_GROUP_BY[$$78]  |PARTITIONED|
-                          {
+                  group by ([$$91 := $$78]) decor ([$$82]) {
+                            aggregate [$$72] <- [listify($$69)]
                             -- AGGREGATE  |LOCAL|
+                              select (not(is-missing($$90)))
                               -- STREAM_SELECT  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                         }
+                  -- PRE_CLUSTERED_GROUP_BY[$$78]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$82, $$69, $$90, $$78])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          left outer join (eq($$78, $$89))
                           -- HYBRID_HASH_JOIN [$$78][$$89]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$78, $$82])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$78, $$82] <- [$$89, $$87]
                                 -- ASSIGN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    replicate
                                     -- REPLICATE  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$89, $$87])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$87] <- [$$88.getField("id")]
                                           -- ASSIGN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.RawTweet)  |PARTITIONED|
+                                              data-scan []<-[$$89, $$88] <- test.RawTweet
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              assign [$$90] <- [true]
                               -- ASSIGN  |PARTITIONED|
+                                project ([$$89, $$69])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  window-aggregate [$$69] <- [rank-impl($$e.url)] partition [$$89] order (ASC, $$e.url)
                                   -- WINDOW_STREAM  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$89) (ASC, $$e.url)
                                       -- STABLE_SORT [$$89(ASC), $$e.url(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$89]  |PARTITIONED|
+                                          project ([$$89, $$e.url])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              join (eq($$ve, $$81))
                                               -- HYBRID_HASH_JOIN [$$ve][$$81]  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$ve]  |PARTITIONED|
+                                                  project ([$$89, $$ve])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    unnest $$ve <- scan-collection($$84)
                                                     -- UNNEST  |PARTITIONED|
+                                                      project ([$$89, $$84])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          join (eq($$87, $$83))
                                                           -- HYBRID_HASH_JOIN [$$87][$$83]  |PARTITIONED|
+                                                            exchange
                                                             -- HASH_PARTITION_EXCHANGE [$$87]  |PARTITIONED|
+                                                              replicate
                                                               -- REPLICATE  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  project ([$$89, $$87])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    assign [$$87] <- [$$88.getField("id")]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                        -- DATASOURCE_SCAN (test.RawTweet)  |PARTITIONED|
+                                                                        data-scan []<-[$$89, $$88] <- test.RawTweet
+                                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            empty-tuple-source
                                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                            exchange
                                                             -- HASH_PARTITION_EXCHANGE [$$83]  |PARTITIONED|
+                                                              project ([$$84, $$83])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$84, $$83] <- [$$v.getField("evidence"), $$v.getField("tweet_id")]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  project ([$$v])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- DATASOURCE_SCAN (test.Verification)  |PARTITIONED|
+                                                                      data-scan []<-[$$79, $$v] <- test.Verification
+                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          empty-tuple-source
                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$81]  |PARTITIONED|
+                                                  project ([$$e.url, $$81])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    assign [$$e.url, $$81] <- [$$e.getField("url"), $$e.getField("ev_id")]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      project ([$$e])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- DATASOURCE_SCAN (test.Evidence)  |PARTITIONED|
+                                                          data-scan []<-[$$80, $$e] <- test.Evidence
+                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              empty-tuple-source
                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/query-ASTERIXDB-2815-3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/query-ASTERIXDB-2815-3.plan
index 6ca6f1c..4d7954c 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/query-ASTERIXDB-2815-3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/query-ASTERIXDB-2815-3.plan
@@ -1,73 +1,143 @@
+distribute result [$$81]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$81])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$81] <- [{"id": $$88, "ranks": array-sort($$77)}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$88(ASC) ]  |PARTITIONED|
+          order (ASC, $$88)
           -- STABLE_SORT [$$88(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$88, $$77])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- PRE_CLUSTERED_GROUP_BY[$$84]  |PARTITIONED|
-                          {
+                  group by ([$$97 := $$84]) decor ([$$88]) {
+                            aggregate [$$77] <- [listify($$74)]
                             -- AGGREGATE  |LOCAL|
+                              select (not(is-missing($$96)))
                               -- STREAM_SELECT  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                         }
+                  -- PRE_CLUSTERED_GROUP_BY[$$84]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$88, $$74, $$96, $$84])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          left outer join (eq($$84, $$95))
                           -- HYBRID_HASH_JOIN [$$84][$$95]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$84, $$88])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$84, $$88] <- [$$95, $$93]
                                 -- ASSIGN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    replicate
                                     -- REPLICATE  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$95, $$93])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$93] <- [$$94.getField("id")]
                                           -- ASSIGN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.RawTweet)  |PARTITIONED|
+                                              data-scan []<-[$$95, $$94] <- test.RawTweet
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$95]  |PARTITIONED|
+                              assign [$$96] <- [true]
                               -- ASSIGN  |PARTITIONED|
+                                project ([$$95, $$74])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  window-aggregate [$$74] <- [rank-impl($$83)] partition [$$72, $$95] order (ASC, $$83)
                                   -- WINDOW_STREAM  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$72) (ASC, $$95) (ASC, $$83)
                                       -- STABLE_SORT [$$72(ASC), $$95(ASC), $$83(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$72, $$95]  |PARTITIONED|
+                                          assign [$$72] <- [numeric-mod(to-bigint(substring($$83, -4)), 2)]
                                           -- ASSIGN  |PARTITIONED|
+                                            project ([$$95, $$83])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                join (eq($$ve, $$87))
                                                 -- HYBRID_HASH_JOIN [$$ve][$$87]  |PARTITIONED|
+                                                  exchange
                                                   -- HASH_PARTITION_EXCHANGE [$$ve]  |PARTITIONED|
+                                                    project ([$$95, $$ve])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      unnest $$ve <- scan-collection($$90)
                                                       -- UNNEST  |PARTITIONED|
+                                                        project ([$$95, $$90])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            join (eq($$93, $$89))
                                                             -- HYBRID_HASH_JOIN [$$93][$$89]  |PARTITIONED|
+                                                              exchange
                                                               -- HASH_PARTITION_EXCHANGE [$$93]  |PARTITIONED|
+                                                                replicate
                                                                 -- REPLICATE  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    project ([$$95, $$93])
                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                      assign [$$93] <- [$$94.getField("id")]
                                                                       -- ASSIGN  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                          -- DATASOURCE_SCAN (test.RawTweet)  |PARTITIONED|
+                                                                          data-scan []<-[$$95, $$94] <- test.RawTweet
+                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              empty-tuple-source
                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                              exchange
                                                               -- HASH_PARTITION_EXCHANGE [$$89]  |PARTITIONED|
+                                                                project ([$$90, $$89])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  assign [$$90, $$89] <- [$$v.getField("evidence"), $$v.getField("tweet_id")]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    project ([$$v])
                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                        -- DATASOURCE_SCAN (test.Verification)  |PARTITIONED|
+                                                                        data-scan []<-[$$85, $$v] <- test.Verification
+                                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            empty-tuple-source
                                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                  exchange
                                                   -- HASH_PARTITION_EXCHANGE [$$87]  |PARTITIONED|
+                                                    project ([$$83, $$87])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      assign [$$83, $$87] <- [$$e.getField("url"), $$e.getField("ev_id")]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        project ([$$e])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- DATASOURCE_SCAN (test.Evidence)  |PARTITIONED|
+                                                            data-scan []<-[$$86, $$e] <- test.Evidence
+                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                empty-tuple-source
                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/query-ASTERIXDB-2815.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/query-ASTERIXDB-2815.plan
index 363b2bd..3aefbda 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/query-ASTERIXDB-2815.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/query-ASTERIXDB-2815.plan
@@ -1,74 +1,145 @@
+distribute result [$$68]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$68])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$68] <- [{"id": $$75, "urls": $$63}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$75(ASC) ]  |PARTITIONED|
+          order (ASC, $$75)
           -- STABLE_SORT [$$75(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$75, $$63])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (gt($$74, 2))
                 -- STREAM_SELECT  |PARTITIONED|
+                  project ([$$63, $$74, $$75])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- PRE_CLUSTERED_GROUP_BY[$$70]  |PARTITIONED|
-                              {
+                      group by ([$$84 := $$70]) decor ([$$75]) {
+                                aggregate [$$63, $$74] <- [listify($$62), agg-sql-count($$62)]
                                 -- AGGREGATE  |LOCAL|
+                                  select (not(is-missing($$83)))
                                   -- STREAM_SELECT  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- PRE_CLUSTERED_GROUP_BY[$$70]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$75, $$62, $$83, $$70])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              left outer join (eq($$70, $$82))
                               -- HYBRID_HASH_JOIN [$$70][$$82]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$70, $$75])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$70, $$75] <- [$$82, $$80]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        replicate
                                         -- REPLICATE  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$82, $$80])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$80] <- [$$81.getField("id")]
                                               -- ASSIGN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- DATASOURCE_SCAN (test.RawTweet)  |PARTITIONED|
+                                                  data-scan []<-[$$82, $$81] <- test.RawTweet
+                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                exchange
                                 -- HASH_PARTITION_EXCHANGE [$$82]  |PARTITIONED|
+                                  assign [$$83] <- [true]
                                   -- ASSIGN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      distinct ([$$62, $$82])
                                       -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          order (ASC, $$62) (ASC, $$82)
                                           -- STABLE_SORT [$$62(ASC), $$82(ASC)]  |PARTITIONED|
+                                            exchange
                                             -- HASH_PARTITION_EXCHANGE [$$62, $$82]  |PARTITIONED|
+                                              project ([$$62, $$82])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  join (eq($$ve, $$73))
                                                   -- HYBRID_HASH_JOIN [$$ve][$$73]  |PARTITIONED|
+                                                    exchange
                                                     -- HASH_PARTITION_EXCHANGE [$$ve]  |PARTITIONED|
+                                                      project ([$$82, $$ve])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        unnest $$ve <- scan-collection($$77)
                                                         -- UNNEST  |PARTITIONED|
+                                                          project ([$$82, $$77])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              join (eq($$80, $$76))
                                                               -- HYBRID_HASH_JOIN [$$80][$$76]  |PARTITIONED|
+                                                                exchange
                                                                 -- HASH_PARTITION_EXCHANGE [$$80]  |PARTITIONED|
+                                                                  replicate
                                                                   -- REPLICATE  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      project ([$$82, $$80])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        assign [$$80] <- [$$81.getField("id")]
                                                                         -- ASSIGN  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                            -- DATASOURCE_SCAN (test.RawTweet)  |PARTITIONED|
+                                                                            data-scan []<-[$$82, $$81] <- test.RawTweet
+                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                empty-tuple-source
                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                exchange
                                                                 -- HASH_PARTITION_EXCHANGE [$$76]  |PARTITIONED|
+                                                                  project ([$$77, $$76])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    assign [$$77, $$76] <- [$$v.getField("evidence"), $$v.getField("tweet_id")]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      project ([$$v])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                          -- DATASOURCE_SCAN (test.Verification)  |PARTITIONED|
+                                                                          data-scan []<-[$$71, $$v] <- test.Verification
+                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              empty-tuple-source
                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                    exchange
                                                     -- HASH_PARTITION_EXCHANGE [$$73]  |PARTITIONED|
+                                                      project ([$$62, $$73])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$62, $$73] <- [$$e.getField("url"), $$e.getField("ev_id")]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          project ([$$e])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- DATASOURCE_SCAN (test.Evidence)  |PARTITIONED|
+                                                              data-scan []<-[$$72, $$e] <- test.Evidence
+                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  empty-tuple-source
                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/query-ASTERIXDB-2845.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/query-ASTERIXDB-2845.plan
index 15e7546..bc655c1 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/query-ASTERIXDB-2845.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/query-ASTERIXDB-2845.plan
@@ -1,134 +1,250 @@
+distribute result [$$272]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$272])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$272] <- [{"j_jid": $$277, "j_a": $$285, "m1_jid": $$287, "m1_x": $#4, "m1_c1": $$290, "m2_jid": $#6, "m2_y": $#5, "m2_c2": $$291}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$277(ASC), $#4(ASC), $#5(ASC), $#6(ASC) ]  |PARTITIONED|
+          order (ASC, $$277) (ASC, $#4) (ASC, $#5) (ASC, $#6)
           -- STABLE_SORT [$$277(ASC), $#4(ASC), $#5(ASC), $#6(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$277, $$285, $$287, $#4, $$290, $#6, $#5, $$291])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  left outer join (and(eq($$277, $$303), eq($$240, $$308), eq($$290, $$298), eq($$287, $$299), eq($#4, $$300), eq($$295, $$301)))
                   -- HYBRID_HASH_JOIN [$$277, $$240, $$290, $$287, $#4, $$295][$$303, $$308, $$298, $$299, $$300, $$301]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      window-aggregate [$$295] <- [row-number-impl()] partition [$$277, $$240, $$290, $$287, $#4]
                       -- WINDOW_STREAM  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          order (ASC, $$277) (ASC, $$240) (ASC, $$290) (ASC, $$287) (ASC, $#4)
                           -- STABLE_SORT [$$277(ASC), $$240(ASC), $$290(ASC), $$287(ASC), $#4(ASC)]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$277, $$285, $$287, $#4, $$290, $$240])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  left outer join (eq($$277, $$jid))
                                   -- HYBRID_HASH_JOIN [$$277][$$jid]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$277, $$285])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$285] <- [$$jds.getField("a")]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$277, $$jds])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$277, $$jds] <- [$$303, $$305]
                                             -- ASSIGN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                replicate
                                                 -- REPLICATE  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (test.jds)  |PARTITIONED|
+                                                    data-scan []<-[$$303, $$305] <- test.jds
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$jid]  |PARTITIONED|
+                                      assign [$$290, $#4, $$287] <- [$$240.getField(0), $$240.getField("x"), $$240.getField("jid")]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$jid, $$240])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$240] <- [{"jid": $$jid, "x": $$x, "c1": $$280}]
                                           -- ASSIGN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- SORT_GROUP_BY[$$324, $$325]  |PARTITIONED|
-                                                      {
+                                              group by ([$$jid := $$324; $$x := $$325]) decor ([]) {
+                                                        aggregate [$$280] <- [agg-sql-sum($$323)]
                                                         -- AGGREGATE  |LOCAL|
+                                                          nested tuple source
                                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                      }
+                                                     }
+                                              -- SORT_GROUP_BY[$$324, $$325]  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$324, $$325]  |PARTITIONED|
-                                                  -- SORT_GROUP_BY[$$273, $$274]  |PARTITIONED|
-                                                          {
+                                                  group by ([$$324 := $$273; $$325 := $$274]) decor ([]) {
+                                                            aggregate [$$323] <- [agg-sql-count(1)]
                                                             -- AGGREGATE  |LOCAL|
+                                                              nested tuple source
                                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                          }
+                                                         }
+                                                  -- SORT_GROUP_BY[$$273, $$274]  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      project ([$$273, $$274])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$274, $$273] <- [$$mds.getField("x"), $$mds.getField("jid")]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          project ([$$mds])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            assign [$$mds] <- [$$313]
                                                             -- ASSIGN  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                replicate
                                                                 -- REPLICATE  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    project ([$$313])
                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                        -- DATASOURCE_SCAN (test.mds)  |PARTITIONED|
+                                                                        data-scan []<-[$$314, $$313] <- test.mds
+                                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            empty-tuple-source
                                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (true)
                       -- NESTED_LOOP  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          select (eq($$303, $$299))
                           -- STREAM_SELECT  |PARTITIONED|
+                            window-aggregate [$$301] <- [row-number-impl()] partition [$$303, $$308, $$298, $$299, $$300]
                             -- WINDOW_STREAM  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$303) (ASC, $$308) (ASC, $$298) (ASC, $$299) (ASC, $$300)
                                 -- STABLE_SORT [$$303(ASC), $$308(ASC), $$298(ASC), $$299(ASC), $$300(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$303, $$308, $$298, $$299, $$300])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        left outer join (eq($$303, $$306))
                                         -- HYBRID_HASH_JOIN [$$303][$$306]  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$303])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                replicate
                                                 -- REPLICATE  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (test.jds)  |PARTITIONED|
+                                                    data-scan []<-[$$303, $$305] <- test.jds
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                          exchange
                                           -- HASH_PARTITION_EXCHANGE [$$306]  |PARTITIONED|
+                                            assign [$$300, $$299, $$298] <- [$$308.getField("x"), $$308.getField("jid"), $$308.getField(0)]
                                             -- ASSIGN  |PARTITIONED|
+                                              project ([$$306, $$308])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$308] <- [{"jid": $$306, "x": $$309, "c1": $$310}]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- SORT_GROUP_BY[$$327, $$328]  |PARTITIONED|
-                                                            {
+                                                    group by ([$$306 := $$327; $$309 := $$328]) decor ([]) {
+                                                              aggregate [$$310] <- [agg-sql-sum($$326)]
                                                               -- AGGREGATE  |LOCAL|
+                                                                nested tuple source
                                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                            }
+                                                           }
+                                                    -- SORT_GROUP_BY[$$327, $$328]  |PARTITIONED|
+                                                      exchange
                                                       -- HASH_PARTITION_EXCHANGE [$$327, $$328]  |PARTITIONED|
-                                                        -- SORT_GROUP_BY[$$311, $$312]  |PARTITIONED|
-                                                                {
+                                                        group by ([$$327 := $$311; $$328 := $$312]) decor ([]) {
+                                                                  aggregate [$$326] <- [agg-sql-count(1)]
                                                                   -- AGGREGATE  |LOCAL|
+                                                                    nested tuple source
                                                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                }
+                                                               }
+                                                        -- SORT_GROUP_BY[$$311, $$312]  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            project ([$$311, $$312])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$311, $$312] <- [$$313.getField("jid"), $$313.getField("x")]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  replicate
                                                                   -- REPLICATE  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      project ([$$313])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                          -- DATASOURCE_SCAN (test.mds)  |PARTITIONED|
+                                                                          data-scan []<-[$$314, $$313] <- test.mds
+                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              empty-tuple-source
                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                          project ([$#6, $#5, $$291])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$291, $#6, $#5] <- [$$256.getField(0), $$256.getField("jid"), $$256.getField("y")]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$256])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$256] <- [{"jid": $$jid, "y": $$y, "c2": $$281}]
                                 -- ASSIGN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- SORT_GROUP_BY[$$330, $$331]  |PARTITIONED|
-                                            {
+                                    group by ([$$jid := $$330; $$y := $$331]) decor ([]) {
+                                              aggregate [$$281] <- [agg-sql-sum($$329)]
                                               -- AGGREGATE  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                            }
+                                           }
+                                    -- SORT_GROUP_BY[$$330, $$331]  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$330, $$331]  |PARTITIONED|
-                                        -- SORT_GROUP_BY[$$275, $$276]  |PARTITIONED|
-                                                {
+                                        group by ([$$330 := $$275; $$331 := $$276]) decor ([]) {
+                                                  aggregate [$$329] <- [agg-sql-count(1)]
                                                   -- AGGREGATE  |LOCAL|
+                                                    nested tuple source
                                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                }
+                                               }
+                                        -- SORT_GROUP_BY[$$275, $$276]  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$275, $$276])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$276, $$275] <- [$$mds.getField("y"), $$mds.getField("jid")]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$mds])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$mds] <- [$$313]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      replicate
                                                       -- REPLICATE  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          project ([$$313])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- DATASOURCE_SCAN (test.mds)  |PARTITIONED|
+                                                              data-scan []<-[$$314, $$313] <- test.mds
+                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  empty-tuple-source
                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/query-ASTERIXDB-3006.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/query-ASTERIXDB-3006.plan
index dfaa310..1d828b0 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/query-ASTERIXDB-3006.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/subquery/query-ASTERIXDB-3006.plan
@@ -1,41 +1,76 @@
+distribute result [$$ds1]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$ds1])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- SORT_MERGE_EXCHANGE [$$55(ASC) ]  |PARTITIONED|
+        project ([$$ds1, $$55])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (neq($$49, 0))
           -- STREAM_SELECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- SORT_GROUP_BY[$$65]  |PARTITIONED|
-                      {
+              group by ([$$55 := $$65]) decor ([$$ds1]) {
+                        aggregate [$$49] <- [agg-sum($$64)]
                         -- AGGREGATE  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SORT_GROUP_BY[$$65]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$65]  |PARTITIONED|
-                  -- PRE_CLUSTERED_GROUP_BY[$$46]  |PARTITIONED|
-                          {
+                  group by ([$$65 := $$46]) decor ([$$ds1]) {
+                            aggregate [$$64] <- [agg-count({"$1": 1})]
                             -- AGGREGATE  |LOCAL|
+                              select (not(is-missing($$54)))
                               -- STREAM_SELECT  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                         }
+                  -- PRE_CLUSTERED_GROUP_BY[$$46]  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$46)
                       -- STABLE_SORT [$$46(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$ds1, $$54, $$46])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              left outer join (eq($$48, $$b))
                               -- HYBRID_HASH_JOIN [$$b][$$48]  |PARTITIONED|
+                                exchange
                                 -- HASH_PARTITION_EXCHANGE [$$b]  |PARTITIONED|
+                                  project ([$$ds1, $$46, $$b])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    unnest $$b <- scan-collection($$50)
                                     -- UNNEST  |PARTITIONED|
+                                      assign [$$50] <- [array-star($$ds1.getField("a")).getField("b")]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.ds1)  |PARTITIONED|
+                                          data-scan []<-[$$46, $$ds1] <- test.ds1
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                exchange
                                 -- HASH_PARTITION_EXCHANGE [$$48]  |PARTITIONED|
+                                  project ([$$54, $$48])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$54, $$48] <- [true, get-item($$ds2.getField("x"), 0).getField("y")]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$ds2])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.ds2)  |PARTITIONED|
+                                          data-scan []<-[$$47, $$ds2] <- test.ds2
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                              empty-tuple-source
+                                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_after/interval_after.3.query.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_after/interval_after.3.query.plan
index 516f5ac..c59df08 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_after/interval_after.3.query.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_after/interval_after.3.query.plan
@@ -1,31 +1,62 @@
+distribute result [$$29]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$29])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$29] <- [{"staff": $$30, "student": $$31}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$30, $$31])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (interval-after($$32, $$33))
             -- INTERVAL_MERGE_JOIN [$$32] [$$33]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (ASC, $$32)
                 -- STABLE_SORT [$$32(ASC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$30, $$32])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- RANGE_PARTITION_EXCHANGE [$$36(ASC)] RANGE_MAP:{SPLIT:3}  |PARTITIONED|
+                        assign [$$36] <- [get-interval-start($$32)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$30, $$32])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$32] <- [$$f.getField(2)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (TinyCollege.Staff)  |PARTITIONED|
+                                data-scan []<-[$$30, $$f] <- TinyCollege.Staff
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (ASC, $$33)
                 -- STABLE_SORT [$$33(ASC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$31, $$33])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- PARTIAL_BROADCAST_RANGE_FOLLOWING_EXCHANGE [$$38(ASC)] RANGE_MAP:{SPLIT:3}  |PARTITIONED|
+                        assign [$$38] <- [get-interval-start($$33)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$31, $$33])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$33] <- [$$d.getField(2)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (TinyCollege.Students)  |PARTITIONED|
+                                data-scan []<-[$$31, $$d] <- TinyCollege.Students
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_before/interval_before.3.query.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_before/interval_before.3.query.plan
index 04ec25e..5232e05 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_before/interval_before.3.query.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_before/interval_before.3.query.plan
@@ -1,31 +1,62 @@
+distribute result [$$29]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$29])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$29] <- [{"staff": $$30, "student": $$31}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$30, $$31])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (interval-before($$32, $$33))
             -- INTERVAL_MERGE_JOIN [$$32] [$$33]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (ASC, $$32)
                 -- STABLE_SORT [$$32(ASC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$30, $$32])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- PARTIAL_BROADCAST_RANGE_FOLLOWING_EXCHANGE [$$36(ASC)] RANGE_MAP:{SPLIT:3}  |PARTITIONED|
+                        assign [$$36] <- [get-interval-start($$32)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$30, $$32])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$32] <- [$$f.getField(2)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (TinyCollege.Staff)  |PARTITIONED|
+                                data-scan []<-[$$30, $$f] <- TinyCollege.Staff
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (ASC, $$33)
                 -- STABLE_SORT [$$33(ASC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$31, $$33])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- RANGE_PARTITION_EXCHANGE [$$38(ASC)] RANGE_MAP:{SPLIT:3}  |PARTITIONED|
+                        assign [$$38] <- [get-interval-start($$33)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$31, $$33])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$33] <- [$$d.getField(2)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (TinyCollege.Students)  |PARTITIONED|
+                                data-scan []<-[$$31, $$d] <- TinyCollege.Students
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_covered_by/interval_covered_by.3.query.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_covered_by/interval_covered_by.3.query.plan
index 2c9e100..c202345 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_covered_by/interval_covered_by.3.query.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_covered_by/interval_covered_by.3.query.plan
@@ -1,31 +1,62 @@
+distribute result [$$29]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$29])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$29] <- [{"staff": $$30, "student": $$31}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$30, $$31])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (interval-covered-by($$32, $$33))
             -- INTERVAL_MERGE_JOIN [$$32] [$$33]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (ASC, $$32)
                 -- STABLE_SORT [$$32(ASC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$30, $$32])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- RANGE_PARTITION_EXCHANGE [$$36(ASC)] RANGE_MAP:{SPLIT:3}  |PARTITIONED|
+                        assign [$$36] <- [get-interval-start($$32)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$30, $$32])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$32] <- [$$f.getField(2)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (TinyCollege.Staff)  |PARTITIONED|
+                                data-scan []<-[$$30, $$f] <- TinyCollege.Staff
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (ASC, $$33)
                 -- STABLE_SORT [$$33(ASC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$31, $$33])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- PARTIAL_BROADCAST_RANGE_INTERSECT_EXCHANGE [{$$38,$$39,ASC}] RANGE_MAP:{SPLIT:3}  |PARTITIONED|
+                        assign [$$38, $$39] <- [get-interval-start($$33), get-interval-end($$33)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$31, $$33])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$33] <- [$$d.getField(2)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (TinyCollege.Students)  |PARTITIONED|
+                                data-scan []<-[$$31, $$d] <- TinyCollege.Students
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_covers/interval_covers.3.query.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_covers/interval_covers.3.query.plan
index 90c6f12..77561b9 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_covers/interval_covers.3.query.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_covers/interval_covers.3.query.plan
@@ -1,31 +1,62 @@
+distribute result [$$29]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$29])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$29] <- [{"staff": $$30, "student": $$31}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$30, $$31])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (interval-covers($$32, $$33))
             -- INTERVAL_MERGE_JOIN [$$32] [$$33]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (ASC, $$32)
                 -- STABLE_SORT [$$32(ASC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$30, $$32])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- PARTIAL_BROADCAST_RANGE_INTERSECT_EXCHANGE [{$$36,$$37,ASC}] RANGE_MAP:{SPLIT:3}  |PARTITIONED|
+                        assign [$$36, $$37] <- [get-interval-start($$32), get-interval-end($$32)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$30, $$32])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$32] <- [$$f.getField(2)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (TinyCollege.Staff)  |PARTITIONED|
+                                data-scan []<-[$$30, $$f] <- TinyCollege.Staff
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (ASC, $$33)
                 -- STABLE_SORT [$$33(ASC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$31, $$33])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- RANGE_PARTITION_EXCHANGE [$$38(ASC)] RANGE_MAP:{SPLIT:3}  |PARTITIONED|
+                        assign [$$38] <- [get-interval-start($$33)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$31, $$33])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$33] <- [$$d.getField(2)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (TinyCollege.Students)  |PARTITIONED|
+                                data-scan []<-[$$31, $$d] <- TinyCollege.Students
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_ended_by/interval_ended_by.3.query.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_ended_by/interval_ended_by.3.query.plan
index 2f858cf..a1b05cd 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_ended_by/interval_ended_by.3.query.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_ended_by/interval_ended_by.3.query.plan
@@ -1,27 +1,54 @@
+distribute result [$$29]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$29])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$29] <- [{"staff": $$32, "student": $$33}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$32, $$33])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (le($$34, $$35))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$32, $$35, $$33, $$34])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                join (eq($$36, $$37))
                 -- HYBRID_HASH_JOIN [$$36][$$37]  |PARTITIONED|
+                  exchange
                   -- HASH_PARTITION_EXCHANGE [$$36]  |PARTITIONED|
+                    project ([$$32, $$35, $$36])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$36, $$35] <- [get-interval-end($$31), get-interval-start($$31)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$32, $$31])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$31] <- [$$f.getField(2)]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (TinyCollege.Staff)  |PARTITIONED|
+                              data-scan []<-[$$32, $$f] <- TinyCollege.Staff
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- HASH_PARTITION_EXCHANGE [$$37]  |PARTITIONED|
+                    project ([$$33, $$34, $$37])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$37, $$34] <- [get-interval-end($$30), get-interval-start($$30)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$33, $$30])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$30] <- [$$d.getField(2)]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (TinyCollege.Students)  |PARTITIONED|
+                              data-scan []<-[$$33, $$d] <- TinyCollege.Students
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_ends/interval_ends.3.query.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_ends/interval_ends.3.query.plan
index 2f858cf..39533d9 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_ends/interval_ends.3.query.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_ends/interval_ends.3.query.plan
@@ -1,27 +1,54 @@
+distribute result [$$29]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$29])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$29] <- [{"staff": $$32, "student": $$33}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$32, $$33])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (le($$34, $$35))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$32, $$34, $$33, $$35])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                join (eq($$36, $$37))
                 -- HYBRID_HASH_JOIN [$$36][$$37]  |PARTITIONED|
+                  exchange
                   -- HASH_PARTITION_EXCHANGE [$$36]  |PARTITIONED|
+                    project ([$$32, $$34, $$36])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$36, $$34] <- [get-interval-end($$30), get-interval-start($$30)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$32, $$30])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$30] <- [$$f.getField(2)]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (TinyCollege.Staff)  |PARTITIONED|
+                              data-scan []<-[$$32, $$f] <- TinyCollege.Staff
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- HASH_PARTITION_EXCHANGE [$$37]  |PARTITIONED|
+                    project ([$$33, $$35, $$37])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$37, $$35] <- [get-interval-end($$31), get-interval-start($$31)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$33, $$31])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$31] <- [$$d.getField(2)]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (TinyCollege.Students)  |PARTITIONED|
+                              data-scan []<-[$$33, $$d] <- TinyCollege.Students
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_meets/interval_meets.3.query.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_meets/interval_meets.3.query.plan
index a5761ed..f9ede4b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_meets/interval_meets.3.query.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_meets/interval_meets.3.query.plan
@@ -1,21 +1,42 @@
+distribute result [$$29]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$29])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$29] <- [{"staff": $$30, "student": $$31}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$30, $$31])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$32, $$33))
             -- HYBRID_HASH_JOIN [$$32][$$33]  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$32]  |PARTITIONED|
+                project ([$$30, $$32])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$32] <- [get-interval-end($$f.getField(2))]
                   -- ASSIGN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (TinyCollege.Staff)  |PARTITIONED|
+                      data-scan []<-[$$30, $$f] <- TinyCollege.Staff
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$33]  |PARTITIONED|
+                project ([$$31, $$33])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$33] <- [get-interval-start($$d.getField(2))]
                   -- ASSIGN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (TinyCollege.Students)  |PARTITIONED|
+                      data-scan []<-[$$31, $$d] <- TinyCollege.Students
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_met_by/interval_met_by.3.query.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_met_by/interval_met_by.3.query.plan
index a5761ed..5104a71 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_met_by/interval_met_by.3.query.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_met_by/interval_met_by.3.query.plan
@@ -1,21 +1,42 @@
+distribute result [$$29]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$29])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$29] <- [{"staff": $$30, "student": $$31}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$30, $$31])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$32, $$33))
             -- HYBRID_HASH_JOIN [$$32][$$33]  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$32]  |PARTITIONED|
+                project ([$$30, $$32])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$32] <- [get-interval-start($$f.getField(2))]
                   -- ASSIGN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (TinyCollege.Staff)  |PARTITIONED|
+                      data-scan []<-[$$30, $$f] <- TinyCollege.Staff
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$33]  |PARTITIONED|
+                project ([$$31, $$33])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$33] <- [get-interval-end($$d.getField(2))]
                   -- ASSIGN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (TinyCollege.Students)  |PARTITIONED|
+                      data-scan []<-[$$31, $$d] <- TinyCollege.Students
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_overlapped_by/interval_overlapped_by.3.query.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_overlapped_by/interval_overlapped_by.3.query.plan
index 2c9e100..018258f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_overlapped_by/interval_overlapped_by.3.query.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_overlapped_by/interval_overlapped_by.3.query.plan
@@ -1,31 +1,62 @@
+distribute result [$$29]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$29])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$29] <- [{"staff": $$30, "student": $$31}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$30, $$31])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (interval-overlapped-by($$32, $$33))
             -- INTERVAL_MERGE_JOIN [$$32] [$$33]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (ASC, $$32)
                 -- STABLE_SORT [$$32(ASC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$30, $$32])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- RANGE_PARTITION_EXCHANGE [$$36(ASC)] RANGE_MAP:{SPLIT:3}  |PARTITIONED|
+                        assign [$$36] <- [get-interval-start($$32)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$30, $$32])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$32] <- [$$f.getField(2)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (TinyCollege.Staff)  |PARTITIONED|
+                                data-scan []<-[$$30, $$f] <- TinyCollege.Staff
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (ASC, $$33)
                 -- STABLE_SORT [$$33(ASC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$31, $$33])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- PARTIAL_BROADCAST_RANGE_INTERSECT_EXCHANGE [{$$38,$$39,ASC}] RANGE_MAP:{SPLIT:3}  |PARTITIONED|
+                        assign [$$38, $$39] <- [get-interval-start($$33), get-interval-end($$33)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$31, $$33])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$33] <- [$$d.getField(2)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (TinyCollege.Students)  |PARTITIONED|
+                                data-scan []<-[$$31, $$d] <- TinyCollege.Students
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_overlapping/interval_overlapping.3.query.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_overlapping/interval_overlapping.3.query.plan
index cd143c5..d2baf20 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_overlapping/interval_overlapping.3.query.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_overlapping/interval_overlapping.3.query.plan
@@ -1,31 +1,62 @@
+distribute result [$$29]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$29])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$29] <- [{"staff": $$30, "student": $$31}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$30, $$31])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (interval-overlapping($$32, $$33))
             -- INTERVAL_MERGE_JOIN [$$32] [$$33]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (ASC, $$32)
                 -- STABLE_SORT [$$32(ASC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$30, $$32])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- PARTIAL_BROADCAST_RANGE_INTERSECT_EXCHANGE [{$$36,$$37,ASC}] RANGE_MAP:{SPLIT:3}  |PARTITIONED|
+                        assign [$$36, $$37] <- [get-interval-start($$32), get-interval-end($$32)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$30, $$32])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$32] <- [$$f.getField(2)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (TinyCollege.Staff)  |PARTITIONED|
+                                data-scan []<-[$$30, $$f] <- TinyCollege.Staff
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (ASC, $$33)
                 -- STABLE_SORT [$$33(ASC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$31, $$33])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- PARTIAL_BROADCAST_RANGE_INTERSECT_EXCHANGE [{$$38,$$39,ASC}] RANGE_MAP:{SPLIT:3}  |PARTITIONED|
+                        assign [$$38, $$39] <- [get-interval-start($$33), get-interval-end($$33)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$31, $$33])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$33] <- [$$d.getField(2)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (TinyCollege.Students)  |PARTITIONED|
+                                data-scan []<-[$$31, $$d] <- TinyCollege.Students
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_overlaps/interval_overlaps.3.query.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_overlaps/interval_overlaps.3.query.plan
index 90c6f12..d83a5c2 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_overlaps/interval_overlaps.3.query.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_overlaps/interval_overlaps.3.query.plan
@@ -1,31 +1,62 @@
+distribute result [$$29]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$29])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$29] <- [{"staff": $$30, "student": $$31}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$30, $$31])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (interval-overlaps($$32, $$33))
             -- INTERVAL_MERGE_JOIN [$$32] [$$33]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (ASC, $$32)
                 -- STABLE_SORT [$$32(ASC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$30, $$32])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- PARTIAL_BROADCAST_RANGE_INTERSECT_EXCHANGE [{$$36,$$37,ASC}] RANGE_MAP:{SPLIT:3}  |PARTITIONED|
+                        assign [$$36, $$37] <- [get-interval-start($$32), get-interval-end($$32)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$30, $$32])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$32] <- [$$f.getField(2)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (TinyCollege.Staff)  |PARTITIONED|
+                                data-scan []<-[$$30, $$f] <- TinyCollege.Staff
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (ASC, $$33)
                 -- STABLE_SORT [$$33(ASC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$31, $$33])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- RANGE_PARTITION_EXCHANGE [$$38(ASC)] RANGE_MAP:{SPLIT:3}  |PARTITIONED|
+                        assign [$$38] <- [get-interval-start($$33)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$31, $$33])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$33] <- [$$d.getField(2)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (TinyCollege.Students)  |PARTITIONED|
+                                data-scan []<-[$$31, $$d] <- TinyCollege.Students
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_started_by/interval_started_by.3.query.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_started_by/interval_started_by.3.query.plan
index 2dce309..a26a9cd 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_started_by/interval_started_by.3.query.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_started_by/interval_started_by.3.query.plan
@@ -1,27 +1,54 @@
+distribute result [$$29]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$29])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$29] <- [{"staff": $$32, "student": $$33}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$32, $$33])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (le($$36, $$37))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$32, $$37, $$33, $$36])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                join (eq($$34, $$35))
                 -- HYBRID_HASH_JOIN [$$34][$$35]  |PARTITIONED|
+                  exchange
                   -- HASH_PARTITION_EXCHANGE [$$34]  |PARTITIONED|
+                    project ([$$32, $$34, $$37])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$37, $$34] <- [get-interval-end($$30), get-interval-start($$30)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$32, $$30])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$30] <- [$$f.getField(2)]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (TinyCollege.Staff)  |PARTITIONED|
+                              data-scan []<-[$$32, $$f] <- TinyCollege.Staff
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- HASH_PARTITION_EXCHANGE [$$35]  |PARTITIONED|
+                    project ([$$33, $$35, $$36])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$36, $$35] <- [get-interval-end($$31), get-interval-start($$31)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$33, $$31])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$31] <- [$$d.getField(2)]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (TinyCollege.Students)  |PARTITIONED|
+                              data-scan []<-[$$33, $$d] <- TinyCollege.Students
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_starts/interval_starts.3.query.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_starts/interval_starts.3.query.plan
index 2dce309..fb6b791 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_starts/interval_starts.3.query.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/temporal/interval_joins/interval_starts/interval_starts.3.query.plan
@@ -1,27 +1,54 @@
+distribute result [$$29]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$29])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$29] <- [{"staff": $$32, "student": $$33}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$32, $$33])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (le($$36, $$37))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$32, $$36, $$33, $$37])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                join (eq($$34, $$35))
                 -- HYBRID_HASH_JOIN [$$34][$$35]  |PARTITIONED|
+                  exchange
                   -- HASH_PARTITION_EXCHANGE [$$34]  |PARTITIONED|
+                    project ([$$32, $$34, $$36])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$36, $$34] <- [get-interval-end($$30), get-interval-start($$30)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$32, $$30])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$30] <- [$$f.getField(2)]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (TinyCollege.Staff)  |PARTITIONED|
+                              data-scan []<-[$$32, $$f] <- TinyCollege.Staff
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- HASH_PARTITION_EXCHANGE [$$35]  |PARTITIONED|
+                    project ([$$33, $$35, $$37])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$37, $$35] <- [get-interval-end($$31), get-interval-start($$31)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$33, $$31])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$31] <- [$$d.getField(2)]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (TinyCollege.Students)  |PARTITIONED|
+                              data-scan []<-[$$33, $$d] <- TinyCollege.Students
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1580.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1580.plan
index 71d5343..7df6234 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1580.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1580.plan
@@ -1,73 +1,140 @@
+distribute result [$$117]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    limit 100
     -- STREAM_LIMIT  |UNPARTITIONED|
+      project ([$$117])
       -- STREAM_PROJECT  |PARTITIONED|
+        assign [$$117] <- [{"state": $$ca_state, "cnt": $$128}]
         -- ASSIGN  |PARTITIONED|
+          exchange
           -- SORT_MERGE_EXCHANGE [$$128(ASC) ]  |PARTITIONED|
+            limit 100
             -- STREAM_LIMIT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (topK: 100) (ASC, $$128)
                 -- STABLE_SORT [topK: 100] [$$128(ASC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$ca_state, $$128])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      select (ge($$127, 10))
                       -- STREAM_SELECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- SORT_GROUP_BY[$$137]  |PARTITIONED|
-                                  {
+                          group by ([$$ca_state := $$137]) decor ([]) {
+                                    aggregate [$$127, $$128] <- [agg-sql-sum($$135), agg-sql-sum($$136)]
                                     -- AGGREGATE  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                  }
+                                 }
+                          -- SORT_GROUP_BY[$$137]  |PARTITIONED|
+                            exchange
                             -- HASH_PARTITION_EXCHANGE [$$137]  |PARTITIONED|
-                              -- SORT_GROUP_BY[$$118]  |PARTITIONED|
-                                      {
+                              group by ([$$137 := $$118]) decor ([]) {
+                                        aggregate [$$135, $$136] <- [agg-sql-count($$a), agg-sql-count($$a)]
                                         -- AGGREGATE  |LOCAL|
+                                          nested tuple source
                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                      }
+                                     }
+                              -- SORT_GROUP_BY[$$118]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$a, $$118])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      join (eq($$121, $$124))
                                       -- HYBRID_HASH_JOIN [$$121][$$124]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$121]  |PARTITIONED|
+                                          project ([$$a, $$118, $$121])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              join (eq($$129, $$123))
                                               -- HYBRID_HASH_JOIN [$$129][$$123]  |PARTITIONED|
+                                                exchange
                                                 -- HASH_PARTITION_EXCHANGE [$$129]  |PARTITIONED|
+                                                  project ([$$a, $$118, $$121, $$129])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      join (eq($$120, $$134))
                                                       -- HYBRID_HASH_JOIN [$$120][$$134]  |PARTITIONED|
+                                                        exchange
                                                         -- HASH_PARTITION_EXCHANGE [$$120]  |PARTITIONED|
+                                                          project ([$$a, $$118, $$120])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              join (eq($$119, $$132))
                                                               -- HYBRID_HASH_JOIN [$$119][$$132]  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  assign [$$118] <- [$$a.getField(8)]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- DATASOURCE_SCAN (tpcds.customer_address)  |PARTITIONED|
+                                                                      data-scan []<-[$$119, $$a] <- tpcds.customer_address
+                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          empty-tuple-source
                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                exchange
                                                                 -- HASH_PARTITION_EXCHANGE [$$132]  |PARTITIONED|
+                                                                  project ([$$120, $$132])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    assign [$$132] <- [$$c.getField(4)]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                        -- DATASOURCE_SCAN (tpcds.customer)  |PARTITIONED|
+                                                                        data-scan []<-[$$120, $$c] <- tpcds.customer
+                                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            empty-tuple-source
                                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                        exchange
                                                         -- HASH_PARTITION_EXCHANGE [$$134]  |PARTITIONED|
+                                                          project ([$$121, $$129, $$134])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            assign [$$129, $$134] <- [$$s.getField(0), $$s.getField(3)]
                                                             -- ASSIGN  |PARTITIONED|
+                                                              project ([$$121, $$s])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- DATASOURCE_SCAN (tpcds.store_sales)  |PARTITIONED|
+                                                                  data-scan []<-[$$121, $$122, $$s] <- tpcds.store_sales
+                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      empty-tuple-source
                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  project ([$$123])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (tpcds.date_dim)  |PARTITIONED|
+                                                      data-scan []<-[$$123, $$d] <- tpcds.date_dim
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$124])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (tpcds.item)  |PARTITIONED|
+                                              data-scan []<-[$$124, $$i] <- tpcds.item
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1581-2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1581-2.plan
index 6e589bc..e24495b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1581-2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1581-2.plan
@@ -1,142 +1,284 @@
+distribute result [$$142]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$142])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$142] <- [{"bucket1": $$140}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$140])
         -- STREAM_PROJECT  |PARTITIONED|
+          unnest $$140 <- scan-collection($$139)
           -- UNNEST  |PARTITIONED|
+            project ([$$139])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$139] <- [switch-case(true, lt(get-item($$102, 0), 25437), cast($$121), cast($$138))]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  join (true)
                   -- NESTED_LOOP  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (true)
                       -- NESTED_LOOP  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          join (true)
                           -- NESTED_LOOP  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- BTREE_SEARCH (tpcds.item.item)  |PARTITIONED|
+                                  unnest-map [$$146, $$item] <- index-search("item", 0, "tpcds", "item", false, false, 1, $$205, 1, $$206, true, true, true)
+                                  -- BTREE_SEARCH  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      assign [$$205, $$206] <- [1, 1]
                                       -- ASSIGN  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                              aggregate [$$138] <- [listify($$137)]
                               -- AGGREGATE  |UNPARTITIONED|
+                                aggregate [$$137] <- [listify($$136)]
                                 -- AGGREGATE  |UNPARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                    join (true)
                                     -- NESTED_LOOP  |UNPARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                        project ([])
                                         -- STREAM_PROJECT  |UNPARTITIONED|
+                                          select (not(or(and($$209, not(is-unknown($$209))))))
                                           -- STREAM_SELECT  |UNPARTITIONED|
+                                            project ([$$209])
                                             -- STREAM_PROJECT  |UNPARTITIONED|
+                                              assign [$$209] <- [lt(get-item($$185, 0), 25437)]
                                               -- ASSIGN  |UNPARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                  replicate
                                                   -- REPLICATE  |UNPARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                      aggregate [$$185] <- [listify($$187)]
                                                       -- AGGREGATE  |UNPARTITIONED|
+                                                        aggregate [$$187] <- [agg-sql-sum($$200)]
                                                         -- AGGREGATE  |UNPARTITIONED|
+                                                          exchange
                                                           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                                                            aggregate [$$200] <- [agg-sql-count(1)]
                                                             -- AGGREGATE  |PARTITIONED|
+                                                              select (and(le($$193, 20), ge($$193, 1)))
                                                               -- STREAM_SELECT  |PARTITIONED|
+                                                                project ([$$193])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  assign [$$193] <- [$$192.getField(10)]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    project ([$$192])
                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                      assign [$$192] <- [$$158]
                                                                       -- ASSIGN  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          replicate
                                                                           -- REPLICATE  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              project ([$$158])
                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                  -- DATASOURCE_SCAN (tpcds.store_sales)  |PARTITIONED|
+                                                                                  data-scan []<-[$$160, $$161, $$158] <- tpcds.store_sales
+                                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                    exchange
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                      empty-tuple-source
                                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                        project ([$$136])
                                         -- STREAM_PROJECT  |UNPARTITIONED|
+                                          assign [$$136] <- [{"$2": $$155}]
                                           -- ASSIGN  |UNPARTITIONED|
+                                            aggregate [$$155] <- [agg-global-sql-avg($$201)]
                                             -- AGGREGATE  |UNPARTITIONED|
+                                              exchange
                                               -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                                                aggregate [$$201] <- [agg-local-sql-avg($$134)]
                                                 -- AGGREGATE  |PARTITIONED|
+                                                  project ([$$134])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    select (and(le($$159, 20), ge($$159, 1)))
                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                      project ([$$134, $$159])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$134, $$159] <- [$$158.getField(22), $$158.getField(10)]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            replicate
                                                             -- REPLICATE  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                project ([$$158])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (tpcds.store_sales)  |PARTITIONED|
+                                                                    data-scan []<-[$$160, $$161, $$158] <- tpcds.store_sales
+                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        empty-tuple-source
                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                          aggregate [$$121] <- [listify($$120)]
                           -- AGGREGATE  |UNPARTITIONED|
+                            aggregate [$$120] <- [listify($$119)]
                             -- AGGREGATE  |UNPARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                join (true)
                                 -- NESTED_LOOP  |UNPARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                    project ([])
                                     -- STREAM_PROJECT  |UNPARTITIONED|
+                                      select (lt(get-item($$174, 0), 25437))
                                       -- STREAM_SELECT  |UNPARTITIONED|
+                                        project ([$$174])
                                         -- STREAM_PROJECT  |UNPARTITIONED|
+                                          assign [$$174] <- [$$185]
                                           -- ASSIGN  |UNPARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                              replicate
                                               -- REPLICATE  |UNPARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                  aggregate [$$185] <- [listify($$187)]
                                                   -- AGGREGATE  |UNPARTITIONED|
+                                                    aggregate [$$187] <- [agg-sql-sum($$200)]
                                                     -- AGGREGATE  |UNPARTITIONED|
+                                                      exchange
                                                       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                                                        aggregate [$$200] <- [agg-sql-count(1)]
                                                         -- AGGREGATE  |PARTITIONED|
+                                                          select (and(le($$193, 20), ge($$193, 1)))
                                                           -- STREAM_SELECT  |PARTITIONED|
+                                                            project ([$$193])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$193] <- [$$192.getField(10)]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                project ([$$192])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  assign [$$192] <- [$$158]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      replicate
                                                                       -- REPLICATE  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          project ([$$158])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                              -- DATASOURCE_SCAN (tpcds.store_sales)  |PARTITIONED|
+                                                                              data-scan []<-[$$160, $$161, $$158] <- tpcds.store_sales
+                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  empty-tuple-source
                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                    project ([$$119])
                                     -- STREAM_PROJECT  |UNPARTITIONED|
+                                      assign [$$119] <- [{"$1": $$154}]
                                       -- ASSIGN  |UNPARTITIONED|
+                                        aggregate [$$154] <- [agg-global-sql-avg($$203)]
                                         -- AGGREGATE  |UNPARTITIONED|
+                                          exchange
                                           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                                            aggregate [$$203] <- [agg-local-sql-avg($$117)]
                                             -- AGGREGATE  |PARTITIONED|
+                                              project ([$$117])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                select (and(le($$165, 20), ge($$165, 1)))
                                                 -- STREAM_SELECT  |PARTITIONED|
+                                                  project ([$$117, $$165])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    assign [$$117, $$165] <- [$$164.getField(14), $$164.getField(10)]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      project ([$$164])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$164] <- [$$158]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            replicate
                                                             -- REPLICATE  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                project ([$$158])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (tpcds.store_sales)  |PARTITIONED|
+                                                                    data-scan []<-[$$160, $$161, $$158] <- tpcds.store_sales
+                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        empty-tuple-source
                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                    exchange
                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                      project ([$$102])
                       -- STREAM_PROJECT  |UNPARTITIONED|
+                        assign [$$102] <- [$$185]
                         -- ASSIGN  |UNPARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                            replicate
                             -- REPLICATE  |UNPARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                aggregate [$$185] <- [listify($$187)]
                                 -- AGGREGATE  |UNPARTITIONED|
+                                  aggregate [$$187] <- [agg-sql-sum($$200)]
                                   -- AGGREGATE  |UNPARTITIONED|
+                                    exchange
                                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                                      aggregate [$$200] <- [agg-sql-count(1)]
                                       -- AGGREGATE  |PARTITIONED|
+                                        select (and(le($$193, 20), ge($$193, 1)))
                                         -- STREAM_SELECT  |PARTITIONED|
+                                          project ([$$193])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$193] <- [$$192.getField(10)]
                                             -- ASSIGN  |PARTITIONED|
+                                              project ([$$192])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$192] <- [$$158]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    replicate
                                                     -- REPLICATE  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        project ([$$158])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- DATASOURCE_SCAN (tpcds.store_sales)  |PARTITIONED|
+                                                            data-scan []<-[$$160, $$161, $$158] <- tpcds.store_sales
+                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                empty-tuple-source
                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1581-correlated-2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1581-correlated-2.plan
index bda21dc..2b46c5a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1581-correlated-2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1581-correlated-2.plan
@@ -1,339 +1,639 @@
+distribute result [$$136]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$136])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$136] <- [{"bucket1": $$134}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$134])
         -- STREAM_PROJECT  |PARTITIONED|
+          unnest $$134 <- scan-collection($$133)
           -- UNNEST  |PARTITIONED|
+            project ([$$133])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$133] <- [switch-case(true, lt(get-item($$100, 0), 25437), cast($$117), cast($$132))]
               -- ASSIGN  |PARTITIONED|
+                project ([$$100, $$132, $$117])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- PRE_CLUSTERED_GROUP_BY[$$227]  |PARTITIONED|
-                            {
+                    group by ([$$229 := $$227]) decor ([$$132; $$117]) {
+                              aggregate [$$100] <- [listify($$144)]
                               -- AGGREGATE  |LOCAL|
+                                aggregate [$$144] <- [agg-sql-count(1)]
                                 -- AGGREGATE  |LOCAL|
+                                  select (not(is-missing($$228)))
                                   -- STREAM_SELECT  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                            }
+                           }
+                    -- PRE_CLUSTERED_GROUP_BY[$$227]  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$117, $$132, $$228, $$227])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            left outer join (eq($$175, $$227))
                             -- HYBRID_HASH_JOIN [$$227][$$175]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- PRE_CLUSTERED_GROUP_BY[$$189]  |PARTITIONED|
-                                        {
+                                group by ([$$227 := $$189]) decor ([$$132]) {
+                                          aggregate [$$117] <- [listify($$116)]
                                           -- AGGREGATE  |LOCAL|
+                                            aggregate [$$116] <- [listify($$115)]
                                             -- AGGREGATE  |LOCAL|
+                                              select (not(is-missing($$226)))
                                               -- STREAM_SELECT  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- PRE_CLUSTERED_GROUP_BY[$$189]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$189)
                                     -- STABLE_SORT [$$189(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$132, $$115, $$226, $$189])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            left outer join (eq($$189, $$225))
                                             -- HYBRID_HASH_JOIN [$$189][$$225]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- PRE_CLUSTERED_GROUP_BY[$$137]  |PARTITIONED|
-                                                        {
+                                                group by ([$$189 := $$137]) decor ([]) {
+                                                          aggregate [$$132] <- [listify($$131)]
                                                           -- AGGREGATE  |LOCAL|
+                                                            aggregate [$$131] <- [listify($$130)]
                                                             -- AGGREGATE  |LOCAL|
+                                                              select (not(is-missing($$188)))
                                                               -- STREAM_SELECT  |LOCAL|
+                                                                nested tuple source
                                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                        }
+                                                       }
+                                                -- PRE_CLUSTERED_GROUP_BY[$$137]  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$$130, $$188, $$137])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        left outer join (eq($$137, $$187))
                                                         -- HYBRID_HASH_JOIN [$$137][$$187]  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            project ([$$137])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$137, $$item] <- [$$208, $$205]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  replicate
                                                                   -- REPLICATE  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- BTREE_SEARCH (tpcds.item.item)  |PARTITIONED|
+                                                                      unnest-map [$$208, $$205] <- index-search("item", 0, "tpcds", "item", false, false, 1, $$253, 1, $$254, true, true, true)
+                                                                      -- BTREE_SEARCH  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          assign [$$253, $$254] <- [1, 1]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            empty-tuple-source
                                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                          exchange
                                                           -- HASH_PARTITION_EXCHANGE [$$187]  |PARTITIONED|
+                                                            project ([$$130, $$188, $$187])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$188, $$130] <- [true, {"$2": $$146}]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                project ([$$146, $$187])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- SORT_GROUP_BY[$$233, $$234]  |PARTITIONED|
-                                                                            {
+                                                                    group by ([$$183 := $$233; $$187 := $$234]) decor ([]) {
+                                                                              aggregate [$$146] <- [agg-global-sql-avg($$232)]
                                                                               -- AGGREGATE  |LOCAL|
+                                                                                nested tuple source
                                                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                            }
+                                                                           }
+                                                                    -- SORT_GROUP_BY[$$233, $$234]  |PARTITIONED|
+                                                                      exchange
                                                                       -- HASH_PARTITION_EXCHANGE [$$233, $$234]  |PARTITIONED|
-                                                                        -- PRE_CLUSTERED_GROUP_BY[$$181, $$186]  |PARTITIONED|
-                                                                                {
+                                                                        group by ([$$233 := $$181; $$234 := $$186]) decor ([]) {
+                                                                                  aggregate [$$232] <- [agg-local-sql-avg($$128)]
                                                                                   -- AGGREGATE  |LOCAL|
+                                                                                    select (not(is-missing($$182)))
                                                                                     -- STREAM_SELECT  |LOCAL|
+                                                                                      nested tuple source
                                                                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                }
+                                                                               }
+                                                                        -- PRE_CLUSTERED_GROUP_BY[$$181, $$186]  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            order (ASC, $$181) (ASC, $$186)
                                                                             -- STABLE_SORT [$$181(ASC), $$186(ASC)]  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                project ([$$128, $$182, $$181, $$186])
                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    left outer join (eq($$169, $$170))
                                                                                     -- HYBRID_HASH_JOIN [$$170][$$169]  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                        project ([$$186, $$170, $$181])
                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                          assign [$$186, $$170, $$181] <- [$$203, $$204, $$202]
                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                            exchange
                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                              replicate
                                                                                               -- REPLICATE  |PARTITIONED|
+                                                                                                exchange
                                                                                                 -- HASH_PARTITION_EXCHANGE [$$204]  |PARTITIONED|
+                                                                                                  running-aggregate [$$202] <- [create-query-uid()]
                                                                                                   -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                                                                    project ([$$203, $$204])
                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                      assign [$$204] <- [$$205.getField(0)]
                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                        project ([$$203, $$205])
                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                          select (not(or(and($$258, not(is-unknown($$258))))))
                                                                                                           -- STREAM_SELECT  |PARTITIONED|
+                                                                                                            project ([$$203, $$205, $$258])
                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                              assign [$$258] <- [lt(get-item($$206, 0), 25437)]
                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                exchange
                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                  -- PRE_CLUSTERED_GROUP_BY[$$208]  |PARTITIONED|
-                                                                                                                          {
+                                                                                                                  group by ([$$203 := $$208]) decor ([$$205]) {
+                                                                                                                            aggregate [$$206] <- [listify($$214)]
                                                                                                                             -- AGGREGATE  |LOCAL|
+                                                                                                                              aggregate [$$214] <- [agg-sql-count(1)]
                                                                                                                               -- AGGREGATE  |LOCAL|
+                                                                                                                                select (not(is-missing($$210)))
                                                                                                                                 -- STREAM_SELECT  |LOCAL|
+                                                                                                                                  nested tuple source
                                                                                                                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                                          }
+                                                                                                                         }
+                                                                                                                  -- PRE_CLUSTERED_GROUP_BY[$$208]  |PARTITIONED|
+                                                                                                                    exchange
                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                      project ([$$205, $$210, $$208])
                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                        exchange
                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                          left outer join (eq($$209, $$208))
                                                                                                                           -- HYBRID_HASH_JOIN [$$208][$$209]  |PARTITIONED|
+                                                                                                                            exchange
                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                              replicate
                                                                                                                               -- REPLICATE  |PARTITIONED|
+                                                                                                                                exchange
                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                  -- BTREE_SEARCH (tpcds.item.item)  |PARTITIONED|
+                                                                                                                                  unnest-map [$$208, $$205] <- index-search("item", 0, "tpcds", "item", false, false, 1, $$253, 1, $$254, true, true, true)
+                                                                                                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                                                                                                    exchange
                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                      assign [$$253, $$254] <- [1, 1]
                                                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                                                        empty-tuple-source
                                                                                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                            exchange
                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                              project ([$$210, $$209])
                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                assign [$$210, $$209] <- [$$215, $$207]
                                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                                  exchange
                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                    replicate
                                                                                                                                     -- REPLICATE  |PARTITIONED|
+                                                                                                                                      exchange
                                                                                                                                       -- HASH_PARTITION_EXCHANGE [$$207]  |PARTITIONED|
+                                                                                                                                        project ([$$215, $$207])
                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                          assign [$$215, $$207] <- [true, $$216.getField(10)]
                                                                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                                                                            project ([$$216])
                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                              assign [$$216] <- [$$store_sales]
                                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                                exchange
                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                  replicate
                                                                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                                                                    exchange
                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                      project ([$$store_sales])
                                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                        exchange
                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                          -- DATASOURCE_SCAN (tpcds.store_sales)  |PARTITIONED|
+                                                                                                                                                          data-scan []<-[$$142, $$143, $$store_sales] <- tpcds.store_sales
+                                                                                                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                            exchange
                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                              empty-tuple-source
                                                                                                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- HASH_PARTITION_EXCHANGE [$$169]  |PARTITIONED|
+                                                                                        project ([$$128, $$182, $$169])
                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                          assign [$$182, $$128, $$169] <- [true, $$store_sales.getField(22), $$store_sales.getField(10)]
                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                            exchange
                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                              replicate
                                                                                               -- REPLICATE  |PARTITIONED|
+                                                                                                exchange
                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                  project ([$$store_sales])
                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                    exchange
                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                      -- DATASOURCE_SCAN (tpcds.store_sales)  |PARTITIONED|
+                                                                                                      data-scan []<-[$$142, $$143, $$store_sales] <- tpcds.store_sales
+                                                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                        exchange
                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                          empty-tuple-source
                                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                              exchange
                                               -- HASH_PARTITION_EXCHANGE [$$225]  |PARTITIONED|
+                                                project ([$$115, $$226, $$225])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$226, $$115] <- [true, {"$1": $$145}]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$145, $$225])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- SORT_GROUP_BY[$$239, $$240]  |PARTITIONED|
-                                                                {
+                                                        group by ([$$193 := $$239; $$225 := $$240]) decor ([]) {
+                                                                  aggregate [$$145] <- [agg-global-sql-avg($$238)]
                                                                   -- AGGREGATE  |LOCAL|
+                                                                    nested tuple source
                                                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                }
+                                                               }
+                                                        -- SORT_GROUP_BY[$$239, $$240]  |PARTITIONED|
+                                                          exchange
                                                           -- HASH_PARTITION_EXCHANGE [$$239, $$240]  |PARTITIONED|
-                                                            -- PRE_CLUSTERED_GROUP_BY[$$191, $$224]  |PARTITIONED|
-                                                                    {
+                                                            group by ([$$239 := $$191; $$240 := $$224]) decor ([]) {
+                                                                      aggregate [$$238] <- [agg-local-sql-avg($$113)]
                                                                       -- AGGREGATE  |LOCAL|
+                                                                        select (not(is-missing($$192)))
                                                                         -- STREAM_SELECT  |LOCAL|
+                                                                          nested tuple source
                                                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                    }
+                                                                   }
+                                                            -- PRE_CLUSTERED_GROUP_BY[$$191, $$224]  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                order (ASC, $$191) (ASC, $$224)
                                                                 -- STABLE_SORT [$$191(ASC), $$224(ASC)]  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    project ([$$113, $$192, $$191, $$224])
                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        left outer join (eq($$173, $$174))
                                                                         -- HYBRID_HASH_JOIN [$$174][$$173]  |PARTITIONED|
+                                                                          exchange
                                                                           -- HASH_PARTITION_EXCHANGE [$$174]  |PARTITIONED|
+                                                                            running-aggregate [$$191] <- [create-query-uid()]
                                                                             -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                                              project ([$$224, $$174])
                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                assign [$$174] <- [$$196.getField(0)]
                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                  project ([$$224, $$196])
                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                    select (lt(get-item($$147, 0), 25437))
                                                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                        -- PRE_CLUSTERED_GROUP_BY[$$194]  |PARTITIONED|
-                                                                                                {
+                                                                                        group by ([$$224 := $$194]) decor ([$$196]) {
+                                                                                                  aggregate [$$147] <- [listify($$149)]
                                                                                                   -- AGGREGATE  |LOCAL|
+                                                                                                    aggregate [$$149] <- [agg-sql-count(1)]
                                                                                                     -- AGGREGATE  |LOCAL|
+                                                                                                      select (not(is-missing($$190)))
                                                                                                       -- STREAM_SELECT  |LOCAL|
+                                                                                                        nested tuple source
                                                                                                         -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                }
+                                                                                               }
+                                                                                        -- PRE_CLUSTERED_GROUP_BY[$$194]  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                            order (ASC, $$194)
                                                                                             -- STABLE_SORT [$$194(ASC)]  |PARTITIONED|
+                                                                                              exchange
                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                project ([$$196, $$190, $$194])
                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                  exchange
                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                    left outer join (eq($$171, $$194))
                                                                                                     -- HYBRID_HASH_JOIN [$$194][$$171]  |PARTITIONED|
+                                                                                                      exchange
                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                        -- PRE_CLUSTERED_GROUP_BY[$$195]  |PARTITIONED|
-                                                                                                                {
+                                                                                                        group by ([$$194 := $$195]) decor ([$$196]) {
+                                                                                                                  aggregate [] <- []
                                                                                                                   -- AGGREGATE  |LOCAL|
+                                                                                                                    aggregate [] <- []
                                                                                                                     -- AGGREGATE  |LOCAL|
+                                                                                                                      select (not(is-missing($$198)))
                                                                                                                       -- STREAM_SELECT  |LOCAL|
+                                                                                                                        nested tuple source
                                                                                                                         -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                                }
+                                                                                                               }
+                                                                                                        -- PRE_CLUSTERED_GROUP_BY[$$195]  |PARTITIONED|
+                                                                                                          exchange
                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                            project ([$$196, $$198, $$195])
                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                              exchange
                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                left outer join (eq($$195, $$197))
                                                                                                                 -- HYBRID_HASH_JOIN [$$195][$$197]  |PARTITIONED|
+                                                                                                                  exchange
                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                    project ([$$195, $$196])
                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                      assign [$$195, $$196] <- [$$208, $$205]
                                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                                        exchange
                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                          replicate
                                                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                                                            exchange
                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                              -- BTREE_SEARCH (tpcds.item.item)  |PARTITIONED|
+                                                                                                                              unnest-map [$$208, $$205] <- index-search("item", 0, "tpcds", "item", false, false, 1, $$253, 1, $$254, true, true, true)
+                                                                                                                              -- BTREE_SEARCH  |PARTITIONED|
+                                                                                                                                exchange
                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                  assign [$$253, $$254] <- [1, 1]
                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                    empty-tuple-source
                                                                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                  exchange
                                                                                                                   -- HASH_PARTITION_EXCHANGE [$$197]  |PARTITIONED|
+                                                                                                                    assign [$$198] <- [true]
                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                      project ([$$197])
                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                        exchange
                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                          -- SORT_GROUP_BY[$$236, $$237]  |PARTITIONED|
-                                                                                                                                  {
+                                                                                                                          group by ([$$201 := $$236; $$197 := $$237]) decor ([]) {
+                                                                                                                                    aggregate [] <- []
                                                                                                                                     -- AGGREGATE  |LOCAL|
+                                                                                                                                      nested tuple source
                                                                                                                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                                                  }
+                                                                                                                                 }
+                                                                                                                          -- SORT_GROUP_BY[$$236, $$237]  |PARTITIONED|
+                                                                                                                            exchange
                                                                                                                             -- HASH_PARTITION_EXCHANGE [$$236, $$237]  |PARTITIONED|
-                                                                                                                              -- PRE_CLUSTERED_GROUP_BY[$$202, $$203]  |PARTITIONED|
-                                                                                                                                      {
+                                                                                                                              group by ([$$236 := $$202; $$237 := $$203]) decor ([]) {
+                                                                                                                                        aggregate [] <- []
                                                                                                                                         -- AGGREGATE  |LOCAL|
+                                                                                                                                          select (not(is-missing($$215)))
                                                                                                                                           -- STREAM_SELECT  |LOCAL|
+                                                                                                                                            nested tuple source
                                                                                                                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                                                      }
+                                                                                                                                     }
+                                                                                                                              -- PRE_CLUSTERED_GROUP_BY[$$202, $$203]  |PARTITIONED|
+                                                                                                                                exchange
                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                  order (ASC, $$202) (ASC, $$203)
                                                                                                                                   -- STABLE_SORT [$$202(ASC), $$203(ASC)]  |PARTITIONED|
+                                                                                                                                    exchange
                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                      project ([$$215, $$202, $$203])
                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                        exchange
                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                          left outer join (eq($$207, $$204))
                                                                                                                                           -- HYBRID_HASH_JOIN [$$204][$$207]  |PARTITIONED|
+                                                                                                                                            exchange
                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                              replicate
                                                                                                                                               -- REPLICATE  |PARTITIONED|
+                                                                                                                                                exchange
                                                                                                                                                 -- HASH_PARTITION_EXCHANGE [$$204]  |PARTITIONED|
+                                                                                                                                                  running-aggregate [$$202] <- [create-query-uid()]
                                                                                                                                                   -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                                                                                                                    project ([$$203, $$204])
                                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                      assign [$$204] <- [$$205.getField(0)]
                                                                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                                                                        project ([$$203, $$205])
                                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                          select (not(or(and($$258, not(is-unknown($$258))))))
                                                                                                                                                           -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                            project ([$$203, $$205, $$258])
                                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                              assign [$$258] <- [lt(get-item($$206, 0), 25437)]
                                                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                exchange
                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                  -- PRE_CLUSTERED_GROUP_BY[$$208]  |PARTITIONED|
-                                                                                                                                                                          {
+                                                                                                                                                                  group by ([$$203 := $$208]) decor ([$$205]) {
+                                                                                                                                                                            aggregate [$$206] <- [listify($$214)]
                                                                                                                                                                             -- AGGREGATE  |LOCAL|
+                                                                                                                                                                              aggregate [$$214] <- [agg-sql-count(1)]
                                                                                                                                                                               -- AGGREGATE  |LOCAL|
+                                                                                                                                                                                select (not(is-missing($$210)))
                                                                                                                                                                                 -- STREAM_SELECT  |LOCAL|
+                                                                                                                                                                                  nested tuple source
                                                                                                                                                                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                                                                                          }
+                                                                                                                                                                         }
+                                                                                                                                                                  -- PRE_CLUSTERED_GROUP_BY[$$208]  |PARTITIONED|
+                                                                                                                                                                    exchange
                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                      project ([$$205, $$210, $$208])
                                                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                        exchange
                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                          left outer join (eq($$209, $$208))
                                                                                                                                                                           -- HYBRID_HASH_JOIN [$$208][$$209]  |PARTITIONED|
+                                                                                                                                                                            exchange
                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                              replicate
                                                                                                                                                                               -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                exchange
                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                  -- BTREE_SEARCH (tpcds.item.item)  |PARTITIONED|
+                                                                                                                                                                                  unnest-map [$$208, $$205] <- index-search("item", 0, "tpcds", "item", false, false, 1, $$253, 1, $$254, true, true, true)
+                                                                                                                                                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                                                                                                                                                    exchange
                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                      assign [$$253, $$254] <- [1, 1]
                                                                                                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                        empty-tuple-source
                                                                                                                                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                            exchange
                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                              project ([$$210, $$209])
                                                                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                assign [$$210, $$209] <- [$$215, $$207]
                                                                                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                  exchange
                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                    replicate
                                                                                                                                                                                     -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                      exchange
                                                                                                                                                                                       -- HASH_PARTITION_EXCHANGE [$$207]  |PARTITIONED|
+                                                                                                                                                                                        project ([$$215, $$207])
                                                                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                          assign [$$215, $$207] <- [true, $$216.getField(10)]
                                                                                                                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                            project ([$$216])
                                                                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                              assign [$$216] <- [$$store_sales]
                                                                                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                exchange
                                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                  replicate
                                                                                                                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                    exchange
                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                      project ([$$store_sales])
                                                                                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                        exchange
                                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                          -- DATASOURCE_SCAN (tpcds.store_sales)  |PARTITIONED|
+                                                                                                                                                                                                          data-scan []<-[$$142, $$143, $$store_sales] <- tpcds.store_sales
+                                                                                                                                                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                            exchange
                                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                              empty-tuple-source
                                                                                                                                                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                            exchange
                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                              replicate
                                                                                                                                               -- REPLICATE  |PARTITIONED|
+                                                                                                                                                exchange
                                                                                                                                                 -- HASH_PARTITION_EXCHANGE [$$207]  |PARTITIONED|
+                                                                                                                                                  project ([$$215, $$207])
                                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                    assign [$$215, $$207] <- [true, $$216.getField(10)]
                                                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                                                      project ([$$216])
                                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                        assign [$$216] <- [$$store_sales]
                                                                                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                                                                                          exchange
                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                            replicate
                                                                                                                                                             -- REPLICATE  |PARTITIONED|
+                                                                                                                                                              exchange
                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                project ([$$store_sales])
                                                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                  exchange
                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                    -- DATASOURCE_SCAN (tpcds.store_sales)  |PARTITIONED|
+                                                                                                                                                                    data-scan []<-[$$142, $$143, $$store_sales] <- tpcds.store_sales
+                                                                                                                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                      exchange
                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                        empty-tuple-source
                                                                                                                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                      exchange
                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                        project ([$$190, $$171])
                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                          assign [$$190, $$171] <- [$$215, $$207]
                                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                                            exchange
                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                              replicate
                                                                                                               -- REPLICATE  |PARTITIONED|
+                                                                                                                exchange
                                                                                                                 -- HASH_PARTITION_EXCHANGE [$$207]  |PARTITIONED|
+                                                                                                                  project ([$$215, $$207])
                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                    assign [$$215, $$207] <- [true, $$216.getField(10)]
                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                      project ([$$216])
                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                        assign [$$216] <- [$$store_sales]
                                                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                                                          exchange
                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                            replicate
                                                                                                                             -- REPLICATE  |PARTITIONED|
+                                                                                                                              exchange
                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                project ([$$store_sales])
                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                  exchange
                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                    -- DATASOURCE_SCAN (tpcds.store_sales)  |PARTITIONED|
+                                                                                                                                    data-scan []<-[$$142, $$143, $$store_sales] <- tpcds.store_sales
+                                                                                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                      exchange
                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                        empty-tuple-source
                                                                                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                          exchange
                                                                           -- HASH_PARTITION_EXCHANGE [$$173]  |PARTITIONED|
+                                                                            project ([$$113, $$192, $$173])
                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                              assign [$$192, $$113, $$173] <- [true, $$store_sales.getField(14), $$store_sales.getField(10)]
                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                project ([$$store_sales])
                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                  assign [$$store_sales] <- [$$store_sales]
                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                    exchange
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                      replicate
                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                        exchange
                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                          project ([$$store_sales])
                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                            exchange
                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                              -- DATASOURCE_SCAN (tpcds.store_sales)  |PARTITIONED|
+                                                                                              data-scan []<-[$$142, $$143, $$store_sales] <- tpcds.store_sales
+                                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                exchange
                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                  empty-tuple-source
                                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$228, $$175])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  assign [$$228, $$175] <- [$$215, $$207]
                                   -- ASSIGN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      replicate
                                       -- REPLICATE  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$207]  |PARTITIONED|
+                                          project ([$$215, $$207])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            assign [$$215, $$207] <- [true, $$216.getField(10)]
                                             -- ASSIGN  |PARTITIONED|
+                                              project ([$$216])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$216] <- [$$store_sales]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    replicate
                                                     -- REPLICATE  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        project ([$$store_sales])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- DATASOURCE_SCAN (tpcds.store_sales)  |PARTITIONED|
+                                                            data-scan []<-[$$142, $$143, $$store_sales] <- tpcds.store_sales
+                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                empty-tuple-source
                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1581-correlated.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1581-correlated.plan
index d61947a..1f6a79e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1581-correlated.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1581-correlated.plan
@@ -1,343 +1,647 @@
+distribute result [$$136]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$136])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$136] <- [{"bucket1": $$134}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$134])
         -- STREAM_PROJECT  |PARTITIONED|
+          unnest $$134 <- scan-collection($$133)
           -- UNNEST  |PARTITIONED|
+            project ([$$133])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$133] <- [switch-case(true, lt(get-item($$100, 0), 25437), cast($$117), cast($$132))]
               -- ASSIGN  |PARTITIONED|
+                project ([$$132, $$100, $$117])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- PRE_CLUSTERED_GROUP_BY[$$173]  |PARTITIONED|
-                            {
+                    group by ([$$217 := $$173]) decor ([$$100; $$117]) {
+                              aggregate [$$132] <- [listify($$131)]
                               -- AGGREGATE  |LOCAL|
+                                aggregate [$$131] <- [listify($$130)]
                                 -- AGGREGATE  |LOCAL|
+                                  select (not(is-missing($$216)))
                                   -- STREAM_SELECT  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                            }
+                           }
+                    -- PRE_CLUSTERED_GROUP_BY[$$173]  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$100, $$117, $$130, $$216, $$173])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            left outer join (eq($$173, $$215))
                             -- HYBRID_HASH_JOIN [$$173][$$215]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- PRE_CLUSTERED_GROUP_BY[$$157]  |PARTITIONED|
-                                        {
+                                group by ([$$173 := $$157]) decor ([$$100]) {
+                                          aggregate [$$117] <- [listify($$116)]
                                           -- AGGREGATE  |LOCAL|
+                                            aggregate [$$116] <- [listify($$115)]
                                             -- AGGREGATE  |LOCAL|
+                                              select (not(is-missing($$172)))
                                               -- STREAM_SELECT  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- PRE_CLUSTERED_GROUP_BY[$$157]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    order (ASC, $$157)
                                     -- STABLE_SORT [$$157(ASC)]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$100, $$115, $$172, $$157])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            left outer join (eq($$157, $$171))
                                             -- HYBRID_HASH_JOIN [$$157][$$171]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- PRE_CLUSTERED_GROUP_BY[$$137]  |PARTITIONED|
-                                                        {
+                                                group by ([$$157 := $$137]) decor ([]) {
+                                                          aggregate [$$100] <- [listify($$144)]
                                                           -- AGGREGATE  |LOCAL|
+                                                            aggregate [$$144] <- [agg-sql-count(1)]
                                                             -- AGGREGATE  |LOCAL|
+                                                              select (not(is-missing($$156)))
                                                               -- STREAM_SELECT  |LOCAL|
+                                                                nested tuple source
                                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                        }
+                                                       }
+                                                -- PRE_CLUSTERED_GROUP_BY[$$137]  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$$156, $$137])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        left outer join (eq($$147, $$137))
                                                         -- HYBRID_HASH_JOIN [$$137][$$147]  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            project ([$$137])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$137, $$item] <- [$$199, $$197]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  replicate
                                                                   -- REPLICATE  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- BTREE_SEARCH (tpcds.item.item)  |PARTITIONED|
+                                                                      unnest-map [$$199, $$197] <- index-search("item", 0, "tpcds", "item", false, false, 1, $$240, 1, $$241, true, true, true)
+                                                                      -- BTREE_SEARCH  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          assign [$$240, $$241] <- [1, 1]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            empty-tuple-source
                                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            project ([$$156, $$147])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$156, $$147] <- [$$206, $$198]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  replicate
                                                                   -- REPLICATE  |PARTITIONED|
+                                                                    exchange
                                                                     -- HASH_PARTITION_EXCHANGE [$$198]  |PARTITIONED|
+                                                                      project ([$$206, $$198])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        assign [$$206, $$198] <- [true, $$207.getField(10)]
                                                                         -- ASSIGN  |PARTITIONED|
+                                                                          project ([$$207])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            assign [$$207] <- [$$store_sales]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                replicate
                                                                                 -- REPLICATE  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    project ([$$store_sales])
                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                        -- DATASOURCE_SCAN (tpcds.store_sales)  |PARTITIONED|
+                                                                                        data-scan []<-[$$140, $$141, $$store_sales] <- tpcds.store_sales
+                                                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                            empty-tuple-source
                                                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                              exchange
                                               -- HASH_PARTITION_EXCHANGE [$$171]  |PARTITIONED|
+                                                project ([$$115, $$172, $$171])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$172, $$115] <- [true, {"$1": $$145}]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$145, $$171])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- SORT_GROUP_BY[$$220, $$221]  |PARTITIONED|
-                                                                {
+                                                        group by ([$$160 := $$220; $$171 := $$221]) decor ([]) {
+                                                                  aggregate [$$145] <- [agg-global-sql-avg($$219)]
                                                                   -- AGGREGATE  |LOCAL|
+                                                                    nested tuple source
                                                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                }
+                                                               }
+                                                        -- SORT_GROUP_BY[$$220, $$221]  |PARTITIONED|
+                                                          exchange
                                                           -- HASH_PARTITION_EXCHANGE [$$220, $$221]  |PARTITIONED|
-                                                            -- PRE_CLUSTERED_GROUP_BY[$$158, $$161]  |PARTITIONED|
-                                                                    {
+                                                            group by ([$$220 := $$158; $$221 := $$161]) decor ([]) {
+                                                                      aggregate [$$219] <- [agg-local-sql-avg($$113)]
                                                                       -- AGGREGATE  |LOCAL|
+                                                                        select (not(is-missing($$159)))
                                                                         -- STREAM_SELECT  |LOCAL|
+                                                                          nested tuple source
                                                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                    }
+                                                                   }
+                                                            -- PRE_CLUSTERED_GROUP_BY[$$158, $$161]  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                order (ASC, $$158) (ASC, $$161)
                                                                 -- STABLE_SORT [$$158(ASC), $$161(ASC)]  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    project ([$$113, $$159, $$158, $$161])
                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        left outer join (eq($$149, $$150))
                                                                         -- HYBRID_HASH_JOIN [$$150][$$149]  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            project ([$$161, $$150, $$158])
                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                              assign [$$161, $$150, $$158] <- [$$194, $$196, $$193]
                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  replicate
                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                    exchange
                                                                                     -- HASH_PARTITION_EXCHANGE [$$196]  |PARTITIONED|
+                                                                                      running-aggregate [$$193] <- [create-query-uid()]
                                                                                       -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                                                        project ([$$194, $$196])
                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                          assign [$$196] <- [$$197.getField(0)]
                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                            project ([$$194, $$197])
                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                              select (lt(get-item($$195, 0), 25437))
                                                                                               -- STREAM_SELECT  |PARTITIONED|
+                                                                                                exchange
                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                  replicate
                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                    exchange
                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                      -- PRE_CLUSTERED_GROUP_BY[$$199]  |PARTITIONED|
-                                                                                                              {
+                                                                                                      group by ([$$194 := $$199]) decor ([$$197]) {
+                                                                                                                aggregate [$$195] <- [listify($$205)]
                                                                                                                 -- AGGREGATE  |LOCAL|
+                                                                                                                  aggregate [$$205] <- [agg-sql-count(1)]
                                                                                                                   -- AGGREGATE  |LOCAL|
+                                                                                                                    select (not(is-missing($$201)))
                                                                                                                     -- STREAM_SELECT  |LOCAL|
+                                                                                                                      nested tuple source
                                                                                                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                              }
+                                                                                                             }
+                                                                                                      -- PRE_CLUSTERED_GROUP_BY[$$199]  |PARTITIONED|
+                                                                                                        exchange
                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                          project ([$$197, $$201, $$199])
                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                            exchange
                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                              left outer join (eq($$200, $$199))
                                                                                                               -- HYBRID_HASH_JOIN [$$199][$$200]  |PARTITIONED|
+                                                                                                                exchange
                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                  replicate
                                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                                    exchange
                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                      -- BTREE_SEARCH (tpcds.item.item)  |PARTITIONED|
+                                                                                                                      unnest-map [$$199, $$197] <- index-search("item", 0, "tpcds", "item", false, false, 1, $$240, 1, $$241, true, true, true)
+                                                                                                                      -- BTREE_SEARCH  |PARTITIONED|
+                                                                                                                        exchange
                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                          assign [$$240, $$241] <- [1, 1]
                                                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                                                            empty-tuple-source
                                                                                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                exchange
                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                  project ([$$201, $$200])
                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                    assign [$$201, $$200] <- [$$206, $$198]
                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                      exchange
                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                        replicate
                                                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                                                          exchange
                                                                                                                           -- HASH_PARTITION_EXCHANGE [$$198]  |PARTITIONED|
+                                                                                                                            project ([$$206, $$198])
                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                              assign [$$206, $$198] <- [true, $$207.getField(10)]
                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                project ([$$207])
                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                  assign [$$207] <- [$$store_sales]
                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                    exchange
                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                      replicate
                                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                                        exchange
                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                          project ([$$store_sales])
                                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                            exchange
                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                              -- DATASOURCE_SCAN (tpcds.store_sales)  |PARTITIONED|
+                                                                                                                                              data-scan []<-[$$140, $$141, $$store_sales] <- tpcds.store_sales
+                                                                                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                exchange
                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                  empty-tuple-source
                                                                                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                          exchange
                                                                           -- HASH_PARTITION_EXCHANGE [$$149]  |PARTITIONED|
+                                                                            project ([$$113, $$159, $$149])
                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                              assign [$$159, $$113, $$149] <- [true, $$store_sales.getField(14), $$store_sales.getField(10)]
                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  replicate
                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                    exchange
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                      project ([$$store_sales])
                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                        exchange
                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                          -- DATASOURCE_SCAN (tpcds.store_sales)  |PARTITIONED|
+                                                                                          data-scan []<-[$$140, $$141, $$store_sales] <- tpcds.store_sales
+                                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                            exchange
                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                              empty-tuple-source
                                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$215]  |PARTITIONED|
+                                project ([$$130, $$216, $$215])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  assign [$$216, $$130] <- [true, {"$2": $$146}]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$146, $$215])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- SORT_GROUP_BY[$$226, $$227]  |PARTITIONED|
-                                                {
+                                        group by ([$$176 := $$226; $$215 := $$227]) decor ([]) {
+                                                  aggregate [$$146] <- [agg-global-sql-avg($$225)]
                                                   -- AGGREGATE  |LOCAL|
+                                                    nested tuple source
                                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                }
+                                               }
+                                        -- SORT_GROUP_BY[$$226, $$227]  |PARTITIONED|
+                                          exchange
                                           -- HASH_PARTITION_EXCHANGE [$$226, $$227]  |PARTITIONED|
-                                            -- PRE_CLUSTERED_GROUP_BY[$$174, $$177]  |PARTITIONED|
-                                                    {
+                                            group by ([$$226 := $$174; $$227 := $$177]) decor ([]) {
+                                                      aggregate [$$225] <- [agg-local-sql-avg($$128)]
                                                       -- AGGREGATE  |LOCAL|
+                                                        select (not(is-missing($$175)))
                                                         -- STREAM_SELECT  |LOCAL|
+                                                          nested tuple source
                                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                    }
+                                                   }
+                                            -- PRE_CLUSTERED_GROUP_BY[$$174, $$177]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                order (ASC, $$174) (ASC, $$177)
                                                 -- STABLE_SORT [$$174(ASC), $$177(ASC)]  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    project ([$$128, $$175, $$174, $$177])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        left outer join (eq($$151, $$152))
                                                         -- HYBRID_HASH_JOIN [$$152][$$151]  |PARTITIONED|
+                                                          exchange
                                                           -- HASH_PARTITION_EXCHANGE [$$152]  |PARTITIONED|
+                                                            running-aggregate [$$174] <- [create-query-uid()]
                                                             -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                              project ([$$177, $$152])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$152] <- [$$180.getField(0)]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  project ([$$177, $$180])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    select (not(or(and($$244, not(is-unknown($$244))))))
                                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                                      project ([$$177, $$180, $$244])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        assign [$$244] <- [lt(get-item($$179, 0), 25437)]
                                                                         -- ASSIGN  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                            -- PRE_CLUSTERED_GROUP_BY[$$178]  |PARTITIONED|
-                                                                                    {
+                                                                            group by ([$$177 := $$178]) decor ([$$179; $$180]) {
+                                                                                      aggregate [] <- []
                                                                                       -- AGGREGATE  |LOCAL|
+                                                                                        aggregate [] <- []
                                                                                         -- AGGREGATE  |LOCAL|
+                                                                                          select (not(is-missing($$189)))
                                                                                           -- STREAM_SELECT  |LOCAL|
+                                                                                            nested tuple source
                                                                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                    }
+                                                                                   }
+                                                                            -- PRE_CLUSTERED_GROUP_BY[$$178]  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                order (ASC, $$178)
                                                                                 -- STABLE_SORT [$$178(ASC)]  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    project ([$$180, $$179, $$189, $$178])
                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                        left outer join (eq($$178, $$181))
                                                                                         -- HYBRID_HASH_JOIN [$$178][$$181]  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                            project ([$$179, $$178, $$180])
                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                              assign [$$179, $$178, $$180] <- [$$195, $$194, $$197]
                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                exchange
                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                  replicate
                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                    exchange
                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                      -- PRE_CLUSTERED_GROUP_BY[$$199]  |PARTITIONED|
-                                                                                                              {
+                                                                                                      group by ([$$194 := $$199]) decor ([$$197]) {
+                                                                                                                aggregate [$$195] <- [listify($$205)]
                                                                                                                 -- AGGREGATE  |LOCAL|
+                                                                                                                  aggregate [$$205] <- [agg-sql-count(1)]
                                                                                                                   -- AGGREGATE  |LOCAL|
+                                                                                                                    select (not(is-missing($$201)))
                                                                                                                     -- STREAM_SELECT  |LOCAL|
+                                                                                                                      nested tuple source
                                                                                                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                              }
+                                                                                                             }
+                                                                                                      -- PRE_CLUSTERED_GROUP_BY[$$199]  |PARTITIONED|
+                                                                                                        exchange
                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                          project ([$$197, $$201, $$199])
                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                            exchange
                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                              left outer join (eq($$200, $$199))
                                                                                                               -- HYBRID_HASH_JOIN [$$199][$$200]  |PARTITIONED|
+                                                                                                                exchange
                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                  replicate
                                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                                    exchange
                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                      -- BTREE_SEARCH (tpcds.item.item)  |PARTITIONED|
+                                                                                                                      unnest-map [$$199, $$197] <- index-search("item", 0, "tpcds", "item", false, false, 1, $$240, 1, $$241, true, true, true)
+                                                                                                                      -- BTREE_SEARCH  |PARTITIONED|
+                                                                                                                        exchange
                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                          assign [$$240, $$241] <- [1, 1]
                                                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                                                            empty-tuple-source
                                                                                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                exchange
                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                  project ([$$201, $$200])
                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                    assign [$$201, $$200] <- [$$206, $$198]
                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                      exchange
                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                        replicate
                                                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                                                          exchange
                                                                                                                           -- HASH_PARTITION_EXCHANGE [$$198]  |PARTITIONED|
+                                                                                                                            project ([$$206, $$198])
                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                              assign [$$206, $$198] <- [true, $$207.getField(10)]
                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                project ([$$207])
                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                  assign [$$207] <- [$$store_sales]
                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                    exchange
                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                      replicate
                                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                                        exchange
                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                          project ([$$store_sales])
                                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                            exchange
                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                              -- DATASOURCE_SCAN (tpcds.store_sales)  |PARTITIONED|
+                                                                                                                                              data-scan []<-[$$140, $$141, $$store_sales] <- tpcds.store_sales
+                                                                                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                exchange
                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                  empty-tuple-source
                                                                                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- HASH_PARTITION_EXCHANGE [$$181]  |PARTITIONED|
+                                                                                            assign [$$189] <- [true]
                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                              project ([$$181])
                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                exchange
                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                  -- SORT_GROUP_BY[$$223, $$224]  |PARTITIONED|
-                                                                                                          {
+                                                                                                  group by ([$$192 := $$223; $$181 := $$224]) decor ([]) {
+                                                                                                            aggregate [] <- []
                                                                                                             -- AGGREGATE  |LOCAL|
+                                                                                                              nested tuple source
                                                                                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                          }
+                                                                                                         }
+                                                                                                  -- SORT_GROUP_BY[$$223, $$224]  |PARTITIONED|
+                                                                                                    exchange
                                                                                                     -- HASH_PARTITION_EXCHANGE [$$223, $$224]  |PARTITIONED|
-                                                                                                      -- PRE_CLUSTERED_GROUP_BY[$$193, $$194]  |PARTITIONED|
-                                                                                                              {
+                                                                                                      group by ([$$223 := $$193; $$224 := $$194]) decor ([]) {
+                                                                                                                aggregate [] <- []
                                                                                                                 -- AGGREGATE  |LOCAL|
+                                                                                                                  select (not(is-missing($$206)))
                                                                                                                   -- STREAM_SELECT  |LOCAL|
+                                                                                                                    nested tuple source
                                                                                                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                              }
+                                                                                                             }
+                                                                                                      -- PRE_CLUSTERED_GROUP_BY[$$193, $$194]  |PARTITIONED|
+                                                                                                        exchange
                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                          order (ASC, $$193) (ASC, $$194)
                                                                                                           -- STABLE_SORT [$$193(ASC), $$194(ASC)]  |PARTITIONED|
+                                                                                                            exchange
                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                              project ([$$206, $$193, $$194])
                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                exchange
                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                  left outer join (eq($$198, $$196))
                                                                                                                   -- HYBRID_HASH_JOIN [$$196][$$198]  |PARTITIONED|
+                                                                                                                    exchange
                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                      replicate
                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                        exchange
                                                                                                                         -- HASH_PARTITION_EXCHANGE [$$196]  |PARTITIONED|
+                                                                                                                          running-aggregate [$$193] <- [create-query-uid()]
                                                                                                                           -- RUNNING_AGGREGATE  |PARTITIONED|
+                                                                                                                            project ([$$194, $$196])
                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                              assign [$$196] <- [$$197.getField(0)]
                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                project ([$$194, $$197])
                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                  select (lt(get-item($$195, 0), 25437))
                                                                                                                                   -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                    exchange
                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                      replicate
                                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                                        exchange
                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                          -- PRE_CLUSTERED_GROUP_BY[$$199]  |PARTITIONED|
-                                                                                                                                                  {
+                                                                                                                                          group by ([$$194 := $$199]) decor ([$$197]) {
+                                                                                                                                                    aggregate [$$195] <- [listify($$205)]
                                                                                                                                                     -- AGGREGATE  |LOCAL|
+                                                                                                                                                      aggregate [$$205] <- [agg-sql-count(1)]
                                                                                                                                                       -- AGGREGATE  |LOCAL|
+                                                                                                                                                        select (not(is-missing($$201)))
                                                                                                                                                         -- STREAM_SELECT  |LOCAL|
+                                                                                                                                                          nested tuple source
                                                                                                                                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                                                                  }
+                                                                                                                                                 }
+                                                                                                                                          -- PRE_CLUSTERED_GROUP_BY[$$199]  |PARTITIONED|
+                                                                                                                                            exchange
                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                              project ([$$197, $$201, $$199])
                                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                exchange
                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                  left outer join (eq($$200, $$199))
                                                                                                                                                   -- HYBRID_HASH_JOIN [$$199][$$200]  |PARTITIONED|
+                                                                                                                                                    exchange
                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                      replicate
                                                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                                                        exchange
                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                          -- BTREE_SEARCH (tpcds.item.item)  |PARTITIONED|
+                                                                                                                                                          unnest-map [$$199, $$197] <- index-search("item", 0, "tpcds", "item", false, false, 1, $$240, 1, $$241, true, true, true)
+                                                                                                                                                          -- BTREE_SEARCH  |PARTITIONED|
+                                                                                                                                                            exchange
                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                              assign [$$240, $$241] <- [1, 1]
                                                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                empty-tuple-source
                                                                                                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                    exchange
                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                      project ([$$201, $$200])
                                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                        assign [$$201, $$200] <- [$$206, $$198]
                                                                                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                                                                                          exchange
                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                            replicate
                                                                                                                                                             -- REPLICATE  |PARTITIONED|
+                                                                                                                                                              exchange
                                                                                                                                                               -- HASH_PARTITION_EXCHANGE [$$198]  |PARTITIONED|
+                                                                                                                                                                project ([$$206, $$198])
                                                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                  assign [$$206, $$198] <- [true, $$207.getField(10)]
                                                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                    project ([$$207])
                                                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                      assign [$$207] <- [$$store_sales]
                                                                                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                        exchange
                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                          replicate
                                                                                                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                            exchange
                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                              project ([$$store_sales])
                                                                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                exchange
                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                  -- DATASOURCE_SCAN (tpcds.store_sales)  |PARTITIONED|
+                                                                                                                                                                                  data-scan []<-[$$140, $$141, $$store_sales] <- tpcds.store_sales
+                                                                                                                                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                    exchange
                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                      empty-tuple-source
                                                                                                                                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                    exchange
                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                      replicate
                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                        exchange
                                                                                                                         -- HASH_PARTITION_EXCHANGE [$$198]  |PARTITIONED|
+                                                                                                                          project ([$$206, $$198])
                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                            assign [$$206, $$198] <- [true, $$207.getField(10)]
                                                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                                                              project ([$$207])
                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                assign [$$207] <- [$$store_sales]
                                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                                  exchange
                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                    replicate
                                                                                                                                     -- REPLICATE  |PARTITIONED|
+                                                                                                                                      exchange
                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                        project ([$$store_sales])
                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                          exchange
                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                            -- DATASOURCE_SCAN (tpcds.store_sales)  |PARTITIONED|
+                                                                                                                                            data-scan []<-[$$140, $$141, $$store_sales] <- tpcds.store_sales
+                                                                                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                              exchange
                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                empty-tuple-source
                                                                                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                          exchange
                                                           -- HASH_PARTITION_EXCHANGE [$$151]  |PARTITIONED|
+                                                            project ([$$128, $$175, $$151])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$175, $$128, $$151] <- [true, $$store_sales.getField(22), $$store_sales.getField(10)]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                project ([$$store_sales])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  assign [$$store_sales] <- [$$store_sales]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      replicate
                                                                       -- REPLICATE  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          project ([$$store_sales])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                              -- DATASOURCE_SCAN (tpcds.store_sales)  |PARTITIONED|
+                                                                              data-scan []<-[$$140, $$141, $$store_sales] <- tpcds.store_sales
+                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  empty-tuple-source
                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1581.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1581.plan
index 728c15a..94d5f44 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1581.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1581.plan
@@ -1,204 +1,399 @@
+distribute result [$$142]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    join (true)
     -- NESTED_LOOP  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- BTREE_SEARCH (tpcds.item.item)  |PARTITIONED|
+            unnest-map [$$146, $$item] <- index-search("item", 0, "tpcds", "item", false, false, 1, $$201, 1, $$202, true, true, true)
+            -- BTREE_SEARCH  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                assign [$$201, $$202] <- [1, 1]
                 -- ASSIGN  |PARTITIONED|
+                  empty-tuple-source
                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+      exchange
       -- BROADCAST_EXCHANGE  |LOCAL|
+        project ([$$142])
         -- STREAM_PROJECT  |LOCAL|
+          assign [$$142] <- [{"bucket1": $$140}]
           -- ASSIGN  |LOCAL|
+            project ([$$140])
             -- STREAM_PROJECT  |LOCAL|
+              unnest $$140 <- scan-collection($$139)
               -- UNNEST  |LOCAL|
+                project ([$$139])
                 -- STREAM_PROJECT  |LOCAL|
+                  assign [$$139] <- [switch-case(true, lt(get-item($$193, 0), 25437), cast($$121), cast($$138))]
                   -- ASSIGN  |LOCAL|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-                      -- PRE_CLUSTERED_GROUP_BY[$$166]  |LOCAL|
-                              {
+                      group by ([$$193 := $$166]) decor ([$$121]) {
+                                aggregate [$$138] <- [listify($$137)]
                                 -- AGGREGATE  |LOCAL|
+                                  aggregate [$$137] <- [listify($$136)]
                                   -- AGGREGATE  |LOCAL|
+                                    select (not(is-missing($$192)))
                                     -- STREAM_SELECT  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- PRE_CLUSTERED_GROUP_BY[$$166]  |LOCAL|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                          project ([$$121, $$136, $$192, $$166])
                           -- STREAM_PROJECT  |LOCAL|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                              left outer join (eq($$166, $$167))
                               -- HYBRID_HASH_JOIN [$$166][$$167]  |LOCAL|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-                                  -- PRE_CLUSTERED_GROUP_BY[$$102]  |LOCAL|
-                                          {
+                                  group by ([$$166 := $$102]) decor ([]) {
+                                            aggregate [$$121] <- [listify($$120)]
                                             -- AGGREGATE  |LOCAL|
+                                              aggregate [$$120] <- [listify($$119)]
                                               -- AGGREGATE  |LOCAL|
+                                                select (not(is-missing($$165)))
                                                 -- STREAM_SELECT  |LOCAL|
+                                                  nested tuple source
                                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                         }
+                                  -- PRE_CLUSTERED_GROUP_BY[$$102]  |LOCAL|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                                      order (ASC, $$102)
                                       -- STABLE_SORT [$$102(ASC)]  |LOCAL|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                          project ([$$119, $$165, $$102])
                                           -- STREAM_PROJECT  |UNPARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                              left outer join (eq($$102, $$159))
                                               -- HYBRID_HASH_JOIN [$$102][$$159]  |UNPARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                  project ([$$102])
                                                   -- STREAM_PROJECT  |UNPARTITIONED|
+                                                    assign [$$102] <- [$$168]
                                                     -- ASSIGN  |UNPARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                        replicate
                                                         -- REPLICATE  |UNPARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                            project ([$$168])
                                                             -- STREAM_PROJECT  |UNPARTITIONED|
+                                                              assign [$$168] <- [$$169]
                                                               -- ASSIGN  |UNPARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                                  replicate
                                                                   -- REPLICATE  |UNPARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                                      aggregate [$$169] <- [listify($$176)]
                                                                       -- AGGREGATE  |UNPARTITIONED|
+                                                                        aggregate [$$176] <- [agg-sql-sum($$199)]
                                                                         -- AGGREGATE  |UNPARTITIONED|
+                                                                          exchange
                                                                           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                                                                            aggregate [$$199] <- [agg-sql-count(1)]
                                                                             -- AGGREGATE  |PARTITIONED|
+                                                                              select (and(ge($$178, 1), le($$178, 20)))
                                                                               -- STREAM_SELECT  |PARTITIONED|
+                                                                                project ([$$178])
                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                  assign [$$178] <- [$$177.getField(10)]
                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                    exchange
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                      replicate
                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                        exchange
                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                          project ([$$177])
                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                            exchange
                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                              -- DATASOURCE_SCAN (tpcds.store_sales)  |PARTITIONED|
+                                                                                              data-scan []<-[$$179, $$180, $$177] <- tpcds.store_sales
+                                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                exchange
                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                  empty-tuple-source
                                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                  join (true)
                                                   -- NESTED_LOOP  |UNPARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                      project ([$$159, $$165])
                                                       -- STREAM_PROJECT  |UNPARTITIONED|
+                                                        assign [$$159, $$165] <- [$$169, $$175]
                                                         -- ASSIGN  |UNPARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                            replicate
                                                             -- REPLICATE  |UNPARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                                assign [$$175] <- [true]
                                                                 -- ASSIGN  |UNPARTITIONED|
+                                                                  select (lt(get-item($$169, 0), 25437))
                                                                   -- STREAM_SELECT  |UNPARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                                      replicate
                                                                       -- REPLICATE  |UNPARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                                          aggregate [$$169] <- [listify($$176)]
                                                                           -- AGGREGATE  |UNPARTITIONED|
+                                                                            aggregate [$$176] <- [agg-sql-sum($$199)]
                                                                             -- AGGREGATE  |UNPARTITIONED|
+                                                                              exchange
                                                                               -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                                                                                aggregate [$$199] <- [agg-sql-count(1)]
                                                                                 -- AGGREGATE  |PARTITIONED|
+                                                                                  select (and(ge($$178, 1), le($$178, 20)))
                                                                                   -- STREAM_SELECT  |PARTITIONED|
+                                                                                    project ([$$178])
                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                      assign [$$178] <- [$$177.getField(10)]
                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                        exchange
                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                          replicate
                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                            exchange
                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                              project ([$$177])
                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                exchange
                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                  -- DATASOURCE_SCAN (tpcds.store_sales)  |PARTITIONED|
+                                                                                                  data-scan []<-[$$179, $$180, $$177] <- tpcds.store_sales
+                                                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                    exchange
                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                      empty-tuple-source
                                                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                      project ([$$119])
                                                       -- STREAM_PROJECT  |UNPARTITIONED|
+                                                        assign [$$119] <- [{"$1": $$154}]
                                                         -- ASSIGN  |UNPARTITIONED|
+                                                          aggregate [$$154] <- [agg-global-sql-avg($$197)]
                                                           -- AGGREGATE  |UNPARTITIONED|
+                                                            exchange
                                                             -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                                                              aggregate [$$197] <- [agg-local-sql-avg($$117)]
                                                               -- AGGREGATE  |PARTITIONED|
+                                                                project ([$$117])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  select (and(ge($$144, 1), le($$144, 20)))
                                                                   -- STREAM_SELECT  |PARTITIONED|
+                                                                    project ([$$117, $$144])
                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                      assign [$$117, $$144] <- [$$store_sales.getField(14), $$store_sales.getField(10)]
                                                                       -- ASSIGN  |PARTITIONED|
+                                                                        project ([$$store_sales])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          assign [$$store_sales] <- [$$177]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              replicate
                                                                               -- REPLICATE  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  project ([$$177])
                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                    exchange
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                      -- DATASOURCE_SCAN (tpcds.store_sales)  |PARTITIONED|
+                                                                                      data-scan []<-[$$179, $$180, $$177] <- tpcds.store_sales
+                                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                        exchange
                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                          empty-tuple-source
                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                                  join (true)
                                   -- NESTED_LOOP  |LOCAL|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                                      assign [$$192] <- [true]
                                       -- ASSIGN  |LOCAL|
+                                        project ([$$167])
                                         -- STREAM_PROJECT  |LOCAL|
+                                          select (not(or(and($$205, not(is-unknown($$205))))))
                                           -- STREAM_SELECT  |LOCAL|
+                                            assign [$$205] <- [lt(get-item($$167, 0), 25437)]
                                             -- ASSIGN  |LOCAL|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-                                                -- PRE_CLUSTERED_GROUP_BY[$$168]  |LOCAL|
-                                                        {
+                                                group by ([$$167 := $$168]) decor ([]) {
+                                                          aggregate [] <- []
                                                           -- AGGREGATE  |LOCAL|
+                                                            aggregate [] <- []
                                                             -- AGGREGATE  |LOCAL|
+                                                              select (not(is-missing($$175)))
                                                               -- STREAM_SELECT  |LOCAL|
+                                                                nested tuple source
                                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                        }
+                                                       }
+                                                -- PRE_CLUSTERED_GROUP_BY[$$168]  |LOCAL|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                                                    order (ASC, $$168)
                                                     -- STABLE_SORT [$$168(ASC)]  |LOCAL|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                        project ([$$175, $$168])
                                                         -- STREAM_PROJECT  |UNPARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                            left outer join (eq($$168, $$169))
                                                             -- HYBRID_HASH_JOIN [$$168][$$169]  |UNPARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                                replicate
                                                                 -- REPLICATE  |UNPARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                                    project ([$$168])
                                                                     -- STREAM_PROJECT  |UNPARTITIONED|
+                                                                      assign [$$168] <- [$$169]
                                                                       -- ASSIGN  |UNPARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                                          replicate
                                                                           -- REPLICATE  |UNPARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                                              aggregate [$$169] <- [listify($$176)]
                                                                               -- AGGREGATE  |UNPARTITIONED|
+                                                                                aggregate [$$176] <- [agg-sql-sum($$199)]
                                                                                 -- AGGREGATE  |UNPARTITIONED|
+                                                                                  exchange
                                                                                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                                                                                    aggregate [$$199] <- [agg-sql-count(1)]
                                                                                     -- AGGREGATE  |PARTITIONED|
+                                                                                      select (and(ge($$178, 1), le($$178, 20)))
                                                                                       -- STREAM_SELECT  |PARTITIONED|
+                                                                                        project ([$$178])
                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                          assign [$$178] <- [$$177.getField(10)]
                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                            exchange
                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                              replicate
                                                                                               -- REPLICATE  |PARTITIONED|
+                                                                                                exchange
                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                  project ([$$177])
                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                    exchange
                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                      -- DATASOURCE_SCAN (tpcds.store_sales)  |PARTITIONED|
+                                                                                                      data-scan []<-[$$179, $$180, $$177] <- tpcds.store_sales
+                                                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                        exchange
                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                          empty-tuple-source
                                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                                replicate
                                                                 -- REPLICATE  |UNPARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                                    assign [$$175] <- [true]
                                                                     -- ASSIGN  |UNPARTITIONED|
+                                                                      select (lt(get-item($$169, 0), 25437))
                                                                       -- STREAM_SELECT  |UNPARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                                          replicate
                                                                           -- REPLICATE  |UNPARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                                                              aggregate [$$169] <- [listify($$176)]
                                                                               -- AGGREGATE  |UNPARTITIONED|
+                                                                                aggregate [$$176] <- [agg-sql-sum($$199)]
                                                                                 -- AGGREGATE  |UNPARTITIONED|
+                                                                                  exchange
                                                                                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                                                                                    aggregate [$$199] <- [agg-sql-count(1)]
                                                                                     -- AGGREGATE  |PARTITIONED|
+                                                                                      select (and(ge($$178, 1), le($$178, 20)))
                                                                                       -- STREAM_SELECT  |PARTITIONED|
+                                                                                        project ([$$178])
                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                          assign [$$178] <- [$$177.getField(10)]
                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                            exchange
                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                              replicate
                                                                                               -- REPLICATE  |PARTITIONED|
+                                                                                                exchange
                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                  project ([$$177])
                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                    exchange
                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                      -- DATASOURCE_SCAN (tpcds.store_sales)  |PARTITIONED|
+                                                                                                      data-scan []<-[$$179, $$180, $$177] <- tpcds.store_sales
+                                                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                        exchange
                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                          empty-tuple-source
                                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                      project ([$$136])
                                       -- STREAM_PROJECT  |UNPARTITIONED|
+                                        assign [$$136] <- [{"$2": $$155}]
                                         -- ASSIGN  |UNPARTITIONED|
+                                          aggregate [$$155] <- [agg-global-sql-avg($$200)]
                                           -- AGGREGATE  |UNPARTITIONED|
+                                            exchange
                                             -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                                              aggregate [$$200] <- [agg-local-sql-avg($$134)]
                                               -- AGGREGATE  |PARTITIONED|
+                                                project ([$$134])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  select (and(ge($$145, 1), le($$145, 20)))
                                                   -- STREAM_SELECT  |PARTITIONED|
+                                                    project ([$$134, $$145])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      assign [$$134, $$145] <- [$$store_sales.getField(22), $$store_sales.getField(10)]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        project ([$$store_sales])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$store_sales] <- [$$177]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              replicate
                                                               -- REPLICATE  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  project ([$$177])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- DATASOURCE_SCAN (tpcds.store_sales)  |PARTITIONED|
+                                                                      data-scan []<-[$$179, $$180, $$177] <- tpcds.store_sales
+                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          empty-tuple-source
                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1591.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1591.plan
index c57a9b4..3e1cb90 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1591.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1591.plan
@@ -1,151 +1,284 @@
+distribute result [$$140]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    limit 100
     -- STREAM_LIMIT  |UNPARTITIONED|
+      project ([$$140])
       -- STREAM_PROJECT  |PARTITIONED|
+        assign [$$140] <- [{"c": $$c, "ca": $$ca}]
         -- ASSIGN  |PARTITIONED|
+          project ([$$c, $$ca])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- SORT_MERGE_EXCHANGE [$$184(ASC) ]  |PARTITIONED|
+              limit 100
               -- STREAM_LIMIT  |PARTITIONED|
+                project ([$$184, $$c, $$ca])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (or(neq($$155, 0), neq($$156, 0)))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$156, $$184, $$c, $$ca, $$155])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- SORT_GROUP_BY[$$193, $$194]  |PARTITIONED|
-                                {
+                        group by ([$$184 := $$193; $$185 := $$194]) decor ([$$c; $$ca; $$155]) {
+                                  aggregate [$$156] <- [agg-sum($$192)]
                                   -- AGGREGATE  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                }
+                               }
+                        -- SORT_GROUP_BY[$$193, $$194]  |PARTITIONED|
+                          exchange
                           -- HASH_PARTITION_EXCHANGE [$$193, $$194]  |PARTITIONED|
-                            -- PRE_CLUSTERED_GROUP_BY[$$181, $$182]  |PARTITIONED|
-                                    {
+                            group by ([$$193 := $$181; $$194 := $$182]) decor ([$$c; $$ca; $$155]) {
+                                      aggregate [$$192] <- [agg-count({"cs1": $$cs1, "dd1": $$dd1})]
                                       -- AGGREGATE  |LOCAL|
+                                        select (not(is-missing($$183)))
                                         -- STREAM_SELECT  |LOCAL|
+                                          nested tuple source
                                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                    }
+                                   }
+                            -- PRE_CLUSTERED_GROUP_BY[$$181, $$182]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$181) (ASC, $$182)
                                 -- STABLE_SORT [$$181(ASC), $$182(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$c, $$ca, $$155, $$cs1, $$dd1, $$183, $$181, $$182])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        left outer join (eq($$181, $$163))
                                         -- HYBRID_HASH_JOIN [$$181][$$163]  |PARTITIONED|
+                                          exchange
                                           -- HASH_PARTITION_EXCHANGE [$$181]  |PARTITIONED|
-                                            -- SORT_GROUP_BY[$$190, $$191]  |PARTITIONED|
-                                                    {
+                                            group by ([$$181 := $$190; $$182 := $$191]) decor ([$$c; $$ca]) {
+                                                      aggregate [$$155] <- [agg-sum($$189)]
                                                       -- AGGREGATE  |LOCAL|
+                                                        nested tuple source
                                                         -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                    }
+                                                   }
+                                            -- SORT_GROUP_BY[$$190, $$191]  |PARTITIONED|
+                                              exchange
                                               -- HASH_PARTITION_EXCHANGE [$$190, $$191]  |PARTITIONED|
-                                                -- PRE_CLUSTERED_GROUP_BY[$$178, $$179]  |PARTITIONED|
-                                                        {
+                                                group by ([$$190 := $$178; $$191 := $$179]) decor ([$$c; $$ca]) {
+                                                          aggregate [$$189] <- [agg-count({"ws1": $$ws1, "dd1": $$dd1})]
                                                           -- AGGREGATE  |LOCAL|
+                                                            select (not(is-missing($$180)))
                                                             -- STREAM_SELECT  |LOCAL|
+                                                              nested tuple source
                                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                        }
+                                                       }
+                                                -- PRE_CLUSTERED_GROUP_BY[$$178, $$179]  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    order (ASC, $$178) (ASC, $$179)
                                                     -- STABLE_SORT [$$178(ASC), $$179(ASC)]  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        project ([$$c, $$ca, $$ws1, $$dd1, $$180, $$178, $$179])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            left outer join (eq($$178, $$161))
                                                             -- HYBRID_HASH_JOIN [$$178][$$161]  |PARTITIONED|
+                                                              exchange
                                                               -- HASH_PARTITION_EXCHANGE [$$178]  |PARTITIONED|
+                                                                project ([$$c, $$ca, $$178, $$179])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  select (neq($$157, 0))
                                                                   -- STREAM_SELECT  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- SORT_GROUP_BY[$$187, $$188]  |PARTITIONED|
-                                                                              {
+                                                                      group by ([$$178 := $$187; $$179 := $$188]) decor ([$$c; $$ca]) {
+                                                                                aggregate [$$157] <- [agg-sum($$186)]
                                                                                 -- AGGREGATE  |LOCAL|
+                                                                                  nested tuple source
                                                                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                              }
+                                                                             }
+                                                                      -- SORT_GROUP_BY[$$187, $$188]  |PARTITIONED|
+                                                                        exchange
                                                                         -- HASH_PARTITION_EXCHANGE [$$187, $$188]  |PARTITIONED|
-                                                                          -- PRE_CLUSTERED_GROUP_BY[$$142, $$143]  |PARTITIONED|
-                                                                                  {
+                                                                          group by ([$$187 := $$142; $$188 := $$143]) decor ([$$c; $$ca]) {
+                                                                                    aggregate [$$186] <- [agg-count({"ss1": $$ss1, "dd1": $$dd1})]
                                                                                     -- AGGREGATE  |LOCAL|
+                                                                                      select (not(is-missing($$177)))
                                                                                       -- STREAM_SELECT  |LOCAL|
+                                                                                        nested tuple source
                                                                                         -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                  }
+                                                                                 }
+                                                                          -- PRE_CLUSTERED_GROUP_BY[$$142, $$143]  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              order (ASC, $$142) (ASC, $$143)
                                                                               -- STABLE_SORT [$$142(ASC), $$143(ASC)]  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  project ([$$c, $$ca, $$ss1, $$dd1, $$177, $$142, $$143])
                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                    exchange
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                      left outer join (eq($$142, $$159))
                                                                                       -- HYBRID_HASH_JOIN [$$142][$$159]  |PARTITIONED|
+                                                                                        exchange
                                                                                         -- HASH_PARTITION_EXCHANGE [$$142]  |PARTITIONED|
+                                                                                          project ([$$c, $$ca, $$142, $$143])
                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                            exchange
                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                              join (eq($$153, $$143))
                                                                                               -- HYBRID_HASH_JOIN [$$153][$$143]  |PARTITIONED|
+                                                                                                exchange
                                                                                                 -- HASH_PARTITION_EXCHANGE [$$153]  |PARTITIONED|
+                                                                                                  assign [$$153] <- [$$c.getField(4)]
                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                    exchange
                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                      -- DATASOURCE_SCAN (tpcds.customer)  |PARTITIONED|
+                                                                                                      data-scan []<-[$$142, $$c] <- tpcds.customer
+                                                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                        exchange
                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                          empty-tuple-source
                                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                exchange
                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                  -- DATASOURCE_SCAN (tpcds.customer_address)  |PARTITIONED|
+                                                                                                  data-scan []<-[$$143, $$ca] <- tpcds.customer_address
+                                                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                    exchange
                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                      empty-tuple-source
                                                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                        exchange
                                                                                         -- HASH_PARTITION_EXCHANGE [$$159]  |PARTITIONED|
+                                                                                          assign [$$177] <- [true]
                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                            project ([$$ss1, $$159, $$dd1])
                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                              exchange
                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                join (eq($$164, $$146))
                                                                                                 -- HYBRID_HASH_JOIN [$$164][$$146]  |PARTITIONED|
+                                                                                                  exchange
                                                                                                   -- HASH_PARTITION_EXCHANGE [$$164]  |PARTITIONED|
+                                                                                                    assign [$$159, $$164] <- [$$ss1.getField(3), $$ss1.getField(0)]
                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                      project ([$$ss1])
                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                        exchange
                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                          -- DATASOURCE_SCAN (tpcds.store_sales)  |PARTITIONED|
+                                                                                                          data-scan []<-[$$144, $$145, $$ss1] <- tpcds.store_sales
+                                                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                            exchange
                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                              empty-tuple-source
                                                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                  exchange
                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                    replicate
                                                                                                     -- REPLICATE  |PARTITIONED|
+                                                                                                      exchange
                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                        select (and(lt($$dd1.getField(10), 4), eq($$dd1.getField(6), 1900)))
                                                                                                         -- STREAM_SELECT  |PARTITIONED|
+                                                                                                          exchange
                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                            -- DATASOURCE_SCAN (tpcds.date_dim)  |PARTITIONED|
+                                                                                                            data-scan []<-[$$146, $$dd1] <- tpcds.date_dim
+                                                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                              exchange
                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                empty-tuple-source
                                                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                              exchange
                                                               -- HASH_PARTITION_EXCHANGE [$$161]  |PARTITIONED|
+                                                                assign [$$180] <- [true]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  project ([$$ws1, $$161, $$dd1])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      join (eq($$166, $$149))
                                                                       -- HYBRID_HASH_JOIN [$$166][$$149]  |PARTITIONED|
+                                                                        exchange
                                                                         -- HASH_PARTITION_EXCHANGE [$$166]  |PARTITIONED|
+                                                                          assign [$$161, $$166] <- [$$ws1.getField(4), $$ws1.getField(0)]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            project ([$$ws1])
                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                -- DATASOURCE_SCAN (tpcds.web_sales)  |PARTITIONED|
+                                                                                data-scan []<-[$$147, $$148, $$ws1] <- tpcds.web_sales
+                                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    empty-tuple-source
                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          project ([$$149, $$dd1])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            assign [$$149, $$dd1] <- [$$146, $$dd1]
                                                                             -- ASSIGN  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                replicate
                                                                                 -- REPLICATE  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    select (and(lt($$dd1.getField(10), 4), eq($$dd1.getField(6), 1900)))
                                                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                        -- DATASOURCE_SCAN (tpcds.date_dim)  |PARTITIONED|
+                                                                                        data-scan []<-[$$146, $$dd1] <- tpcds.date_dim
+                                                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                            empty-tuple-source
                                                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                          exchange
                                           -- HASH_PARTITION_EXCHANGE [$$163]  |PARTITIONED|
+                                            assign [$$183] <- [true]
                                             -- ASSIGN  |PARTITIONED|
+                                              project ([$$cs1, $$163, $$dd1])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  join (eq($$168, $$152))
                                                   -- HYBRID_HASH_JOIN [$$168][$$152]  |PARTITIONED|
+                                                    exchange
                                                     -- HASH_PARTITION_EXCHANGE [$$168]  |PARTITIONED|
+                                                      assign [$$163, $$168] <- [$$cs1.getField(7), $$cs1.getField(0)]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        project ([$$cs1])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- DATASOURCE_SCAN (tpcds.catalog_sales)  |PARTITIONED|
+                                                            data-scan []<-[$$150, $$151, $$cs1] <- tpcds.catalog_sales
+                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                empty-tuple-source
                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      project ([$$152, $$dd1])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$152, $$dd1] <- [$$146, $$dd1]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            replicate
                                                             -- REPLICATE  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                select (and(lt($$dd1.getField(10), 4), eq($$dd1.getField(6), 1900)))
                                                                 -- STREAM_SELECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (tpcds.date_dim)  |PARTITIONED|
+                                                                    data-scan []<-[$$146, $$dd1] <- tpcds.date_dim
+                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        empty-tuple-source
                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1596.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1596.plan
index d27745b..60726f7 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1596.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1596.plan
@@ -1,27 +1,54 @@
+distribute result [$$47]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$47])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$47] <- [{"cs1": $$cs1, "cr1": $$cr1, "i1": $$i1}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$cs1, $$cr1, $$i1])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- SORT_MERGE_EXCHANGE [$$50(ASC), $$51(ASC) ]  |PARTITIONED|
+            order (ASC, $$50) (ASC, $$51)
             -- STABLE_SORT [$$50(ASC), $$51(ASC)]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$cs1, $$cr1, $$i1, $$50, $$51])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    join (eq($$54, $$50))
                     -- HYBRID_HASH_JOIN [$$50][$$54]  |PARTITIONED|
+                      exchange
                       -- HASH_PARTITION_EXCHANGE [$$50]  |PARTITIONED|
+                        project ([$$cs1, $$cr1, $$50, $$51])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            left outer join (and(eq($$51, $$53), eq($$50, $$52)))
                             -- HYBRID_HASH_JOIN [$$51, $$50][$$53, $$52]  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (tpcds.catalog_sales)  |PARTITIONED|
+                                data-scan []<-[$$50, $$51, $$cs1] <- tpcds.catalog_sales
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (tpcds.catalog_returns)  |PARTITIONED|
+                                data-scan []<-[$$52, $$53, $$cr1] <- tpcds.catalog_returns
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (tpcds.item)  |PARTITIONED|
+                        data-scan []<-[$$54, $$i1] <- tpcds.item
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1596_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1596_ps.plan
index e83f7f4..46c5ace 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1596_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpcds/query-ASTERIXDB-1596_ps.plan
@@ -1,58 +1,116 @@
+distribute result [$$47]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$47])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$47] <- [{"cs1": $$cs1, "cr1": $$cr1, "i1": $$i1}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$cs1, $$cr1, $$i1])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            order (ASC, $$50) (ASC, $$51)
             -- STABLE_SORT [$$50(ASC), $$51(ASC)]  |PARTITIONED|
+              exchange
               -- RANGE_PARTITION_EXCHANGE [$$50(ASC), $$51(ASC)]  |PARTITIONED|
+                forward: shared-variable = $$69
                 -- FORWARD  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    replicate
                     -- REPLICATE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$cs1, $$cr1, $$i1, $$50, $$51])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            join (eq($$54, $$50))
                             -- HYBRID_HASH_JOIN [$$50][$$54]  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$50]  |PARTITIONED|
+                                project ([$$cs1, $$cr1, $$50, $$51])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    left outer join (and(eq($$51, $$53), eq($$50, $$52)))
                                     -- HYBRID_HASH_JOIN [$$51, $$50][$$53, $$52]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (tpcds.catalog_sales)  |PARTITIONED|
+                                        data-scan []<-[$$50, $$51, $$cs1] <- tpcds.catalog_sales
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (tpcds.catalog_returns)  |PARTITIONED|
+                                        data-scan []<-[$$52, $$53, $$cr1] <- tpcds.catalog_returns
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (tpcds.item)  |PARTITIONED|
+                                data-scan []<-[$$54, $$i1] <- tpcds.item
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    aggregate [$$69] <- [agg-range-map($$66, $$67, $$68)]
                     -- AGGREGATE  |UNPARTITIONED|
+                      exchange
                       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                        aggregate [$$66, $$67, $$68] <- [agg-local-sampling($$50, $$51), agg-null-writer($$50), agg-null-writer($$51)]
                         -- AGGREGATE  |PARTITIONED|
+                          project ([$$50, $$51])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              replicate
                               -- REPLICATE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$cs1, $$cr1, $$i1, $$50, $$51])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      join (eq($$54, $$50))
                                       -- HYBRID_HASH_JOIN [$$50][$$54]  |PARTITIONED|
+                                        exchange
                                         -- HASH_PARTITION_EXCHANGE [$$50]  |PARTITIONED|
+                                          project ([$$cs1, $$cr1, $$50, $$51])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              left outer join (and(eq($$51, $$53), eq($$50, $$52)))
                                               -- HYBRID_HASH_JOIN [$$51, $$50][$$53, $$52]  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- DATASOURCE_SCAN (tpcds.catalog_sales)  |PARTITIONED|
+                                                  data-scan []<-[$$50, $$51, $$cs1] <- tpcds.catalog_sales
+                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- DATASOURCE_SCAN (tpcds.catalog_returns)  |PARTITIONED|
+                                                  data-scan []<-[$$52, $$53, $$cr1] <- tpcds.catalog_returns
+                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (tpcds.item)  |PARTITIONED|
+                                          data-scan []<-[$$54, $$i1] <- tpcds.item
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpch/q12_shipping.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpch/q12_shipping.plan
index 0be7ab2..2f415e7 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpch/q12_shipping.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpch/q12_shipping.plan
@@ -1,43 +1,80 @@
+distribute result [$$112]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$112])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$112] <- [{"l_shipmode": $$l_shipmode, "high_line_count": $$123, "low_line_count": $$124}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$l_shipmode(ASC) ]  |PARTITIONED|
-          -- SORT_GROUP_BY[$$131]  |PARTITIONED|
-                  {
+          group by ([$$l_shipmode := $$131]) decor ([]) {
+                    aggregate [$$123, $$124] <- [agg-global-sql-sum($$129), agg-global-sql-sum($$130)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- SORT_GROUP_BY[$$131]  |PARTITIONED|
+            exchange
             -- HASH_PARTITION_EXCHANGE [$$131]  |PARTITIONED|
-              -- SORT_GROUP_BY[$$114]  |PARTITIONED|
-                      {
+              group by ([$$131 := $$114]) decor ([]) {
+                        aggregate [$$129, $$130] <- [agg-local-sql-sum(switch-case(true, or(eq($$119, "1-URGENT"), eq($$119, "2-HIGH")), numeric-add(1, numeric-multiply($$119, 0)), numeric-add(0, numeric-multiply($$119, 0)))), agg-local-sql-sum(switch-case(true, eq(true, or(eq($$119, "1-URGENT"), eq($$119, "2-HIGH"))), numeric-add(0, numeric-multiply($$119, 0)), numeric-add(1, numeric-multiply($$119, 0))))]
                         -- AGGREGATE  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SORT_GROUP_BY[$$114]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$119, $$114])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (eq($$120, $$114))
                       -- HYBRID_HASH_JOIN [$$114][$$120]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$119, $$114])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              join (eq($$118, $$122))
                               -- HYBRID_HASH_JOIN [$$122][$$118]  |PARTITIONED|
+                                exchange
                                 -- HASH_PARTITION_EXCHANGE [$$122]  |PARTITIONED|
+                                  project ([$$114, $$122])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    select (and(lt($$116, $$115), ge($$115, "1994-01-01"), lt($$115, "1995-01-01"), lt($$l.getField("l_shipdate"), $$116)))
                                     -- STREAM_SELECT  |PARTITIONED|
+                                      assign [$$116, $$115, $$114, $$122] <- [$$l.getField("l_commitdate"), $$l.getField("l_receiptdate"), $$l.getField("l_shipmode"), $$l.getField("l_orderkey")]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$l])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
+                                            data-scan []<-[$$117, $$l] <- tpch.LineItem
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$119, $$118])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$119] <- [$$o.getField("o_orderpriority")]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                                        data-scan []<-[$$118, $$o] <- tpch.Orders
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                          unnest $$120 <- scan-collection(array: [ "MAIL", "SHIP" ])
                           -- UNNEST  |UNPARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpch/q12_shipping_broadcast.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpch/q12_shipping_broadcast.plan
index 9908238..dbc33eb 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpch/q12_shipping_broadcast.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpch/q12_shipping_broadcast.plan
@@ -1,43 +1,80 @@
+distribute result [$$112]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$112])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$112] <- [{"l_shipmode": $$l_shipmode, "high_line_count": $$123, "low_line_count": $$124}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$l_shipmode(ASC) ]  |PARTITIONED|
-          -- SORT_GROUP_BY[$$131]  |PARTITIONED|
-                  {
+          group by ([$$l_shipmode := $$131]) decor ([]) {
+                    aggregate [$$123, $$124] <- [agg-global-sql-sum($$129), agg-global-sql-sum($$130)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- SORT_GROUP_BY[$$131]  |PARTITIONED|
+            exchange
             -- HASH_PARTITION_EXCHANGE [$$131]  |PARTITIONED|
-              -- SORT_GROUP_BY[$$114]  |PARTITIONED|
-                      {
+              group by ([$$131 := $$114]) decor ([]) {
+                        aggregate [$$129, $$130] <- [agg-local-sql-sum(switch-case(true, or(eq($$119, "1-URGENT"), eq($$119, "2-HIGH")), numeric-add(1, numeric-multiply($$119, 0)), numeric-add(0, numeric-multiply($$119, 0)))), agg-local-sql-sum(switch-case(true, eq(true, or(eq($$119, "1-URGENT"), eq($$119, "2-HIGH"))), numeric-add(0, numeric-multiply($$119, 0)), numeric-add(1, numeric-multiply($$119, 0))))]
                         -- AGGREGATE  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SORT_GROUP_BY[$$114]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$119, $$114])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (eq($$120, $$114))
                       -- HYBRID_HASH_JOIN [$$114][$$120]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$119, $$114])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              join (eq($$121, $$118))
                               -- HYBRID_HASH_JOIN [$$121][$$118]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$114, $$121])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    select (and(lt($$116, $$115), ge($$115, "1994-01-01"), lt($$115, "1995-01-01"), lt($$l.getField("l_shipdate"), $$116)))
                                     -- STREAM_SELECT  |PARTITIONED|
+                                      assign [$$116, $$115, $$114, $$121] <- [$$l.getField("l_commitdate"), $$l.getField("l_receiptdate"), $$l.getField("l_shipmode"), $$l.getField("l_orderkey")]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$l])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
+                                            data-scan []<-[$$117, $$l] <- tpch.LineItem
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                exchange
                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                  project ([$$119, $$118])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$119] <- [$$o.getField("o_orderpriority")]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                                        data-scan []<-[$$118, $$o] <- tpch.Orders
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                          unnest $$120 <- scan-collection(array: [ "MAIL", "SHIP" ])
                           -- UNNEST  |UNPARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpch/q12_shipping_broadcast_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpch/q12_shipping_broadcast_ps.plan
index baeda7a..2aae859 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpch/q12_shipping_broadcast_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpch/q12_shipping_broadcast_ps.plan
@@ -1,95 +1,178 @@
+distribute result [$$112]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$112])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$112] <- [{"l_shipmode": $$l_shipmode, "high_line_count": $$123, "low_line_count": $$124}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$l_shipmode)
           -- STABLE_SORT [$$l_shipmode(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$l_shipmode(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$134
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- SORT_GROUP_BY[$$131]  |PARTITIONED|
-                              {
+                      group by ([$$l_shipmode := $$131]) decor ([]) {
+                                aggregate [$$123, $$124] <- [agg-global-sql-sum($$129), agg-global-sql-sum($$130)]
                                 -- AGGREGATE  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- SORT_GROUP_BY[$$131]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$131]  |PARTITIONED|
-                          -- SORT_GROUP_BY[$$114]  |PARTITIONED|
-                                  {
+                          group by ([$$131 := $$114]) decor ([]) {
+                                    aggregate [$$129, $$130] <- [agg-local-sql-sum(switch-case(true, or(eq($$119, "1-URGENT"), eq($$119, "2-HIGH")), numeric-add(1, numeric-multiply($$119, 0)), numeric-add(0, numeric-multiply($$119, 0)))), agg-local-sql-sum(switch-case(true, eq(true, or(eq($$119, "1-URGENT"), eq($$119, "2-HIGH"))), numeric-add(0, numeric-multiply($$119, 0)), numeric-add(1, numeric-multiply($$119, 0))))]
                                     -- AGGREGATE  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                  }
+                                 }
+                          -- SORT_GROUP_BY[$$114]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$119, $$114])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  join (eq($$120, $$114))
                                   -- HYBRID_HASH_JOIN [$$114][$$120]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$119, $$114])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          join (eq($$121, $$118))
                                           -- HYBRID_HASH_JOIN [$$121][$$118]  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$114, $$121])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                select (and(lt($$116, $$115), ge($$115, "1994-01-01"), lt($$115, "1995-01-01"), lt($$l.getField("l_shipdate"), $$116)))
                                                 -- STREAM_SELECT  |PARTITIONED|
+                                                  assign [$$116, $$115, $$114, $$121] <- [$$l.getField("l_commitdate"), $$l.getField("l_receiptdate"), $$l.getField("l_shipmode"), $$l.getField("l_orderkey")]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$l])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
+                                                        data-scan []<-[$$117, $$l] <- tpch.LineItem
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                            exchange
                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                              project ([$$119, $$118])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$119] <- [$$o.getField("o_orderpriority")]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                                                    data-scan []<-[$$118, $$o] <- tpch.Orders
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                      unnest $$120 <- scan-collection(array: [ "MAIL", "SHIP" ])
                                       -- UNNEST  |UNPARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$134] <- [agg-range-map($$132, $$133)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$132, $$133] <- [agg-local-sampling($$l_shipmode), agg-null-writer($$l_shipmode)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$l_shipmode])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- SORT_GROUP_BY[$$131]  |PARTITIONED|
-                                        {
+                                group by ([$$l_shipmode := $$131]) decor ([]) {
+                                          aggregate [$$123, $$124] <- [agg-global-sql-sum($$129), agg-global-sql-sum($$130)]
                                           -- AGGREGATE  |LOCAL|
+                                            nested tuple source
                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- SORT_GROUP_BY[$$131]  |PARTITIONED|
+                                  exchange
                                   -- HASH_PARTITION_EXCHANGE [$$131]  |PARTITIONED|
-                                    -- SORT_GROUP_BY[$$114]  |PARTITIONED|
-                                            {
+                                    group by ([$$131 := $$114]) decor ([]) {
+                                              aggregate [$$129, $$130] <- [agg-local-sql-sum(switch-case(true, or(eq($$119, "1-URGENT"), eq($$119, "2-HIGH")), numeric-add(1, numeric-multiply($$119, 0)), numeric-add(0, numeric-multiply($$119, 0)))), agg-local-sql-sum(switch-case(true, eq(true, or(eq($$119, "1-URGENT"), eq($$119, "2-HIGH"))), numeric-add(0, numeric-multiply($$119, 0)), numeric-add(1, numeric-multiply($$119, 0))))]
                                               -- AGGREGATE  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                            }
+                                           }
+                                    -- SORT_GROUP_BY[$$114]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$119, $$114])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            join (eq($$120, $$114))
                                             -- HYBRID_HASH_JOIN [$$114][$$120]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$119, $$114])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    join (eq($$121, $$118))
                                                     -- HYBRID_HASH_JOIN [$$121][$$118]  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        project ([$$114, $$121])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          select (and(lt($$116, $$115), ge($$115, "1994-01-01"), lt($$115, "1995-01-01"), lt($$l.getField("l_shipdate"), $$116)))
                                                           -- STREAM_SELECT  |PARTITIONED|
+                                                            assign [$$116, $$115, $$114, $$121] <- [$$l.getField("l_commitdate"), $$l.getField("l_receiptdate"), $$l.getField("l_shipmode"), $$l.getField("l_orderkey")]
                                                             -- ASSIGN  |PARTITIONED|
+                                                              project ([$$l])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
+                                                                  data-scan []<-[$$117, $$l] <- tpch.LineItem
+                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      empty-tuple-source
                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                      exchange
                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                        project ([$$119, $$118])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$119] <- [$$o.getField("o_orderpriority")]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                                                              data-scan []<-[$$118, $$o] <- tpch.Orders
+                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  empty-tuple-source
                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                              exchange
                                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                unnest $$120 <- scan-collection(array: [ "MAIL", "SHIP" ])
                                                 -- UNNEST  |UNPARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpch/q12_shipping_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpch/q12_shipping_ps.plan
index bbd6cf0..45fdf51 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpch/q12_shipping_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/tpch/q12_shipping_ps.plan
@@ -1,95 +1,178 @@
+distribute result [$$112]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$112])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$112] <- [{"l_shipmode": $$l_shipmode, "high_line_count": $$123, "low_line_count": $$124}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$l_shipmode)
           -- STABLE_SORT [$$l_shipmode(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$l_shipmode(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$134
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- SORT_GROUP_BY[$$131]  |PARTITIONED|
-                              {
+                      group by ([$$l_shipmode := $$131]) decor ([]) {
+                                aggregate [$$123, $$124] <- [agg-global-sql-sum($$129), agg-global-sql-sum($$130)]
                                 -- AGGREGATE  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- SORT_GROUP_BY[$$131]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$131]  |PARTITIONED|
-                          -- SORT_GROUP_BY[$$114]  |PARTITIONED|
-                                  {
+                          group by ([$$131 := $$114]) decor ([]) {
+                                    aggregate [$$129, $$130] <- [agg-local-sql-sum(switch-case(true, or(eq($$119, "1-URGENT"), eq($$119, "2-HIGH")), numeric-add(1, numeric-multiply($$119, 0)), numeric-add(0, numeric-multiply($$119, 0)))), agg-local-sql-sum(switch-case(true, eq(true, or(eq($$119, "1-URGENT"), eq($$119, "2-HIGH"))), numeric-add(0, numeric-multiply($$119, 0)), numeric-add(1, numeric-multiply($$119, 0))))]
                                     -- AGGREGATE  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                  }
+                                 }
+                          -- SORT_GROUP_BY[$$114]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$119, $$114])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  join (eq($$120, $$114))
                                   -- HYBRID_HASH_JOIN [$$114][$$120]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$119, $$114])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          join (eq($$118, $$122))
                                           -- HYBRID_HASH_JOIN [$$122][$$118]  |PARTITIONED|
+                                            exchange
                                             -- HASH_PARTITION_EXCHANGE [$$122]  |PARTITIONED|
+                                              project ([$$114, $$122])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                select (and(lt($$116, $$115), ge($$115, "1994-01-01"), lt($$115, "1995-01-01"), lt($$l.getField("l_shipdate"), $$116)))
                                                 -- STREAM_SELECT  |PARTITIONED|
+                                                  assign [$$116, $$115, $$114, $$122] <- [$$l.getField("l_commitdate"), $$l.getField("l_receiptdate"), $$l.getField("l_shipmode"), $$l.getField("l_orderkey")]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$l])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
+                                                        data-scan []<-[$$117, $$l] <- tpch.LineItem
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$119, $$118])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$119] <- [$$o.getField("o_orderpriority")]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                                                    data-scan []<-[$$118, $$o] <- tpch.Orders
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                      unnest $$120 <- scan-collection(array: [ "MAIL", "SHIP" ])
                                       -- UNNEST  |UNPARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$134] <- [agg-range-map($$132, $$133)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$132, $$133] <- [agg-local-sampling($$l_shipmode), agg-null-writer($$l_shipmode)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$l_shipmode])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- SORT_GROUP_BY[$$131]  |PARTITIONED|
-                                        {
+                                group by ([$$l_shipmode := $$131]) decor ([]) {
+                                          aggregate [$$123, $$124] <- [agg-global-sql-sum($$129), agg-global-sql-sum($$130)]
                                           -- AGGREGATE  |LOCAL|
+                                            nested tuple source
                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- SORT_GROUP_BY[$$131]  |PARTITIONED|
+                                  exchange
                                   -- HASH_PARTITION_EXCHANGE [$$131]  |PARTITIONED|
-                                    -- SORT_GROUP_BY[$$114]  |PARTITIONED|
-                                            {
+                                    group by ([$$131 := $$114]) decor ([]) {
+                                              aggregate [$$129, $$130] <- [agg-local-sql-sum(switch-case(true, or(eq($$119, "1-URGENT"), eq($$119, "2-HIGH")), numeric-add(1, numeric-multiply($$119, 0)), numeric-add(0, numeric-multiply($$119, 0)))), agg-local-sql-sum(switch-case(true, eq(true, or(eq($$119, "1-URGENT"), eq($$119, "2-HIGH"))), numeric-add(0, numeric-multiply($$119, 0)), numeric-add(1, numeric-multiply($$119, 0))))]
                                               -- AGGREGATE  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                            }
+                                           }
+                                    -- SORT_GROUP_BY[$$114]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$119, $$114])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            join (eq($$120, $$114))
                                             -- HYBRID_HASH_JOIN [$$114][$$120]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$119, $$114])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    join (eq($$118, $$122))
                                                     -- HYBRID_HASH_JOIN [$$122][$$118]  |PARTITIONED|
+                                                      exchange
                                                       -- HASH_PARTITION_EXCHANGE [$$122]  |PARTITIONED|
+                                                        project ([$$114, $$122])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          select (and(lt($$116, $$115), ge($$115, "1994-01-01"), lt($$115, "1995-01-01"), lt($$l.getField("l_shipdate"), $$116)))
                                                           -- STREAM_SELECT  |PARTITIONED|
+                                                            assign [$$116, $$115, $$114, $$122] <- [$$l.getField("l_commitdate"), $$l.getField("l_receiptdate"), $$l.getField("l_shipmode"), $$l.getField("l_orderkey")]
                                                             -- ASSIGN  |PARTITIONED|
+                                                              project ([$$l])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
+                                                                  data-scan []<-[$$117, $$l] <- tpch.LineItem
+                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      empty-tuple-source
                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        project ([$$119, $$118])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$119] <- [$$o.getField("o_orderpriority")]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                                                              data-scan []<-[$$118, $$o] <- tpch.Orders
+                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  empty-tuple-source
                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                              exchange
                                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                unnest $$120 <- scan-collection(array: [ "MAIL", "SHIP" ])
                                                 -- UNNEST  |UNPARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/union/union_opt_1_1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/union/union_opt_1_1.plan
index bf2376e..58ef8b7 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/union/union_opt_1_1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/union/union_opt_1_1.plan
@@ -1,47 +1,94 @@
+distribute result [$$59]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$59])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$59] <- [{"unique1": $$61, "unique2": $$122, "unique3": $$124}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$122(ASC) ]  |PARTITIONED|
+          order (ASC, $$122)
           -- STABLE_SORT [$$122(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              union ($$78, $$88, $$61) ($$125, $$133, $$124) ($$62, $$63, $$122)
               -- UNION_ALL  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$78, $$125, $$62])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    select (ge($$78, 98))
                     -- STREAM_SELECT  |PARTITIONED|
+                      project ([$$62, $$125, $$78])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$125, $$78] <- [$$t1.getField(10), $$t1.getField(0)]
                         -- ASSIGN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.onek1.onek1)  |PARTITIONED|
+                            unnest-map [$$62, $$t1] <- index-search("onek1", 0, "test", "onek1", false, false, 1, $$165, 1, $$165, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$165)
                                 -- STABLE_SORT [$$165(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$165])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.onek1.onek1_idx)  |PARTITIONED|
+                                        unnest-map [$$164, $$165] <- index-search("onek1_idx", 0, "test", "onek1", false, false, 1, $$163, 0, true, true, false)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$163])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$163] <- [$$166]
                                               -- ASSIGN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  replicate
                                                   -- REPLICATE  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      assign [$$166] <- [98]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$88, $$133, $$63])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    select (ge($$88, 98))
                     -- STREAM_SELECT  |PARTITIONED|
+                      project ([$$63, $$133, $$88])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$133, $$88] <- [$$t2.getField(10), $$t2.getField(1)]
                         -- ASSIGN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.onek2.onek2)  |PARTITIONED|
+                            unnest-map [$$63, $$t2] <- index-search("onek2", 0, "test", "onek2", false, false, 1, $$168, 1, $$168, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$168)
                                 -- STABLE_SORT [$$168(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$168])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.onek2.onek2_idx)  |PARTITIONED|
+                                        unnest-map [$$167, $$168] <- index-search("onek2_idx", 0, "test", "onek2", false, false, 1, $$166, 0, true, true, false)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$166] <- [98]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/union/union_opt_1_2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/union/union_opt_1_2.plan
index c3dede7..ce89474 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/union/union_opt_1_2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/union/union_opt_1_2.plan
@@ -1,48 +1,96 @@
+distribute result [$$t]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$t])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- SORT_MERGE_EXCHANGE [$$116(ASC) ]  |PARTITIONED|
+        order (ASC, $$116)
         -- STABLE_SORT [$$116(ASC)]  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            union ($$50, $$58, $$t) ($$66, $$67, $$116)
             -- UNION_ALL  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$50, $$66])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (ge($$108, 98))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$66, $$108, $$50])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$50] <- [{"unique1": $$108, "unique2": $$66, "unique3": $$onek1.getField(10)}]
                       -- ASSIGN  |PARTITIONED|
+                        assign [$$108] <- [$$onek1.getField(0)]
                         -- ASSIGN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.onek1.onek1)  |PARTITIONED|
+                            unnest-map [$$66, $$onek1] <- index-search("onek1", 0, "test", "onek1", false, false, 1, $$141, 1, $$141, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$141)
                                 -- STABLE_SORT [$$141(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$141])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.onek1.onek1_idx)  |PARTITIONED|
+                                        unnest-map [$$140, $$141] <- index-search("onek1_idx", 0, "test", "onek1", false, false, 1, $$139, 0, true, true, false)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$139])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$139] <- [$$142]
                                               -- ASSIGN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  replicate
                                                   -- REPLICATE  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      assign [$$142] <- [98]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$58, $$67])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (ge($$112, 98))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$67, $$112, $$58])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$58] <- [{"unique1": $$112, "unique2": $$67, "unique3": $$onek2.getField(10)}]
                       -- ASSIGN  |PARTITIONED|
+                        assign [$$112] <- [$$onek2.getField(1)]
                         -- ASSIGN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (test.onek2.onek2)  |PARTITIONED|
+                            unnest-map [$$67, $$onek2] <- index-search("onek2", 0, "test", "onek2", false, false, 1, $$144, 1, $$144, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$144)
                                 -- STABLE_SORT [$$144(ASC)]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    project ([$$144])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (test.onek2.onek2_idx)  |PARTITIONED|
+                                        unnest-map [$$143, $$144] <- index-search("onek2_idx", 0, "test", "onek2", false, false, 1, $$142, 0, true, true, false)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                assign [$$142] <- [98]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/union/union_opt_1_3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/union/union_opt_1_3.plan
index 30cd988..e7608f7 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/union/union_opt_1_3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/union/union_opt_1_3.plan
@@ -1,49 +1,98 @@
+distribute result [$$58]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$58])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$58] <- [{"alias": $$60, "name": $$122}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$60(ASC) ]  |PARTITIONED|
+          order (ASC, $$60)
           -- STABLE_SORT [$$60(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              union ($$77, $$87, $$60) ($$123, $$131, $$122)
               -- UNION_ALL  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$77, $$123])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    select (ge($$77, "Von"))
                     -- STREAM_SELECT  |PARTITIONED|
+                      project ([$$123, $$77])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$123, $$77] <- [$$t1.getField("name"), $$t1.getField("alias")]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$t1])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.fbu1.fbu1)  |PARTITIONED|
+                              unnest-map [$$61, $$t1] <- index-search("fbu1", 0, "test", "fbu1", false, false, 1, $$163, 1, $$163, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  order (ASC, $$163)
                                   -- STABLE_SORT [$$163(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$163])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (test.fbu1.fbu1_idx)  |PARTITIONED|
+                                          unnest-map [$$162, $$163] <- index-search("fbu1_idx", 0, "test", "fbu1", false, false, 1, $$161, 0, true, true, false)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$161])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$161] <- [$$164]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    replicate
                                                     -- REPLICATE  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        assign [$$164] <- ["Von"]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$87, $$131])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    select (ge($$87, "Von"))
                     -- STREAM_SELECT  |PARTITIONED|
+                      project ([$$131, $$87])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$131, $$87] <- [$$t2.getField("name"), $$t2.getField("alias")]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$t2])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.fbu2.fbu2)  |PARTITIONED|
+                              unnest-map [$$62, $$t2] <- index-search("fbu2", 0, "test", "fbu2", false, false, 1, $$166, 1, $$166, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  order (ASC, $$166)
                                   -- STABLE_SORT [$$166(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$166])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (test.fbu2.fbu2_idx)  |PARTITIONED|
+                                          unnest-map [$$165, $$166] <- index-search("fbu2_idx", 0, "test", "fbu2", false, false, 1, $$164, 0, true, true, false)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              replicate
                                               -- REPLICATE  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  assign [$$164] <- ["Von"]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/union/union_opt_1_4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/union/union_opt_1_4.plan
index 8a1cc02..d2bf047 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/union/union_opt_1_4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/union/union_opt_1_4.plan
@@ -1,50 +1,100 @@
+distribute result [$$t]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$t])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- SORT_MERGE_EXCHANGE [$$112(ASC) ]  |PARTITIONED|
+        order (ASC, $$112)
         -- STABLE_SORT [$$112(ASC)]  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            union ($$49, $$56, $$t) ($$106, $$109, $$112)
             -- UNION_ALL  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$49, $$106])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (ge($$106, "Von"))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$106, $$49])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$49] <- [{"alias": $$106, "name": $$fbu1.getField("name")}]
                       -- ASSIGN  |PARTITIONED|
+                        assign [$$106] <- [$$fbu1.getField("alias")]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$fbu1])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.fbu1.fbu1)  |PARTITIONED|
+                              unnest-map [$$64, $$fbu1] <- index-search("fbu1", 0, "test", "fbu1", false, false, 1, $$137, 1, $$137, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  order (ASC, $$137)
                                   -- STABLE_SORT [$$137(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$137])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (test.fbu1.fbu1_idx)  |PARTITIONED|
+                                          unnest-map [$$136, $$137] <- index-search("fbu1_idx", 0, "test", "fbu1", false, false, 1, $$135, 0, true, true, false)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$135])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$135] <- [$$138]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    replicate
                                                     -- REPLICATE  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        assign [$$138] <- ["Von"]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$56, $$109])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (ge($$109, "Von"))
                   -- STREAM_SELECT  |PARTITIONED|
+                    project ([$$109, $$56])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$56] <- [{"alias": $$109, "name": $$fbu2.getField("name")}]
                       -- ASSIGN  |PARTITIONED|
+                        assign [$$109] <- [$$fbu2.getField("alias")]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$fbu2])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.fbu2.fbu2)  |PARTITIONED|
+                              unnest-map [$$65, $$fbu2] <- index-search("fbu2", 0, "test", "fbu2", false, false, 1, $$140, 1, $$140, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  order (ASC, $$140)
                                   -- STABLE_SORT [$$140(ASC)]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$140])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (test.fbu2.fbu2_idx)  |PARTITIONED|
+                                          unnest-map [$$139, $$140] <- index-search("fbu2_idx", 0, "test", "fbu2", false, false, 1, $$138, 0, true, true, false)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              replicate
                                               -- REPLICATE  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  assign [$$138] <- ["Von"]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/pg_win/pg_win_01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/pg_win/pg_win_01.plan
index 1fee6e7..2869b7a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/pg_win/pg_win_01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/pg_win/pg_win_01.plan
@@ -1,9 +1,18 @@
+distribute result [$$76]
 -- DISTRIBUTE_RESULT  |LOCAL|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+    project ([$$76])
     -- STREAM_PROJECT  |LOCAL|
+      assign [$$76] <- [{"cnt": $$77}]
       -- ASSIGN  |LOCAL|
+        aggregate [$$77] <- [agg-sql-sum($$78)]
         -- AGGREGATE  |LOCAL|
+          aggregate [$$78] <- [agg-sql-count(1)]
           -- AGGREGATE  |LOCAL|
+            unnest $$four <- range(1, 10)
             -- UNNEST  |UNPARTITIONED|
+              select (false)
               -- STREAM_SELECT  |UNPARTITIONED|
-                -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
\ No newline at end of file
+                empty-tuple-source
+                -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_misc/win_misc_01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_misc/win_misc_01.plan
index d58eaa1..724676b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_misc/win_misc_01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_misc/win_misc_01.plan
@@ -1,29 +1,58 @@
+distribute result [$$234]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$234])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$234] <- [{"rank_min_delta": $$236, "rank_max_delta": $$237, "percent_rank_min_delta": $$238, "percent_rank_max_delta": $$239}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$236, $$237, $$238, $$239] <- [agg-global-sql-min($$244), agg-global-sql-max($$245), agg-global-sql-min($$246), agg-global-sql-max($$247)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$244, $$245, $$246, $$247] <- [agg-local-sql-min($$220), agg-local-sql-max($$220), agg-local-sql-min($$228), agg-local-sql-max($$228)]
             -- AGGREGATE  |PARTITIONED|
+              project ([$$220, $$228])
               -- STREAM_PROJECT  |PARTITIONED|
+                assign [$$228, $$220] <- [switch-case(true, lt($$248, 0.001), 0, $$248), numeric-subtract($$250, $$200)]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$200, $$250, $$248])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$248] <- [numeric-subtract(numeric-divide(numeric-subtract($$250, 1), 3), $$210)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$210, $$200, $$250])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$250] <- [numeric-add(numeric-multiply(numeric-subtract(2, $$n), 2), 1)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$n, $$210, $$200])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            window-aggregate [$$210, $$200] <- [percent-rank-impl($$n), rank-impl($$n)] partition [$$t1.c2, $$p] order (DESC, $$n)
                             -- WINDOW  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                order (ASC, $$t1.c2) (ASC, $$p) (DESC, $$n)
                                 -- STABLE_SORT [$$t1.c2(ASC), $$p(ASC), $$n(DESC)]  |PARTITIONED|
+                                  exchange
                                   -- HASH_PARTITION_EXCHANGE [$$t1.c2, $$p]  |PARTITIONED|
+                                    project ([$$n, $$t1.c2, $$p])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      unnest $$d <- range($$240, 2)
                                       -- UNNEST  |PARTITIONED|
+                                        unnest $$n <- range($$240, 2)
                                         -- UNNEST  |PARTITIONED|
+                                          unnest $$p <- range($$240, 2)
                                           -- UNNEST  |PARTITIONED|
+                                            project ([$$t1.c2, $$240])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$t1.c2, $$240] <- [$$t1.getField("c2"), $$t1.getField("one")]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$t1])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (test.t1)  |PARTITIONED|
+                                                    data-scan []<-[$$235, $$t1] <- test.t1
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_misc/win_misc_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_misc/win_misc_02.plan
index a7c9cf6..d1c9b7a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_misc/win_misc_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_misc/win_misc_02.plan
@@ -1,23 +1,43 @@
+distribute result [$$49]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$49])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$49] <- [{"c1": $$51, "sum": $$52}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$51(ASC) ]  |PARTITIONED|
+          order (ASC, $$51)
           -- STABLE_SORT [$$51(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$51, $$52])
               -- STREAM_PROJECT  |PARTITIONED|
-                -- WINDOW  |PARTITIONED|
-                        {
+                window-aggregate [] <- [] partition [$$37] order (ASC, $$51) frame on (ASC, $$39) start unbounded end [$$39] exclude [$$39] {
+                          aggregate [$$52] <- [agg-sql-sum($$51)]
                           -- AGGREGATE  |LOCAL|
+                            nested tuple source
                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                        }
+                       }
+                -- WINDOW  |PARTITIONED|
+                  window-aggregate [$$39] <- [row-number-impl()] partition [$$37] order (ASC, $$51)
                   -- WINDOW_STREAM  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$37) (ASC, $$51)
                       -- STABLE_SORT [$$37(ASC), $$51(ASC)]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$37]  |PARTITIONED|
+                          project ([$$51, $$37])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$37] <- [numeric-mod($$t1.getField("c2"), 2)]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.t1)  |PARTITIONED|
+                                data-scan []<-[$$51, $$t1] <- test.t1
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_1.plan
index 871ea8e..1f6079b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_1.plan
@@ -1,11 +1,22 @@
+distribute result [$$47]
 -- DISTRIBUTE_RESULT  |LOCAL|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+    project ([$$47])
     -- STREAM_PROJECT  |LOCAL|
+      assign [$$47] <- [{"m": $$m, "t": $$t, "row_nubmer": $$40, "percent_rank": round-half-to-even($$45, 2)}]
       -- ASSIGN  |LOCAL|
+        window-aggregate [$$45, $$40] <- [percent-rank-impl($$t), row-number-impl()] partition [$$m] order (ASC, $$t)
         -- WINDOW  |LOCAL|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+            order (ASC, $$m) (ASC, $$t)
             -- STABLE_SORT [$$m(ASC), $$t(ASC)]  |LOCAL|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                assign [$$m] <- [numeric-mod($$t, 4)]
                 -- ASSIGN  |UNPARTITIONED|
+                  unnest $$t <- range(1, 20)
                   -- UNNEST  |UNPARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_10.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_10.plan
index a131487..0ea4062 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_10.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_10.plan
@@ -1,15 +1,27 @@
+distribute result [$$96]
 -- DISTRIBUTE_RESULT  |LOCAL|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+    project ([$$96])
     -- STREAM_PROJECT  |LOCAL|
+      assign [$$96] <- [{"m": $$m, "t": $$t, "w1_first": $$97, "w2_first": numeric-subtract($$98, 1), "w3_last": $$99}]
       -- ASSIGN  |LOCAL|
-        -- WINDOW  |LOCAL|
-                {
+        window-aggregate [] <- [] partition [$$m] order (ASC, $$t) frame on  start unbounded end unbounded {
+                  aggregate [$$99, $$98, $$97] <- [agg-last-element($$t), agg-first-element(numeric-add($$t, 1)), agg-first-element($$t)]
                   -- AGGREGATE  |LOCAL|
+                    nested tuple source
                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                }
+               }
+        -- WINDOW  |LOCAL|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+            order (ASC, $$m) (ASC, $$t)
             -- STABLE_SORT [$$m(ASC), $$t(ASC)]  |LOCAL|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                assign [$$m] <- [numeric-mod($$t, 4)]
                 -- ASSIGN  |UNPARTITIONED|
+                  unnest $$t <- range(0, 11)
                   -- UNNEST  |UNPARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_11.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_11.plan
index a131487..8a1a96b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_11.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_11.plan
@@ -1,15 +1,27 @@
+distribute result [$$96]
 -- DISTRIBUTE_RESULT  |LOCAL|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+    project ([$$96])
     -- STREAM_PROJECT  |LOCAL|
+      assign [$$96] <- [{"m": $$m, "t": $$t, "w1_last": $$97, "w2_first": $$98, "w3_first": numeric-subtract($$99, 1)}]
       -- ASSIGN  |LOCAL|
-        -- WINDOW  |LOCAL|
-                {
+        window-aggregate [] <- [] partition [$$m] order (ASC, $$t) frame on  start unbounded end unbounded {
+                  aggregate [$$99, $$98, $$97] <- [agg-first-element(numeric-add($$t, 1)), agg-first-element($$t), agg-last-element($$t)]
                   -- AGGREGATE  |LOCAL|
+                    nested tuple source
                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                }
+               }
+        -- WINDOW  |LOCAL|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+            order (ASC, $$m) (ASC, $$t)
             -- STABLE_SORT [$$m(ASC), $$t(ASC)]  |LOCAL|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                assign [$$m] <- [numeric-mod($$t, 4)]
                 -- ASSIGN  |UNPARTITIONED|
+                  unnest $$t <- range(0, 11)
                   -- UNNEST  |UNPARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_12.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_12.plan
index 77572d4..8519e1a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_12.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_12.plan
@@ -1,24 +1,45 @@
+distribute result [$$97]
 -- DISTRIBUTE_RESULT  |LOCAL|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+    project ([$$97])
     -- STREAM_PROJECT  |LOCAL|
+      assign [$$97] <- [{"x": $$x, "y": $$y, "cnt": $$100, "rnk": $$95}]
       -- ASSIGN  |LOCAL|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-          -- STABLE_SORT [$$x(ASC), $$93(ASC)]  |LOCAL|
+          order (ASC, $$x) (ASC, $$100)
+          -- STABLE_SORT [$$x(ASC), $$100(ASC)]  |LOCAL|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+              project ([$$x, $$y, $$100, $$95])
               -- STREAM_PROJECT  |LOCAL|
+                window-aggregate [$$95] <- [rank-impl($$101)] partition [$$x] order (ASC, $$101)
                 -- WINDOW_STREAM  |LOCAL|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-                    -- STABLE_SORT [$$x(ASC), $$94(ASC)]  |LOCAL|
+                    order (ASC, $$x) (ASC, $$101)
+                    -- STABLE_SORT [$$x(ASC), $$101(ASC)]  |LOCAL|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-                        -- PRE_CLUSTERED_GROUP_BY[$$96, $$97]  |LOCAL|
-                                {
+                        group by ([$$x := $$103; $$y := $$104]) decor ([]) {
+                                  aggregate [$$100, $$101] <- [agg-sql-sum($$105), agg-sql-sum($$106)]
                                   -- AGGREGATE  |LOCAL|
+                                    aggregate [$$105, $$106] <- [agg-sql-count($$r), agg-sql-count($$r)]
                                     -- AGGREGATE  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                }
+                               }
+                        -- PRE_CLUSTERED_GROUP_BY[$$103, $$104]  |LOCAL|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-                            -- STABLE_SORT [$$96(ASC), $$97(ASC)]  |LOCAL|
+                            order (ASC, $$103) (ASC, $$104)
+                            -- STABLE_SORT [$$103(ASC), $$104(ASC)]  |LOCAL|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                                assign [$$104, $$103] <- [numeric-mod($$r, 4), numeric-mod($$r, 2)]
                                 -- ASSIGN  |UNPARTITIONED|
+                                  unnest $$r <- range(1, 10)
                                   -- UNNEST  |UNPARTITIONED|
-                                    -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
\ No newline at end of file
+                                    empty-tuple-source
+                                    -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_2.plan
index a131487..a79fa0d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_2.plan
@@ -1,15 +1,27 @@
+distribute result [$$56]
 -- DISTRIBUTE_RESULT  |LOCAL|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+    project ([$$56])
     -- STREAM_PROJECT  |LOCAL|
+      assign [$$56] <- [{"m": $$m, "t": $$t, "row_nubmer": $$43, "sum": $$57}]
       -- ASSIGN  |LOCAL|
-        -- WINDOW  |LOCAL|
-                {
+        window-aggregate [$$43] <- [row-number-impl()] partition [$$m] order (ASC, $$t) frame on (ASC, $$t) start unbounded end [$$t] {
+                  aggregate [$$57] <- [agg-sql-sum($$t)]
                   -- AGGREGATE  |LOCAL|
+                    nested tuple source
                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                }
+               }
+        -- WINDOW  |LOCAL|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+            order (ASC, $$m) (ASC, $$t)
             -- STABLE_SORT [$$m(ASC), $$t(ASC)]  |LOCAL|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                assign [$$m] <- [numeric-mod($$t, 4)]
                 -- ASSIGN  |UNPARTITIONED|
+                  unnest $$t <- range(1, 20)
                   -- UNNEST  |UNPARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_3.plan
index a131487..b30973a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_3.plan
@@ -1,15 +1,27 @@
+distribute result [$$64]
 -- DISTRIBUTE_RESULT  |LOCAL|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+    project ([$$64])
     -- STREAM_PROJECT  |LOCAL|
+      assign [$$64] <- [{"m": $$m, "t": $$t, "row_nubmer": $$51, "sum": $$65}]
       -- ASSIGN  |LOCAL|
-        -- WINDOW  |LOCAL|
-                {
+        window-aggregate [$$51] <- [row-number-impl()] partition [$$m] order (ASC, $$t) frame on (ASC, $$t) start unbounded end [$$t] {
+                  aggregate [$$65] <- [agg-sql-sum(numeric-add($$t, numeric-mod($$t, 4)))]
                   -- AGGREGATE  |LOCAL|
+                    nested tuple source
                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                }
+               }
+        -- WINDOW  |LOCAL|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+            order (ASC, $$m) (ASC, $$t)
             -- STABLE_SORT [$$m(ASC), $$t(ASC)]  |LOCAL|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                assign [$$m] <- [numeric-mod($$t, 4)]
                 -- ASSIGN  |UNPARTITIONED|
+                  unnest $$t <- range(1, 20)
                   -- UNNEST  |UNPARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_4.plan
index a131487..c408d88 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_4.plan
@@ -1,15 +1,27 @@
+distribute result [$$94]
 -- DISTRIBUTE_RESULT  |LOCAL|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+    project ([$$94])
     -- STREAM_PROJECT  |LOCAL|
+      assign [$$94] <- [{"m": $$m, "t": $$t, "row_nubmer": $$69, "sum": $$95, "avg": round-half-to-even($$96, 2)}]
       -- ASSIGN  |LOCAL|
-        -- WINDOW  |LOCAL|
-                {
+        window-aggregate [$$69] <- [row-number-impl()] partition [$$m] order (ASC, $$t) frame on (ASC, $$t) start unbounded end [$$t] {
+                  aggregate [$$96, $$95] <- [agg-sql-avg(numeric-subtract($$t, numeric-mod($$t, 4))), agg-sql-sum(numeric-add($$t, numeric-mod($$t, 4)))]
                   -- AGGREGATE  |LOCAL|
+                    nested tuple source
                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                }
+               }
+        -- WINDOW  |LOCAL|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+            order (ASC, $$m) (ASC, $$t)
             -- STABLE_SORT [$$m(ASC), $$t(ASC)]  |LOCAL|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                assign [$$m] <- [numeric-mod($$t, 4)]
                 -- ASSIGN  |UNPARTITIONED|
+                  unnest $$t <- range(1, 20)
                   -- UNNEST  |UNPARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_5.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_5.plan
index 871ea8e..c7f91ad 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_5.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_5.plan
@@ -1,11 +1,22 @@
+distribute result [$$66]
 -- DISTRIBUTE_RESULT  |LOCAL|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+    project ([$$66])
     -- STREAM_PROJECT  |LOCAL|
+      assign [$$66] <- [{"m": $$m, "t": $$t, "row_number": $$59, "ntile": $$63}]
       -- ASSIGN  |LOCAL|
+        window-aggregate [$$63, $$59] <- [ntile-impl(2), row-number-impl()] partition [$$m] order (ASC, $$t)
         -- WINDOW  |LOCAL|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+            order (ASC, $$m) (ASC, $$t)
             -- STABLE_SORT [$$m(ASC), $$t(ASC)]  |LOCAL|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                assign [$$m] <- [numeric-mod($$t, 4)]
                 -- ASSIGN  |UNPARTITIONED|
+                  unnest $$t <- range(1, 16)
                   -- UNNEST  |UNPARTITIONED|
+                    empty-tuple-source
                     -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_6.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_6.plan
index a1e04ad..369bfe2 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_6.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_6.plan
@@ -1,12 +1,24 @@
+distribute result [$$67]
 -- DISTRIBUTE_RESULT  |LOCAL|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+    project ([$$67])
     -- STREAM_PROJECT  |LOCAL|
+      assign [$$67] <- [{"m": $$m, "t": $$t, "row_number": $$59, "ntile": $$63}]
       -- ASSIGN  |LOCAL|
+        window-aggregate [$$63] <- [ntile-impl(numeric-add($$59, 1))] partition [$$m] order (ASC, $$t)
         -- WINDOW  |LOCAL|
+          window-aggregate [$$59] <- [row-number-impl()] partition [$$m] order (ASC, $$t)
           -- WINDOW_STREAM  |LOCAL|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+              order (ASC, $$m) (ASC, $$t)
               -- STABLE_SORT [$$m(ASC), $$t(ASC)]  |LOCAL|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                  assign [$$m] <- [numeric-mod($$t, 4)]
                   -- ASSIGN  |UNPARTITIONED|
+                    unnest $$t <- range(1, 16)
                     -- UNNEST  |UNPARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_7.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_7.plan
index b111336..81934a8 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_7.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_7.plan
@@ -1,17 +1,31 @@
+distribute result [$$67]
 -- DISTRIBUTE_RESULT  |LOCAL|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+    project ([$$67])
     -- STREAM_PROJECT  |LOCAL|
+      assign [$$67] <- [{"m": $$m, "t": $$t, "sum": $$68, "avg": round-half-to-even($$69, 2)}]
       -- ASSIGN  |LOCAL|
+        project ([$$m, $$t, $$68, $$69])
         -- STREAM_PROJECT  |LOCAL|
-          -- WINDOW  |LOCAL|
-                  {
+          window-aggregate [] <- [] partition [$$m] order (ASC, $$t) frame on (ASC, $$46) start unbounded end [$$46] {
+                    aggregate [$$69, $$68] <- [agg-sql-avg($$t), agg-sql-sum($$t)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- WINDOW  |LOCAL|
+            window-aggregate [$$46] <- [row-number-impl()] partition [$$m] order (ASC, $$t)
             -- WINDOW_STREAM  |LOCAL|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                order (ASC, $$m) (ASC, $$t)
                 -- STABLE_SORT [$$m(ASC), $$t(ASC)]  |LOCAL|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                    assign [$$m] <- [numeric-mod($$t, 4)]
                     -- ASSIGN  |UNPARTITIONED|
+                      unnest $$t <- range(1, 20)
                       -- UNNEST  |UNPARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_8.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_8.plan
index 28dbe05..e6db206 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_8.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_8.plan
@@ -1,6 +1,12 @@
+distribute result [$$53]
 -- DISTRIBUTE_RESULT  |LOCAL|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+    aggregate [$$53] <- [agg-sql-sum($$54)]
     -- AGGREGATE  |LOCAL|
+      aggregate [$$54] <- [agg-sql-count(1)]
       -- AGGREGATE  |LOCAL|
+        unnest $$x <- range(1, 10)
         -- UNNEST  |UNPARTITIONED|
-          -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
\ No newline at end of file
+          empty-tuple-source
+          -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_9.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_9.plan
index ac920c2..d7350a3 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_9.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_01/win_opt_01_9.plan
@@ -1,14 +1,25 @@
+distribute result [$$33]
 -- DISTRIBUTE_RESULT  |LOCAL|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+    project ([$$33])
     -- STREAM_PROJECT  |LOCAL|
+      assign [$$33] <- [{"x": $$x, "sum": $$34}]
       -- ASSIGN  |LOCAL|
-        -- WINDOW  |LOCAL|
-                {
+        window-aggregate [] <- [] order (ASC, $$x) frame on  start unbounded end unbounded {
+                  aggregate [$$34] <- [agg-sql-sum($$x)]
                   -- AGGREGATE  |LOCAL|
+                    nested tuple source
                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                }
+               }
+        -- WINDOW  |LOCAL|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+            order (ASC, $$x)
             -- STABLE_SORT [$$x(ASC)]  |LOCAL|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                unnest $$x <- range(1, 10)
                 -- UNNEST  |UNPARTITIONED|
+                  empty-tuple-source
                   -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_02/win_opt_02_1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_02/win_opt_02_1.plan
index 931e417..9db1622 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_02/win_opt_02_1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results/window/win_opt_02/win_opt_02_1.plan
@@ -1,23 +1,40 @@
+distribute result [$$167]
 -- DISTRIBUTE_RESULT  |LOCAL|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+    project ([$$167])
     -- STREAM_PROJECT  |LOCAL|
+      assign [$$167] <- [{"t": $$r, "x": $$178, "dt": $$179, "dx": numeric-subtract($$178, $$171), "v": int64(numeric-divide(numeric-subtract($$178, $$171), $$179)), "a": int64(numeric-subtract(numeric-divide(numeric-subtract($$178, $$171), $$179), $$172))}]
       -- ASSIGN  |LOCAL|
+        project ([$$r, $$171, $$172, $$179, $$178])
         -- STREAM_PROJECT  |LOCAL|
+          assign [$$179, $$178] <- [numeric-subtract($$r, $$170), numeric-multiply($$r, $$r)]
           -- ASSIGN  |LOCAL|
+            project ([$$r, $$171, $$172, $$170])
             -- STREAM_PROJECT  |LOCAL|
-              -- WINDOW  |LOCAL|
-                      {
+              window-aggregate [] <- [] order (ASC, $$r) frame on (ASC, $$120) start [numeric-subtract($$120, 1)] if [is-numeric-add-compatible($$120)] end [numeric-subtract($$120, 1)] if [is-numeric-add-compatible($$120)] maxObjects 1 {
+                        aggregate [$$172] <- [agg-first-element(numeric-divide(numeric-subtract(numeric-multiply($$r, $$r), $$171), numeric-subtract($$r, $$170)))]
                         -- AGGREGATE  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
-                -- WINDOW  |LOCAL|
-                        {
+                     }
+              -- WINDOW  |LOCAL|
+                window-aggregate [] <- [] order (ASC, $$r) frame on (ASC, $$120) start [numeric-subtract($$120, 1)] if [is-numeric-add-compatible($$120)] end [numeric-subtract($$120, 1)] if [is-numeric-add-compatible($$120)] maxObjects 1 {
+                          aggregate [$$171, $$170] <- [agg-first-element(numeric-multiply($$r, $$r)), agg-first-element($$r)]
                           -- AGGREGATE  |LOCAL|
+                            nested tuple source
                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                        }
+                       }
+                -- WINDOW  |LOCAL|
+                  window-aggregate [$$120] <- [row-number-impl()] order (ASC, $$r)
                   -- WINDOW_STREAM  |LOCAL|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                      order (ASC, $$r)
                       -- STABLE_SORT [$$r(ASC)]  |LOCAL|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                          unnest $$r <- range(1, 10)
                           -- UNNEST  |UNPARTITIONED|
-                            -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
\ No newline at end of file
+                            empty-tuple-source
+                            -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/aggregate-sql-sugar/distinct_mixed/distinct_mixed.10.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/aggregate-sql-sugar/distinct_mixed/distinct_mixed.10.plan
index 9ea1780..4863e86 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/aggregate-sql-sugar/distinct_mixed/distinct_mixed.10.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/aggregate-sql-sugar/distinct_mixed/distinct_mixed.10.plan
@@ -1,35 +1,67 @@
+distribute result [$$74]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$74])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$74] <- [{"g": $$g, "count_distinct_x": $$77, "sum_distinct_x": $$78}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$g(ASC) ]  |PARTITIONED|
-          -- PRE_CLUSTERED_GROUP_BY[$$g]  |PARTITIONED|
-                  {
+          group by ([$$g := $$g]) decor ([]) {
+                    aggregate [$$77, $$78] <- [agg-sql-count($$67), agg-sql-sum($$67)]
                     -- AGGREGATE  |LOCAL|
+                      distinct ([$$67])
                       -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                        order (ASC, $$67)
                         -- MICRO_STABLE_SORT [$$67(ASC)]  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- PRE_CLUSTERED_GROUP_BY[$$g]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$g)
               -- STABLE_SORT [$$g(ASC)]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$g]  |PARTITIONED|
+                  join (true)
                   -- NESTED_LOOP  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (true)
                       -- NESTED_LOOP  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$67])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$67] <- [$$x.getField(1)]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$x])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.d1)  |PARTITIONED|
+                                  data-scan []<-[$$75, $$x] <- test.d1
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                          unnest $$g <- range(1, 3)
                           -- UNNEST  |UNPARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                    exchange
                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                      project ([])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (test.d2)  |PARTITIONED|
+                          data-scan []<-[$$76, $$y] <- test.d2
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/aggregate-sql-sugar/distinct_mixed/distinct_mixed.11.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/aggregate-sql-sugar/distinct_mixed/distinct_mixed.11.plan
index ebfcfc2..dbfdeba 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/aggregate-sql-sugar/distinct_mixed/distinct_mixed.11.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/aggregate-sql-sugar/distinct_mixed/distinct_mixed.11.plan
@@ -1,43 +1,81 @@
+distribute result [$$74]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$74])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$74] <- [{"g": $$g, "sum_distinct_x": $$77, "sum_distinct_y": $$78}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$g(ASC) ]  |PARTITIONED|
-          -- PRE_CLUSTERED_GROUP_BY[$$g]  |PARTITIONED|
-                  {
+          group by ([$$g := $$g]) decor ([]) {
+                    aggregate [$$77] <- [agg-sql-sum($$67)]
                     -- AGGREGATE  |LOCAL|
+                      distinct ([$$67])
                       -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                        order (ASC, $$67)
                         -- MICRO_STABLE_SORT [$$67(ASC)]  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
-                  {
+                 }
+                 {
+                    aggregate [$$78] <- [agg-sql-sum($$72)]
                     -- AGGREGATE  |LOCAL|
+                      distinct ([$$72])
                       -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                        order (ASC, $$72)
                         -- MICRO_STABLE_SORT [$$72(ASC)]  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- PRE_CLUSTERED_GROUP_BY[$$g]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$g)
               -- STABLE_SORT [$$g(ASC)]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$g]  |PARTITIONED|
+                  join (true)
                   -- NESTED_LOOP  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (true)
                       -- NESTED_LOOP  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$67])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$67] <- [$$x.getField(1)]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$x])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.d1)  |PARTITIONED|
+                                  data-scan []<-[$$75, $$x] <- test.d1
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                          unnest $$g <- range(1, 3)
                           -- UNNEST  |UNPARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                    exchange
                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                      project ([$$72])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$72] <- [$$y.getField(1)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$y])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (test.d2)  |PARTITIONED|
+                              data-scan []<-[$$76, $$y] <- test.d2
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/aggregate-sql-sugar/distinct_mixed/distinct_mixed.12.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/aggregate-sql-sugar/distinct_mixed/distinct_mixed.12.plan
index a8f346f..15778c2 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/aggregate-sql-sugar/distinct_mixed/distinct_mixed.12.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/aggregate-sql-sugar/distinct_mixed/distinct_mixed.12.plan
@@ -1,39 +1,73 @@
+distribute result [$$83]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$83])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$83] <- [{"g": $$g, "sum_x": $$86, "sum_distinct_x": $$87, "sum_distinct_y": $$88}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$g(ASC) ]  |PARTITIONED|
-          -- PRE_CLUSTERED_GROUP_BY[$$g]  |PARTITIONED|
-                  {
+          group by ([$$g := $$g]) decor ([]) {
+                    aggregate [$$86] <- [agg-sql-sum($$71)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
-                  {
+                 }
+                 {
+                    aggregate [$$87, $$88] <- [agg-sql-sum($$71), agg-sql-sum($$71)]
                     -- AGGREGATE  |LOCAL|
+                      distinct ([$$71])
                       -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                        order (ASC, $$71)
                         -- MICRO_STABLE_SORT [$$71(ASC)]  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- PRE_CLUSTERED_GROUP_BY[$$g]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$g)
               -- STABLE_SORT [$$g(ASC)]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$g]  |PARTITIONED|
+                  join (true)
                   -- NESTED_LOOP  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (true)
                       -- NESTED_LOOP  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$71])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$71] <- [$$x.getField(1)]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$x])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.d1)  |PARTITIONED|
+                                  data-scan []<-[$$84, $$x] <- test.d1
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                          unnest $$g <- range(1, 3)
                           -- UNNEST  |UNPARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                    exchange
                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                      project ([])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (test.d2)  |PARTITIONED|
+                          data-scan []<-[$$85, $$y] <- test.d2
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/aggregate-sql-sugar/distinct_mixed/distinct_mixed.13.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/aggregate-sql-sugar/distinct_mixed/distinct_mixed.13.plan
index 439b1d4..6c77ada 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/aggregate-sql-sugar/distinct_mixed/distinct_mixed.13.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/aggregate-sql-sugar/distinct_mixed/distinct_mixed.13.plan
@@ -1,57 +1,107 @@
+distribute result [$$94]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$94])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$94] <- [{"g": $$g, "sum_distinct_x": $$98, "sum_y": $$99, "sum_distinct_z": $$100}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$g(ASC) ]  |PARTITIONED|
-          -- PRE_CLUSTERED_GROUP_BY[$$g]  |PARTITIONED|
-                  {
+          group by ([$$g := $$g]) decor ([]) {
+                    aggregate [$$98] <- [agg-sql-sum($$82)]
                     -- AGGREGATE  |LOCAL|
+                      distinct ([$$82])
                       -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                        order (ASC, $$82)
                         -- MICRO_STABLE_SORT [$$82(ASC)]  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
-                  {
+                 }
+                 {
+                    aggregate [$$99] <- [agg-sql-sum($$87)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
-                  {
+                 }
+                 {
+                    aggregate [$$100] <- [agg-sql-sum($$92)]
                     -- AGGREGATE  |LOCAL|
+                      distinct ([$$92])
                       -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                        order (ASC, $$92)
                         -- MICRO_STABLE_SORT [$$92(ASC)]  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- PRE_CLUSTERED_GROUP_BY[$$g]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$g)
               -- STABLE_SORT [$$g(ASC)]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$g]  |PARTITIONED|
+                  join (true)
                   -- NESTED_LOOP  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (true)
                       -- NESTED_LOOP  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          join (true)
                           -- NESTED_LOOP  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$82])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$82] <- [$$x.getField(1)]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$x])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.d1)  |PARTITIONED|
+                                      data-scan []<-[$$95, $$x] <- test.d1
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                              unnest $$g <- range(1, 3)
                               -- UNNEST  |UNPARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                        exchange
                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                          project ([$$87])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$87] <- [$$y.getField(1)]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$y])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.d2)  |PARTITIONED|
+                                  data-scan []<-[$$96, $$y] <- test.d2
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                    exchange
                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                      project ([$$92])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$92] <- [$$z.getField(1)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$z])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (test.d3)  |PARTITIONED|
+                              data-scan []<-[$$97, $$z] <- test.d3
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/aggregate-sql-sugar/distinct_mixed/distinct_mixed.14.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/aggregate-sql-sugar/distinct_mixed/distinct_mixed.14.plan
index c57b6f9..ea445d9 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/aggregate-sql-sugar/distinct_mixed/distinct_mixed.14.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/aggregate-sql-sugar/distinct_mixed/distinct_mixed.14.plan
@@ -1,63 +1,117 @@
+distribute result [$$148]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$148])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$148] <- [{"g": $$g, "sum_distinct_x": $$152, "sum_y": $$153, "sum_distinct_z": $$154, "avg_distinct_x": $$155, "avg_distinct_y": $$156, "count_x": $$157, "count_distinct_y": $$158, "avg_z": $$159, "count_distinct_z": $$160}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$g(ASC) ]  |PARTITIONED|
-          -- PRE_CLUSTERED_GROUP_BY[$$g]  |PARTITIONED|
-                  {
+          group by ([$$g := $$g]) decor ([]) {
+                    aggregate [$$152, $$155] <- [agg-sql-sum($$106), agg-sql-avg($$106)]
                     -- AGGREGATE  |LOCAL|
+                      distinct ([$$106])
                       -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                        order (ASC, $$106)
                         -- MICRO_STABLE_SORT [$$106(ASC)]  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
-                  {
+                 }
+                 {
+                    aggregate [$$153, $$157, $$159] <- [agg-sql-sum($$111), agg-sql-count($$106), agg-sql-avg($$116)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
-                  {
+                 }
+                 {
+                    aggregate [$$154, $$160] <- [agg-sql-sum($$116), agg-sql-count($$116)]
                     -- AGGREGATE  |LOCAL|
+                      distinct ([$$116])
                       -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                        order (ASC, $$116)
                         -- MICRO_STABLE_SORT [$$116(ASC)]  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
-                  {
+                 }
+                 {
+                    aggregate [$$156, $$158] <- [agg-sql-avg($$111), agg-sql-count($$111)]
                     -- AGGREGATE  |LOCAL|
+                      distinct ([$$111])
                       -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                        order (ASC, $$111)
                         -- MICRO_STABLE_SORT [$$111(ASC)]  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- PRE_CLUSTERED_GROUP_BY[$$g]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$g)
               -- STABLE_SORT [$$g(ASC)]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$g]  |PARTITIONED|
+                  join (true)
                   -- NESTED_LOOP  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (true)
                       -- NESTED_LOOP  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          join (true)
                           -- NESTED_LOOP  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$106])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$106] <- [$$x.getField(1)]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$x])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.d1)  |PARTITIONED|
+                                      data-scan []<-[$$149, $$x] <- test.d1
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                            exchange
                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                              unnest $$g <- range(1, 3)
                               -- UNNEST  |UNPARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                        exchange
                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                          project ([$$111])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$111] <- [$$y.getField(1)]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$y])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.d2)  |PARTITIONED|
+                                  data-scan []<-[$$150, $$y] <- test.d2
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                    exchange
                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                      project ([$$116])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$116] <- [$$z.getField(1)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$z])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (test.d3)  |PARTITIONED|
+                              data-scan []<-[$$151, $$z] <- test.d3
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/aggregate-sql-sugar/distinct_mixed/distinct_mixed.9.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/aggregate-sql-sugar/distinct_mixed/distinct_mixed.9.plan
index 8802ff5..b503885 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/aggregate-sql-sugar/distinct_mixed/distinct_mixed.9.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/aggregate-sql-sugar/distinct_mixed/distinct_mixed.9.plan
@@ -1,35 +1,67 @@
+distribute result [$$65]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$65])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$65] <- [{"g": $$g, "count_distinct_x": $$68}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$g(ASC) ]  |PARTITIONED|
-          -- PRE_CLUSTERED_GROUP_BY[$$g]  |PARTITIONED|
-                  {
+          group by ([$$g := $$g]) decor ([]) {
+                    aggregate [$$68] <- [agg-sql-count($$63)]
                     -- AGGREGATE  |LOCAL|
+                      distinct ([$$63])
                       -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                        order (ASC, $$63)
                         -- MICRO_STABLE_SORT [$$63(ASC)]  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- PRE_CLUSTERED_GROUP_BY[$$g]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              order (ASC, $$g)
               -- STABLE_SORT [$$g(ASC)]  |PARTITIONED|
+                exchange
                 -- HASH_PARTITION_EXCHANGE [$$g]  |PARTITIONED|
+                  join (true)
                   -- NESTED_LOOP  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (true)
                       -- NESTED_LOOP  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$63])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$63] <- [$$x.getField(1)]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$x])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.d1)  |PARTITIONED|
+                                  data-scan []<-[$$66, $$x] <- test.d1
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                          unnest $$g <- range(1, 3)
                           -- UNNEST  |UNPARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                    exchange
                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                      project ([])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (test.d2)  |PARTITIONED|
+                          data-scan []<-[$$67, $$y] <- test.d2
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/atomic-and-array-queries/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/atomic-and-array-queries/query1.plan
index d69738a..aae767e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/atomic-and-array-queries/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/atomic-and-array-queries/query1.plan
@@ -1,14 +1,28 @@
+distribute result [$$33]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$33])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$33] <- [{"D": $$D, "DI": $$DI}]
       -- ASSIGN  |PARTITIONED|
+        select (and(eq($$DI.getField("field2"), 2), eq($$DI.getField("field3"), 3)))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$D, $$DI])
           -- STREAM_PROJECT  |PARTITIONED|
+            unnest $$DI <- scan-collection($$37)
             -- UNNEST  |PARTITIONED|
+              select (and(eq($$D.getField("field1"), 1), eq($$D.getField("field4"), 4)))
               -- STREAM_SELECT  |PARTITIONED|
+                assign [$$37] <- [$$D.getField("items")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$D])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (TestDataverse.Dataset1)  |PARTITIONED|
+                      data-scan []<-[$$34, $$D] <- TestDataverse.Dataset1
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/atomic-and-array-queries/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/atomic-and-array-queries/query2.plan
index d69738a..f373a2c 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/atomic-and-array-queries/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/atomic-and-array-queries/query2.plan
@@ -1,14 +1,28 @@
+distribute result [$$37]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$37])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$37] <- [{"D": $$D, "DI": $$DI}]
       -- ASSIGN  |PARTITIONED|
+        select (and(eq($$DI.getField("field2"), 2), eq($$DI.getField("field3"), 3), eq($$DI.getField("field3_notindexed"), 3)))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$D, $$DI])
           -- STREAM_PROJECT  |PARTITIONED|
+            unnest $$DI <- scan-collection($$42)
             -- UNNEST  |PARTITIONED|
+              select (and(eq($$D.getField("field4"), 4), eq($$D.getField("field1"), 1), eq($$D.getField("field4_notindexed"), 4)))
               -- STREAM_SELECT  |PARTITIONED|
+                assign [$$42] <- [$$D.getField("items")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$D])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (TestDataverse.Dataset1)  |PARTITIONED|
+                      data-scan []<-[$$38, $$D] <- TestDataverse.Dataset1
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/atomic-and-array-queries/query3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/atomic-and-array-queries/query3.plan
index 52f7d02..1ac8d7d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/atomic-and-array-queries/query3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/atomic-and-array-queries/query3.plan
@@ -1,18 +1,36 @@
+distribute result [$$48]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$48])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$48] <- [{"D": $$D, "DOI": $$DOI, "DII": $$DII}]
       -- ASSIGN  |PARTITIONED|
+        select (and(eq($$DII.getField("field2"), 2), eq($$DII.getField("field3"), 3), eq($$DII.getField("field3_notindexed"), 3)))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$D, $$DOI, $$DII])
           -- STREAM_PROJECT  |PARTITIONED|
+            unnest $$DII <- scan-collection($$54)
             -- UNNEST  |PARTITIONED|
+              select (eq($$DOI.getField("field2_notindexed"), 2))
               -- STREAM_SELECT  |PARTITIONED|
+                assign [$$54] <- [$$DOI.getField("inner_items")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$D, $$DOI])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    unnest $$DOI <- scan-collection($$52)
                     -- UNNEST  |PARTITIONED|
+                      select (and(eq($$D.getField("field1"), 1), eq($$D.getField("field4"), 4)))
                       -- STREAM_SELECT  |PARTITIONED|
+                        assign [$$52] <- [$$D.getField("outer_items")]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$D])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (TestDataverse.Dataset1)  |PARTITIONED|
+                              data-scan []<-[$$49, $$D] <- TestDataverse.Dataset1
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/atomic-and-array-queries/query8.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/atomic-and-array-queries/query8.plan
deleted file mode 100644
index ea7ceef..0000000
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/atomic-and-array-queries/query8.plan
+++ /dev/null
@@ -1,38 +0,0 @@
--- DISTRIBUTE_RESULT  |PARTITIONED|
-  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- STREAM_PROJECT  |PARTITIONED|
-      -- ASSIGN  |PARTITIONED|
-        -- STREAM_PROJECT  |PARTITIONED|
-          -- STREAM_SELECT  |PARTITIONED|
-            -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
-                        -- AGGREGATE  |LOCAL|
-                          -- STREAM_SELECT  |LOCAL|
-                            -- ASSIGN  |LOCAL|
-                              -- UNNEST  |LOCAL|
-                                -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
-                -- ASSIGN  |PARTITIONED|
-                  -- STREAM_PROJECT  |PARTITIONED|
-                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (TestDataverse.Dataset1.Dataset1)  |PARTITIONED|
-                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- STREAM_PROJECT  |PARTITIONED|
-                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
-                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- STABLE_SORT [$$74(ASC), $$75(ASC)]  |PARTITIONED|
-                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- STREAM_PROJECT  |PARTITIONED|
-                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (TestDataverse.Dataset1.d1Idx)  |PARTITIONED|
-                                            -- BROADCAST_EXCHANGE  |PARTITIONED|
-                                              -- RUNNING_AGGREGATE  |PARTITIONED|
-                                                -- ASSIGN  |PARTITIONED|
-                                                  -- ASSIGN  |PARTITIONED|
-                                                    -- STREAM_PROJECT  |PARTITIONED|
-                                                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (TestDataverse.Dataset2)  |PARTITIONED|
-                                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/atomic-and-array-queries/query9.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/atomic-and-array-queries/query9.plan
deleted file mode 100644
index b47e122..0000000
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/atomic-and-array-queries/query9.plan
+++ /dev/null
@@ -1,47 +0,0 @@
--- DISTRIBUTE_RESULT  |PARTITIONED|
-  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- STREAM_PROJECT  |PARTITIONED|
-      -- ASSIGN  |PARTITIONED|
-        -- STREAM_PROJECT  |PARTITIONED|
-          -- STREAM_SELECT  |PARTITIONED|
-            -- STREAM_PROJECT  |PARTITIONED|
-              -- SUBPLAN  |PARTITIONED|
-                      {
-                        -- AGGREGATE  |LOCAL|
-                          -- STREAM_SELECT  |LOCAL|
-                            -- SUBPLAN  |LOCAL|
-                                    {
-                                      -- AGGREGATE  |LOCAL|
-                                        -- STREAM_SELECT  |LOCAL|
-                                          -- ASSIGN  |LOCAL|
-                                            -- UNNEST  |LOCAL|
-                                              -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                    }
-                              -- STREAM_SELECT  |LOCAL|
-                                -- ASSIGN  |LOCAL|
-                                  -- UNNEST  |LOCAL|
-                                    -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
-                -- ASSIGN  |PARTITIONED|
-                  -- STREAM_PROJECT  |PARTITIONED|
-                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (TestDataverse.Dataset1.Dataset1)  |PARTITIONED|
-                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- STREAM_PROJECT  |PARTITIONED|
-                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
-                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- STABLE_SORT [$$104(ASC), $$105(ASC)]  |PARTITIONED|
-                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- STREAM_PROJECT  |PARTITIONED|
-                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (TestDataverse.Dataset1.d1Idx)  |PARTITIONED|
-                                            -- BROADCAST_EXCHANGE  |PARTITIONED|
-                                              -- RUNNING_AGGREGATE  |PARTITIONED|
-                                                -- ASSIGN  |PARTITIONED|
-                                                  -- ASSIGN  |PARTITIONED|
-                                                    -- STREAM_PROJECT  |PARTITIONED|
-                                                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (TestDataverse.Dataset2)  |PARTITIONED|
-                                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-1/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-1/query1.plan
index 834d7d2..e4c803c 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-1/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-1/query1.plan
@@ -1,14 +1,28 @@
+distribute result [$$26]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$26])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$26] <- [{"business_id": $$C.getField(1)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$C])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq("2016-04-26 19:49:16", $$D))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$C, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$28)
               -- UNNEST  |PARTITIONED|
+                assign [$$28] <- [$$C.getField(2)]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$C])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                      data-scan []<-[$$27, $$C] <- TestYelp.YelpCheckin
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-1/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-1/query2.plan
index d18b9b4..10f69e4 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-1/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-1/query2.plan
@@ -1,17 +1,34 @@
+distribute result [$$46]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$46])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$46] <- [{"$1": $$48}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$48] <- [agg-sql-sum($$50)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$50] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(gt($$D, "2016"), lt($$D, "2017")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$D <- scan-collection($$49)
                   -- UNNEST  |PARTITIONED|
+                    project ([$$49])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$49] <- [$$C.getField(2)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$C])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                            data-scan []<-[$$47, $$C] <- TestYelp.YelpCheckin
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-2/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-2/query1.plan
index 834d7d2..92cb49f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-2/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-2/query1.plan
@@ -1,14 +1,28 @@
+distribute result [$$27]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$27])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$27] <- [{"business_id": $$C.getField(1)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$C])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq("2016-04-26", $$D))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$C, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$29)
               -- UNNEST  |PARTITIONED|
+                assign [$$29] <- [$$C.getField(2).getField(0)]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$C])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                      data-scan []<-[$$28, $$C] <- TestYelp.YelpCheckin
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-2/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-2/query2.plan
index d18b9b4..1faed3f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-2/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-2/query2.plan
@@ -1,17 +1,34 @@
+distribute result [$$47]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$47])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$47] <- [{"$1": $$49}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$49] <- [agg-sql-sum($$52)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$52] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(gt($$D, "2016"), lt($$D, "2017")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$D <- scan-collection($$50)
                   -- UNNEST  |PARTITIONED|
+                    project ([$$50])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$50] <- [$$C.getField(2).getField(0)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$C])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                            data-scan []<-[$$48, $$C] <- TestYelp.YelpCheckin
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-3/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-3/query1.plan
index 834d7d2..63c0051 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-3/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-3/query1.plan
@@ -1,14 +1,28 @@
+distribute result [$$27]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$27])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$27] <- [{"business_id": $$C.getField(1)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$C])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq("2016-04-26", $$D.getField(0)))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$C, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$29)
               -- UNNEST  |PARTITIONED|
+                assign [$$29] <- [$$C.getField(2)]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$C])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                      data-scan []<-[$$28, $$C] <- TestYelp.YelpCheckin
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-3/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-3/query2.plan
index 5e46297..8824380 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-3/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-3/query2.plan
@@ -1,19 +1,38 @@
+distribute result [$$48]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$48])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$48] <- [{"$1": $$51}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$51] <- [agg-sql-sum($$53)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$53] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(gt($$49, "2016"), lt($$49, "2017")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$49])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$49] <- [$$D.getField(0)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$D])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      unnest $$D <- scan-collection($$52)
                       -- UNNEST  |PARTITIONED|
+                        project ([$$52])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$52] <- [$$C.getField(2)]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$C])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                                data-scan []<-[$$50, $$C] <- TestYelp.YelpCheckin
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-3/query3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-3/query3.plan
index 834d7d2..84bf568 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-3/query3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-3/query3.plan
@@ -1,14 +1,28 @@
+distribute result [$$30]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$30])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$30] <- [{"business_id": $$C.getField(1)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$C])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and(eq("2016-04-26", $$D.getField(0)), eq($$D.getField(1), "19:49:16")))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$C, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$32)
               -- UNNEST  |PARTITIONED|
+                assign [$$32] <- [$$C.getField(2)]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$C])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                      data-scan []<-[$$31, $$C] <- TestYelp.YelpCheckin
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-4/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-4/query1.plan
index 7c44281..882270e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-4/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-4/query1.plan
@@ -1,18 +1,36 @@
+distribute result [$$37]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$37])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$37] <- [{"business_id": $$C.getField(1)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$C])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq("2016-04-26", $$D))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$C, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$40)
               -- UNNEST  |PARTITIONED|
+                project ([$$C, $$40])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$40] <- [$$CT.getField(0)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$C, $$CT])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      unnest $$CT <- scan-collection($$39)
                       -- UNNEST  |PARTITIONED|
+                        assign [$$39] <- [$$C.getField(2)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$C])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                              data-scan []<-[$$38, $$C] <- TestYelp.YelpCheckin
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-4/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-4/query2.plan
index b191fe2..aae3036 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-4/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/use-case-4/query2.plan
@@ -1,21 +1,42 @@
+distribute result [$$57]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$57])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$57] <- [{"$1": $$59}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$59] <- [agg-sql-sum($$62)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$62] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(gt($$D, "2016"), lt($$D, "2017")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$D <- scan-collection($$61)
                   -- UNNEST  |PARTITIONED|
+                    project ([$$61])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$61] <- [$$CT.getField(0)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$CT])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          unnest $$CT <- scan-collection($$60)
                           -- UNNEST  |PARTITIONED|
+                            project ([$$60])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$60] <- [$$C.getField(2)]
                               -- ASSIGN  |PARTITIONED|
+                                project ([$$C])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                                    data-scan []<-[$$58, $$C] <- TestYelp.YelpCheckin
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-3-level-record-path/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-3-level-record-path/query1.plan
index 834d7d2..ea5d756 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-3-level-record-path/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-3-level-record-path/query1.plan
@@ -1,14 +1,28 @@
+distribute result [$$29]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$29])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$29] <- [{"business_id": $$C.getField(1)}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$C])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq("2016-04-26", $$D))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$C, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$31)
               -- UNNEST  |PARTITIONED|
+                assign [$$31] <- [$$C.getField(2).getField(0).getField(0).getField(0)]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$C])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                      data-scan []<-[$$30, $$C] <- TestYelp.YelpCheckin
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-3-level-record-path/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-3-level-record-path/query2.plan
index d18b9b4..6e10c32 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-3-level-record-path/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-3-level-record-path/query2.plan
@@ -1,17 +1,34 @@
+distribute result [$$49]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$49])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$49] <- [{"$1": $$51}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$51] <- [agg-sql-sum($$56)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$56] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(gt($$D, "2016"), lt($$D, "2017")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$D <- scan-collection($$52)
                   -- UNNEST  |PARTITIONED|
+                    project ([$$52])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$52] <- [$$C.getField(2).getField(0).getField(0).getField(0)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$C])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                            data-scan []<-[$$50, $$C] <- TestYelp.YelpCheckin
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-composite-pk/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-composite-pk/query1.plan
index 070c67b..227b792 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-composite-pk/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-composite-pk/query1.plan
@@ -1,15 +1,30 @@
+distribute result [$$26]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$26])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$26] <- [{"business_id": $$28}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$28])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq("2016-04-26 19:49:16", $$D))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$28, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$29)
               -- UNNEST  |PARTITIONED|
+                project ([$$28, $$29])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$29] <- [$$C.getField(2)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$28, $$C])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                        data-scan []<-[$$27, $$28, $$C] <- TestYelp.YelpCheckin
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-composite-pk/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-composite-pk/query2.plan
index d18b9b4..61fd70b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-composite-pk/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-composite-pk/query2.plan
@@ -1,17 +1,34 @@
+distribute result [$$46]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$46])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$46] <- [{"$1": $$49}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$49] <- [agg-sql-sum($$51)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$51] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(gt($$D, "2016"), lt($$D, "2017")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$D <- scan-collection($$50)
                   -- UNNEST  |PARTITIONED|
+                    project ([$$50])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$50] <- [$$C.getField(2)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$C])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                            data-scan []<-[$$47, $$48, $$C] <- TestYelp.YelpCheckin
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-composite-sk/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-composite-sk/query1.plan
index e92baf8..3fb480d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-composite-sk/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-composite-sk/query1.plan
@@ -1,16 +1,32 @@
+distribute result [$$32]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$32])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$32] <- [{"business_id": $$33}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$33])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and(eq("2016-04-26", $$D.getField(0)), eq("19:49:16", $$D.getField(1))))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$33, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$35)
               -- UNNEST  |PARTITIONED|
+                select (eq("--1UhMGODdWsrMastO9DZw", $$33))
                 -- STREAM_SELECT  |PARTITIONED|
+                  project ([$$33, $$35])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$33, $$35] <- [$$C.getField(1), $$C.getField(2)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$C])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                          data-scan []<-[$$34, $$C] <- TestYelp.YelpCheckin
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-composite-sk/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-composite-sk/query2.plan
index 5e46297..8824380 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-composite-sk/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-composite-sk/query2.plan
@@ -1,19 +1,38 @@
+distribute result [$$48]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$48])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$48] <- [{"$1": $$51}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$51] <- [agg-sql-sum($$53)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$53] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(gt($$49, "2016"), lt($$49, "2017")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$49])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$49] <- [$$D.getField(0)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$D])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      unnest $$D <- scan-collection($$52)
                       -- UNNEST  |PARTITIONED|
+                        project ([$$52])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$52] <- [$$C.getField(2)]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$C])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                                data-scan []<-[$$50, $$C] <- TestYelp.YelpCheckin
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-filter-fields/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-filter-fields/query1.plan
index a224a0e..e63f32d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-filter-fields/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-filter-fields/query1.plan
@@ -1,17 +1,34 @@
+distribute result [$$29]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$29])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$29] <- [{"business_id": $$30}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$30])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq("2016-04-26 19:49:16", $$D))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$30, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$32)
               -- UNNEST  |PARTITIONED|
+                select (eq($$30, "--1UhMGODdWsrMastO9DZw"))
                 -- STREAM_SELECT  |PARTITIONED|
+                  project ([$$30, $$32])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$30, $$32] <- [$$C.getField(1), $$C.getField(2)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$C])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                          data-scan []<-[$$31, $$C] <- TestYelp.YelpCheckin with filter on min:[$$33] max:[$$33]
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                              assign [$$33] <- ["--1UhMGODdWsrMastO9DZw"]
                               -- ASSIGN  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-filter-fields/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-filter-fields/query2.plan
index d18b9b4..10f69e4 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-filter-fields/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/closed/with-filter-fields/query2.plan
@@ -1,17 +1,34 @@
+distribute result [$$46]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$46])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$46] <- [{"$1": $$48}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$48] <- [agg-sql-sum($$50)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$50] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(gt($$D, "2016"), lt($$D, "2017")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$D <- scan-collection($$49)
                   -- UNNEST  |PARTITIONED|
+                    project ([$$49])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$49] <- [$$C.getField(2)]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$C])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                            data-scan []<-[$$47, $$C] <- TestYelp.YelpCheckin
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query1.plan
index 30d30c6..b4e17d1 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query1.plan
@@ -1,13 +1,26 @@
+distribute result [$$27]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$27])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$27] <- [{"D": $$D, "F": $$F}]
       -- ASSIGN  |PARTITIONED|
+        select (gt($$F.getField("open_field_3a"), 0))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$D, $$F])
           -- STREAM_PROJECT  |PARTITIONED|
+            unnest $$F <- scan-collection($$29)
             -- UNNEST  |PARTITIONED|
+              assign [$$29] <- [$$D.getField("open_field_1").getField("open_field_2")]
               -- ASSIGN  |PARTITIONED|
+                project ([$$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- DATASOURCE_SCAN (TestDataverse.TestDataset)  |PARTITIONED|
+                    data-scan []<-[$$28, $$D] <- TestDataverse.TestDataset
+                    -- DATASOURCE_SCAN  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query2.plan
index 30d30c6..b389d4a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query2.plan
@@ -1,13 +1,26 @@
+distribute result [$$28]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$28])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$28] <- [{"D": $$D, "F": $$F}]
       -- ASSIGN  |PARTITIONED|
+        select (gt($$F.getField("open_field_3b").getField("open_field_4"), 0))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$D, $$F])
           -- STREAM_PROJECT  |PARTITIONED|
+            unnest $$F <- scan-collection($$30)
             -- UNNEST  |PARTITIONED|
+              assign [$$30] <- [$$D.getField("open_field_1").getField("open_field_2")]
               -- ASSIGN  |PARTITIONED|
+                project ([$$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- DATASOURCE_SCAN (TestDataverse.TestDataset)  |PARTITIONED|
+                    data-scan []<-[$$29, $$D] <- TestDataverse.TestDataset
+                    -- DATASOURCE_SCAN  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query3.plan
index 4cbcbbd..c1f37d8 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query3.plan
@@ -1,16 +1,32 @@
+distribute result [$$38]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$38])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$38] <- [{"D": $$D, "F1": $$F1, "F2": $$F2}]
       -- ASSIGN  |PARTITIONED|
+        select (gt($$F2, 0))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$D, $$F1, $$F2])
           -- STREAM_PROJECT  |PARTITIONED|
+            unnest $$F2 <- scan-collection($$41)
             -- UNNEST  |PARTITIONED|
+              assign [$$41] <- [$$F1.getField("open_field_3c").getField("open_field_4a")]
               -- ASSIGN  |PARTITIONED|
+                project ([$$D, $$F1])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$F1 <- scan-collection($$40)
                   -- UNNEST  |PARTITIONED|
+                    assign [$$40] <- [$$D.getField("open_field_1").getField("open_field_2")]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$D])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (TestDataverse.TestDataset)  |PARTITIONED|
+                          data-scan []<-[$$39, $$D] <- TestDataverse.TestDataset
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query4.plan
index 4cbcbbd..b6a4ba6 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query4.plan
@@ -1,16 +1,32 @@
+distribute result [$$39]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$39])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$39] <- [{"D": $$D, "F1": $$F1, "F2": $$F2}]
       -- ASSIGN  |PARTITIONED|
+        select (gt($$F2.getField("open_field_5"), 0))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$D, $$F1, $$F2])
           -- STREAM_PROJECT  |PARTITIONED|
+            unnest $$F2 <- scan-collection($$42)
             -- UNNEST  |PARTITIONED|
+              assign [$$42] <- [$$F1.getField("open_field_3c").getField("open_field_4b")]
               -- ASSIGN  |PARTITIONED|
+                project ([$$D, $$F1])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$F1 <- scan-collection($$41)
                   -- UNNEST  |PARTITIONED|
+                    assign [$$41] <- [$$D.getField("open_field_1").getField("open_field_2")]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$D])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (TestDataverse.TestDataset)  |PARTITIONED|
+                          data-scan []<-[$$40, $$D] <- TestDataverse.TestDataset
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query5.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query5.plan
index 30d30c6..b481983 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query5.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query5.plan
@@ -1,13 +1,26 @@
+distribute result [$$27]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$27])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$27] <- [{"D": $$D, "F": $$F}]
       -- ASSIGN  |PARTITIONED|
+        select (gt($$F.getField("open_field_3a"), 0))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$D, $$F])
           -- STREAM_PROJECT  |PARTITIONED|
+            unnest $$F <- scan-collection($$29)
             -- UNNEST  |PARTITIONED|
+              assign [$$29] <- [$$D.getField(1).getField("open_field_2")]
               -- ASSIGN  |PARTITIONED|
+                project ([$$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- DATASOURCE_SCAN (TestDataverse.TestDataset)  |PARTITIONED|
+                    data-scan []<-[$$28, $$D] <- TestDataverse.TestDataset
+                    -- DATASOURCE_SCAN  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query6.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query6.plan
index 30d30c6..61da21f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query6.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query6.plan
@@ -1,13 +1,26 @@
+distribute result [$$28]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$28])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$28] <- [{"D": $$D, "F": $$F}]
       -- ASSIGN  |PARTITIONED|
+        select (gt($$F.getField("open_field_3b").getField("open_field_4"), 0))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$D, $$F])
           -- STREAM_PROJECT  |PARTITIONED|
+            unnest $$F <- scan-collection($$30)
             -- UNNEST  |PARTITIONED|
+              assign [$$30] <- [$$D.getField(1).getField(0)]
               -- ASSIGN  |PARTITIONED|
+                project ([$$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- DATASOURCE_SCAN (TestDataverse.TestDataset)  |PARTITIONED|
+                    data-scan []<-[$$29, $$D] <- TestDataverse.TestDataset
+                    -- DATASOURCE_SCAN  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query7.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query7.plan
index 4cbcbbd..6ccafe4 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query7.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query7.plan
@@ -1,16 +1,32 @@
+distribute result [$$38]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$38])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$38] <- [{"D": $$D, "F1": $$F1, "F2": $$F2}]
       -- ASSIGN  |PARTITIONED|
+        select (gt($$F2, 0))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$D, $$F1, $$F2])
           -- STREAM_PROJECT  |PARTITIONED|
+            unnest $$F2 <- scan-collection($$41)
             -- UNNEST  |PARTITIONED|
+              assign [$$41] <- [$$F1.getField(0).getField("open_field_4a")]
               -- ASSIGN  |PARTITIONED|
+                project ([$$D, $$F1])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$F1 <- scan-collection($$40)
                   -- UNNEST  |PARTITIONED|
+                    assign [$$40] <- [$$D.getField(1).getField(0)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$D])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (TestDataverse.TestDataset)  |PARTITIONED|
+                          data-scan []<-[$$39, $$D] <- TestDataverse.TestDataset
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query8.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query8.plan
index 4cbcbbd..7bfdf9f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query8.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/complex-structures/query8.plan
@@ -1,16 +1,32 @@
+distribute result [$$39]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$39])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$39] <- [{"D": $$D, "F1": $$F1, "F2": $$F2}]
       -- ASSIGN  |PARTITIONED|
+        select (gt($$F2.getField("open_field_5"), 0))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$D, $$F1, $$F2])
           -- STREAM_PROJECT  |PARTITIONED|
+            unnest $$F2 <- scan-collection($$42)
             -- UNNEST  |PARTITIONED|
+              assign [$$42] <- [$$F1.getField(0).getField(0)]
               -- ASSIGN  |PARTITIONED|
+                project ([$$D, $$F1])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$F1 <- scan-collection($$41)
                   -- UNNEST  |PARTITIONED|
+                    assign [$$41] <- [$$D.getField(1).getField(0)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$D])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (TestDataverse.TestDataset)  |PARTITIONED|
+                          data-scan []<-[$$40, $$D] <- TestDataverse.TestDataset
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/multiple-indexes/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/multiple-indexes/query1.plan
index 8a0bc58..c2eabb6 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/multiple-indexes/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/multiple-indexes/query1.plan
@@ -1,13 +1,26 @@
+distribute result [$$29]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$29])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$29] <- [{"k": $$k, "v": $$v}]
       -- ASSIGN  |PARTITIONED|
+        select (and(eq($$v.getField("a"), 284), eq($$v.getField("b"), 263)))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$k, $$v])
           -- STREAM_PROJECT  |PARTITIONED|
+            unnest $$v <- scan-collection($$31)
             -- UNNEST  |PARTITIONED|
+              assign [$$31] <- [$$k.getField("uarr_i")]
               -- ASSIGN  |PARTITIONED|
+                project ([$$k])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- DATASOURCE_SCAN (test.KSI)  |PARTITIONED|
+                    data-scan []<-[$$30, $$k] <- test.KSI
+                    -- DATASOURCE_SCAN  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/multiple-indexes/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/multiple-indexes/query2.plan
index 8a0bc58..cda2f8a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/multiple-indexes/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/multiple-indexes/query2.plan
@@ -1,13 +1,26 @@
+distribute result [$$31]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$31])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$31] <- [{"k": $$k, "v": $$v}]
       -- ASSIGN  |PARTITIONED|
+        select (and(eq($$v.getField("a"), 284), eq($$v.getField("b"), 263), eq($$v.getField("c"), 123)))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$k, $$v])
           -- STREAM_PROJECT  |PARTITIONED|
+            unnest $$v <- scan-collection($$33)
             -- UNNEST  |PARTITIONED|
+              assign [$$33] <- [$$k.getField("uarr_i")]
               -- ASSIGN  |PARTITIONED|
+                project ([$$k])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- DATASOURCE_SCAN (test.KSI)  |PARTITIONED|
+                    data-scan []<-[$$32, $$k] <- test.KSI
+                    -- DATASOURCE_SCAN  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-1/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-1/query1.plan
index 834d7d2..38887ec 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-1/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-1/query1.plan
@@ -1,14 +1,28 @@
+distribute result [$$26]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$26])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$26] <- [{"business_id": $$C.getField("business_id")}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$C])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq("2016-04-26 19:49:16", $$D))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$C, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$28)
               -- UNNEST  |PARTITIONED|
+                assign [$$28] <- [$$C.getField("dates")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$C])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                      data-scan []<-[$$27, $$C] <- TestYelp.YelpCheckin
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-1/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-1/query2.plan
index d18b9b4..9235807 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-1/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-1/query2.plan
@@ -1,17 +1,34 @@
+distribute result [$$46]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$46])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$46] <- [{"$1": $$48}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$48] <- [agg-sql-sum($$50)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$50] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(gt($$D, "2016"), lt($$D, "2017")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$D <- scan-collection($$49)
                   -- UNNEST  |PARTITIONED|
+                    project ([$$49])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$49] <- [$$C.getField("dates")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$C])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                            data-scan []<-[$$47, $$C] <- TestYelp.YelpCheckin
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-2/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-2/query1.plan
index 834d7d2..8e93c6b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-2/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-2/query1.plan
@@ -1,14 +1,28 @@
+distribute result [$$27]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$27])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$27] <- [{"business_id": $$C.getField("business_id")}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$C])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq("2016-04-26", $$D))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$C, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$29)
               -- UNNEST  |PARTITIONED|
+                assign [$$29] <- [$$C.getField("checkin_times").getField("dates")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$C])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                      data-scan []<-[$$28, $$C] <- TestYelp.YelpCheckin
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-2/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-2/query2.plan
index d18b9b4..10e49d5 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-2/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-2/query2.plan
@@ -1,17 +1,34 @@
+distribute result [$$47]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$47])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$47] <- [{"$1": $$49}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$49] <- [agg-sql-sum($$52)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$52] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(gt($$D, "2016"), lt($$D, "2017")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$D <- scan-collection($$50)
                   -- UNNEST  |PARTITIONED|
+                    project ([$$50])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$50] <- [$$C.getField("checkin_times").getField("dates")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$C])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                            data-scan []<-[$$48, $$C] <- TestYelp.YelpCheckin
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-3/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-3/query1.plan
index 834d7d2..f9c638b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-3/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-3/query1.plan
@@ -1,14 +1,28 @@
+distribute result [$$27]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$27])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$27] <- [{"business_id": $$C.getField("business_id")}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$C])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq("2016-04-26", $$D.getField("date")))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$C, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$29)
               -- UNNEST  |PARTITIONED|
+                assign [$$29] <- [$$C.getField("checkin_times")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$C])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                      data-scan []<-[$$28, $$C] <- TestYelp.YelpCheckin
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-3/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-3/query2.plan
index 5e46297..6eefc74 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-3/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-3/query2.plan
@@ -1,19 +1,38 @@
+distribute result [$$48]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$48])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$48] <- [{"$1": $$51}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$51] <- [agg-sql-sum($$53)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$53] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(gt($$49, "2016"), lt($$49, "2017")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$49])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$49] <- [$$D.getField("date")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$D])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      unnest $$D <- scan-collection($$52)
                       -- UNNEST  |PARTITIONED|
+                        project ([$$52])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$52] <- [$$C.getField("checkin_times")]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$C])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                                data-scan []<-[$$50, $$C] <- TestYelp.YelpCheckin
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-3/query3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-3/query3.plan
index 834d7d2..3c1fa34 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-3/query3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-3/query3.plan
@@ -1,14 +1,28 @@
+distribute result [$$30]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$30])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$30] <- [{"business_id": $$C.getField("business_id")}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$C])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and(eq("2016-04-26", $$D.getField("date")), eq($$D.getField("time"), "19:49:16")))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$C, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$32)
               -- UNNEST  |PARTITIONED|
+                assign [$$32] <- [$$C.getField("checkin_times")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$C])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                      data-scan []<-[$$31, $$C] <- TestYelp.YelpCheckin
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-4/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-4/query1.plan
index 7c44281..eb7a6f2 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-4/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-4/query1.plan
@@ -1,18 +1,36 @@
+distribute result [$$37]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$37])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$37] <- [{"business_id": $$C.getField("business_id")}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$C])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq("2016-04-26", $$D))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$C, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$40)
               -- UNNEST  |PARTITIONED|
+                project ([$$C, $$40])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$40] <- [$$CT.getField("dates")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$C, $$CT])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      unnest $$CT <- scan-collection($$39)
                       -- UNNEST  |PARTITIONED|
+                        assign [$$39] <- [$$C.getField("checkin_times")]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$C])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                              data-scan []<-[$$38, $$C] <- TestYelp.YelpCheckin
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-4/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-4/query2.plan
index b191fe2..4a34bd8 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-4/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/use-case-4/query2.plan
@@ -1,21 +1,42 @@
+distribute result [$$57]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$57])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$57] <- [{"$1": $$59}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$59] <- [agg-sql-sum($$62)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$62] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(gt($$D, "2016"), lt($$D, "2017")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$D <- scan-collection($$61)
                   -- UNNEST  |PARTITIONED|
+                    project ([$$61])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$61] <- [$$CT.getField("dates")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$CT])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          unnest $$CT <- scan-collection($$60)
                           -- UNNEST  |PARTITIONED|
+                            project ([$$60])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$60] <- [$$C.getField("checkin_times")]
                               -- ASSIGN  |PARTITIONED|
+                                project ([$$C])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                                    data-scan []<-[$$58, $$C] <- TestYelp.YelpCheckin
+                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/with-3-level-record-path/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/with-3-level-record-path/query1.plan
index 834d7d2..2b4ecf3 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/with-3-level-record-path/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/with-3-level-record-path/query1.plan
@@ -1,14 +1,28 @@
+distribute result [$$29]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$29])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$29] <- [{"business_id": $$C.getField("business_id")}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$C])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq("2016-04-26", $$D))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$C, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$31)
               -- UNNEST  |PARTITIONED|
+                assign [$$31] <- [$$C.getField("checkin_data").getField("checkin_temporal").getField("checkin_times").getField("dates")]
                 -- ASSIGN  |PARTITIONED|
+                  project ([$$C])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                      data-scan []<-[$$30, $$C] <- TestYelp.YelpCheckin
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/with-3-level-record-path/query2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/with-3-level-record-path/query2.plan
index d18b9b4..fff79a5 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/with-3-level-record-path/query2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/with-3-level-record-path/query2.plan
@@ -1,17 +1,34 @@
+distribute result [$$49]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$49])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$49] <- [{"$1": $$51}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$51] <- [agg-sql-sum($$56)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$56] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (and(gt($$D, "2016"), lt($$D, "2017")))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$D])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  unnest $$D <- scan-collection($$52)
                   -- UNNEST  |PARTITIONED|
+                    project ([$$52])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$52] <- [$$C.getField("checkin_data").getField("checkin_temporal").getField("checkin_times").getField("dates")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$C])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                            data-scan []<-[$$50, $$C] <- TestYelp.YelpCheckin
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/with-composite-sk/query1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/with-composite-sk/query1.plan
index e92baf8..069093b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/with-composite-sk/query1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/array-index/select-unnest-queries/open/with-composite-sk/query1.plan
@@ -1,16 +1,32 @@
+distribute result [$$32]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$32])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$32] <- [{"business_id": $$33}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$33])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and(eq("2016-04-26", $$D.getField("date")), eq("19:49:16", $$D.getField("time"))))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$33, $$D])
             -- STREAM_PROJECT  |PARTITIONED|
+              unnest $$D <- scan-collection($$35)
               -- UNNEST  |PARTITIONED|
+                select (eq("--1UhMGODdWsrMastO9DZw", $$33))
                 -- STREAM_SELECT  |PARTITIONED|
+                  project ([$$33, $$35])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$33, $$35] <- [$$C.getField("business_id"), $$C.getField("checkin_times")]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$C])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (TestYelp.YelpCheckin)  |PARTITIONED|
+                          data-scan []<-[$$34, $$C] <- TestYelp.YelpCheckin
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-join/hints-indexnl-params/hints-indexnl-params-3.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-join/hints-indexnl-params/hints-indexnl-params-3.plan
index bd6d8cf..6b11c30 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-join/hints-indexnl-params/hints-indexnl-params-3.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-join/hints-indexnl-params/hints-indexnl-params-3.plan
@@ -1,25 +1,50 @@
+distribute result [$$37]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$37(ASC) ]  |PARTITIONED|
+    order (ASC, $$37)
     -- STABLE_SORT [$$37(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$37])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$34, $$tenk2.getField(7)))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$37] <- [$$tenk2.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$34, $$tenk2])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk2.tenk2)  |PARTITIONED|
+                  unnest-map [$$33, $$tenk2] <- index-search("tenk2", 0, "test", "tenk2", true, false, 1, $$42, 1, $$42, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$42)
                       -- STABLE_SORT [$$42(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$34, $$42])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.tenk2.idx_tenk2_1k)  |PARTITIONED|
+                              unnest-map [$$41, $$42] <- index-search("idx_tenk2_1k", 0, "test", "tenk2", true, true, 1, $$34, 1, $$34, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                  project ([$$34])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$34] <- [$$tenk1.getField(7)]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$tenk1])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (test.tenk1.tenk1)  |PARTITIONED|
+                                          unnest-map [$$32, $$tenk1] <- index-search("tenk1", 0, "test", "tenk1", false, false, 0, 1, $$38, true, false, false)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$38] <- [1]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-join/hints-indexnl-params/hints-indexnl-params-5.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-join/hints-indexnl-params/hints-indexnl-params-5.plan
index bd6d8cf..6b11c30 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-join/hints-indexnl-params/hints-indexnl-params-5.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-join/hints-indexnl-params/hints-indexnl-params-5.plan
@@ -1,25 +1,50 @@
+distribute result [$$37]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$37(ASC) ]  |PARTITIONED|
+    order (ASC, $$37)
     -- STABLE_SORT [$$37(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$37])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$34, $$tenk2.getField(7)))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$37] <- [$$tenk2.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$34, $$tenk2])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk2.tenk2)  |PARTITIONED|
+                  unnest-map [$$33, $$tenk2] <- index-search("tenk2", 0, "test", "tenk2", true, false, 1, $$42, 1, $$42, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$42)
                       -- STABLE_SORT [$$42(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$34, $$42])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.tenk2.idx_tenk2_1k)  |PARTITIONED|
+                              unnest-map [$$41, $$42] <- index-search("idx_tenk2_1k", 0, "test", "tenk2", true, true, 1, $$34, 1, $$34, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                  project ([$$34])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$34] <- [$$tenk1.getField(7)]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$tenk1])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (test.tenk1.tenk1)  |PARTITIONED|
+                                          unnest-map [$$32, $$tenk1] <- index-search("tenk1", 0, "test", "tenk1", false, false, 0, 1, $$38, true, false, false)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$38] <- [1]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-join/hints-indexnl-params/hints-indexnl-params-6.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-join/hints-indexnl-params/hints-indexnl-params-6.plan
index b6b4ba0..550f5cc 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-join/hints-indexnl-params/hints-indexnl-params-6.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-join/hints-indexnl-params/hints-indexnl-params-6.plan
@@ -1,24 +1,48 @@
+distribute result [$$37]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$37(ASC) ]  |PARTITIONED|
+    order (ASC, $$37)
     -- STABLE_SORT [$$37(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$37])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$34, $$35))
             -- HYBRID_HASH_JOIN [$$35][$$34]  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$35]  |PARTITIONED|
+                project ([$$37, $$35])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$37, $$35] <- [$$tenk2.getField(0), $$tenk2.getField(7)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$tenk2])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.tenk2)  |PARTITIONED|
+                        data-scan []<-[$$33, $$tenk2] <- test.tenk2
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$34]  |PARTITIONED|
+                project ([$$34])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$34] <- [$$tenk1.getField(7)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$tenk1])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- BTREE_SEARCH (test.tenk1.tenk1)  |PARTITIONED|
+                        unnest-map [$$32, $$tenk1] <- index-search("tenk1", 0, "test", "tenk1", false, false, 0, 1, $$38, true, false, false)
+                        -- BTREE_SEARCH  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            assign [$$38] <- [1]
                             -- ASSIGN  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-join/hints-indexnl-params/hints-indexnl-params-7.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-join/hints-indexnl-params/hints-indexnl-params-7.plan
index bd6d8cf..6b11c30 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-join/hints-indexnl-params/hints-indexnl-params-7.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-join/hints-indexnl-params/hints-indexnl-params-7.plan
@@ -1,25 +1,50 @@
+distribute result [$$37]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$37(ASC) ]  |PARTITIONED|
+    order (ASC, $$37)
     -- STABLE_SORT [$$37(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$37])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$34, $$tenk2.getField(7)))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$37] <- [$$tenk2.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$34, $$tenk2])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- BTREE_SEARCH (test.tenk2.tenk2)  |PARTITIONED|
+                  unnest-map [$$33, $$tenk2] <- index-search("tenk2", 0, "test", "tenk2", true, false, 1, $$42, 1, $$42, true, true, true)
+                  -- BTREE_SEARCH  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      order (ASC, $$42)
                       -- STABLE_SORT [$$42(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$34, $$42])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (test.tenk2.idx_tenk2_1k)  |PARTITIONED|
+                              unnest-map [$$41, $$42] <- index-search("idx_tenk2_1k", 0, "test", "tenk2", true, true, 1, $$34, 1, $$34, true, true, true)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                  project ([$$34])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$34] <- [$$tenk1.getField(7)]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$tenk1])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- BTREE_SEARCH (test.tenk1.tenk1)  |PARTITIONED|
+                                          unnest-map [$$32, $$tenk1] <- index-search("tenk1", 0, "test", "tenk1", false, false, 0, 1, $$38, true, false, false)
+                                          -- BTREE_SEARCH  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              assign [$$38] <- [1]
                                               -- ASSIGN  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/btree-index-composite-key-04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/btree-index-composite-key-04.plan
index ce1677d..d372af9 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/btree-index-composite-key-04.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/btree-index-composite-key-04.plan
@@ -1,12 +1,24 @@
+distribute result [$$18]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$18])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$18] <- [{"id": $$21, "fname": $$20, "lname": $$24}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$21(ASC) ]  |PARTITIONED|
+          select (eq($$20, "A"))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$21, $$24, $$20])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$24, $$20] <- [$$employee.getField(2), $$employee.getField(1)]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.employee)  |PARTITIONED|
+                  data-scan []<-[$$21, $$employee] <- test.employee
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-02.plan
index a41ba60..f115987 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-02.plan
@@ -1,12 +1,24 @@
+distribute result [$$56]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$56])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$56] <- [{"id": $$59, "x": $$70, "y": int64-default-null($$62)}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$59(ASC) ]  |PARTITIONED|
+          select (le($$70, 1))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$59, $$70, $$62])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$70, $$62] <- [int64-default-null($$ds2.getField("x")), $$ds2.getField("y")]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.ds2)  |PARTITIONED|
+                  data-scan []<-[$$59, $$ds2] <- test.ds2
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-10.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-10.plan
index 753d23d..79593a2 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-10.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-10.plan
@@ -1,12 +1,24 @@
+distribute result [$$42]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$42])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$42] <- [{"id": $$48, "f_dt_fmt": $$57}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$48(ASC) ]  |PARTITIONED|
+          select (lt($$57, datetime: { 2020-12-20T00:00:00.000 }))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$48, $$57])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$57] <- [datetime-default-null($$ds5.getField("f_dt_fmt"), "MM/DD/YYYY hh:mm:ss.nnna")]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.ds5)  |PARTITIONED|
+                  data-scan []<-[$$48, $$ds5] <- test.ds5
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-11.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-11.plan
index 753d23d..99d2b68 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-11.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-11.plan
@@ -1,12 +1,24 @@
+distribute result [$$42]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$42])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$42] <- [{"id": $$48, "f_d_fmt": $$57}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$48(ASC) ]  |PARTITIONED|
+          select (lt($$57, date: { 2020-12-20 }))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$48, $$57])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$57] <- [date-default-null($$ds5.getField("f_d_fmt"), "MM/DD/YYYY")]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.ds5)  |PARTITIONED|
+                  data-scan []<-[$$48, $$ds5] <- test.ds5
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-12.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-12.plan
index 753d23d..7e4f90a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-12.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-12.plan
@@ -1,12 +1,24 @@
+distribute result [$$42]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$42])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$42] <- [{"id": $$48, "f_t_fmt": $$57}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$48(ASC) ]  |PARTITIONED|
+          select (lt($$57, time: { 18:13:03.000 }))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$48, $$57])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$57] <- [time-default-null($$ds5.getField("f_t_fmt"), "hh:mm:ss.nnna")]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.ds5)  |PARTITIONED|
+                  data-scan []<-[$$48, $$ds5] <- test.ds5
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-13.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-13.plan
index f6647d4..f7de447 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-13.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-13.plan
@@ -1,12 +1,24 @@
+distribute result [$$42]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$42])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$42] <- [{"id": $$48, "f_dt": $$57}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$48(ASC) ]  |PARTITIONED|
+          select (lt($$57, datetime: { 2020-12-20T00:00:00.000 }))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$48, $$57])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$57] <- [datetime-default-null($$ds6.getField("f_dt"))]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.ds6)  |PARTITIONED|
+                  data-scan []<-[$$48, $$ds6] <- test.ds6
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-14.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-14.plan
index f6647d4..ee97f2a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-14.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-14.plan
@@ -1,12 +1,24 @@
+distribute result [$$42]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$42])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$42] <- [{"id": $$48, "f_d": $$57}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$48(ASC) ]  |PARTITIONED|
+          select (lt($$57, date: { 2020-12-20 }))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$48, $$57])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$57] <- [date-default-null($$ds6.getField("f_d"))]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.ds6)  |PARTITIONED|
+                  data-scan []<-[$$48, $$ds6] <- test.ds6
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-15.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-15.plan
index f6647d4..3df08dd 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-15.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-15.plan
@@ -1,12 +1,24 @@
+distribute result [$$42]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$42])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$42] <- [{"id": $$48, "f_t": $$57}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$48(ASC) ]  |PARTITIONED|
+          select (lt($$57, time: { 18:13:03.000 }))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$48, $$57])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$57] <- [time-default-null($$ds6.getField("f_t"))]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.ds6)  |PARTITIONED|
+                  data-scan []<-[$$48, $$ds6] <- test.ds6
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-20.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-20.plan
index e5fd2d4..fd18cf4 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-20.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-20.plan
@@ -1,12 +1,24 @@
+distribute result [$$55]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$55])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$55] <- [{"id": $$58, "s_f2": $$68}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$58(ASC) ]  |PARTITIONED|
+          select (lt($$68, "4"))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$58, $$68])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$68] <- [string-default-null($$ds7.getField(2))]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.ds7)  |PARTITIONED|
+                  data-scan []<-[$$58, $$ds7] <- test.ds7
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-23.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-23.plan
index e5fd2d4..e8844db 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-23.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-23.plan
@@ -1,12 +1,24 @@
+distribute result [$$55]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$55])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$55] <- [{"id": $$58, "s_f2": $$68}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$58(ASC) ]  |PARTITIONED|
+          select (lt($$68, 4))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$58, $$68])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$68] <- [int64-default-null($$ds7.getField(2))]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.ds7)  |PARTITIONED|
+                  data-scan []<-[$$58, $$ds7] <- test.ds7
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-24.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-24.plan
index c587ffb..e0fce8e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-24.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-24.plan
@@ -1,12 +1,24 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$17] <- [{"id": $$20, "s_f2": $$19}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$20(ASC) ]  |PARTITIONED|
+          select (lt($$19, "4"))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$20, $$19])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$19] <- [$$ds7.getField(2)]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.ds7)  |PARTITIONED|
+                  data-scan []<-[$$20, $$ds7] <- test.ds7
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-25.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-25.plan
index e5fd2d4..4ed2747 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-25.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/cast-default-null/cast-default-null-25.plan
@@ -1,12 +1,24 @@
+distribute result [$$55]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$55])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$55] <- [{"id": $$58, "s_f2": $$60}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$58(ASC) ]  |PARTITIONED|
+          select (lt($$60, "4"))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$58, $$60])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$60] <- [$$ds7.getField(2)]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.ds7)  |PARTITIONED|
+                  data-scan []<-[$$58, $$ds7] <- test.ds7
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/disjunctive-predicate/disjunctive-predicate-1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/disjunctive-predicate/disjunctive-predicate-1.plan
index 61695a3..57cca6f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/disjunctive-predicate/disjunctive-predicate-1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/disjunctive-predicate/disjunctive-predicate-1.plan
@@ -1,12 +1,24 @@
+distribute result [$$x]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$x])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        join (eq($$21, $$20))
         -- HYBRID_HASH_JOIN [$$20][$$21]  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- DATASOURCE_SCAN (test.TestSet)  |PARTITIONED|
+            data-scan []<-[$$20, $$x] <- test.TestSet
+            -- DATASOURCE_SCAN  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                empty-tuple-source
                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+          exchange
           -- BROADCAST_EXCHANGE  |PARTITIONED|
+            unnest $$21 <- scan-collection(array: [ "one", "two" ])
             -- UNNEST  |UNPARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/disjunctive-predicate/disjunctive-predicate-2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/disjunctive-predicate/disjunctive-predicate-2.plan
index 318f7d5..f1126e3 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/disjunctive-predicate/disjunctive-predicate-2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/disjunctive-predicate/disjunctive-predicate-2.plan
@@ -1,15 +1,30 @@
+distribute result [$$x]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$x])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        join (eq($$21, $$19))
         -- HYBRID_HASH_JOIN [$$19][$$21]  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            assign [$$19] <- [$$x.getField(1)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$x])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.TestSet)  |PARTITIONED|
+                  data-scan []<-[$$20, $$x] <- test.TestSet
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+          exchange
           -- BROADCAST_EXCHANGE  |PARTITIONED|
+            unnest $$21 <- scan-collection(array: [ "one", "two" ])
             -- UNNEST  |UNPARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-10.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-10.plan
index c266c21..b4793ca 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-10.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-10.plan
@@ -1,12 +1,24 @@
+distribute result [$$19]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$19(ASC) ]  |PARTITIONED|
+    order (ASC, $$19)
     -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$19])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$tenk.getField(7), 0))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$19] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                  data-scan []<-[$$17, $$tenk] <- test.tenk
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-11.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-11.plan
deleted file mode 100644
index a2a9642..0000000
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-11.plan
+++ /dev/null
@@ -1,18 +0,0 @@
--- DISTRIBUTE_RESULT  |PARTITIONED|
-  -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
-    -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
-      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-        -- STREAM_PROJECT  |PARTITIONED|
-          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- HYBRID_HASH_JOIN [$$20][$$22]  |PARTITIONED|
-              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- STREAM_PROJECT  |PARTITIONED|
-                  -- ASSIGN  |PARTITIONED|
-                    -- STREAM_PROJECT  |PARTITIONED|
-                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
-                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-              -- BROADCAST_EXCHANGE  |PARTITIONED|
-                -- UNNEST  |UNPARTITIONED|
-                  -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-12.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-12.plan
index a2a9642..4d1a7c7 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-12.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-12.plan
@@ -1,18 +1,36 @@
+distribute result [$$23]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+    order (ASC, $$23)
     -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$23])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$22, $$20))
             -- HYBRID_HASH_JOIN [$$20][$$22]  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$23, $$20])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$23, $$20] <- [$$tenk.getField(0), $$tenk.getField(7)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$tenk])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                        data-scan []<-[$$21, $$tenk] <- test.tenk
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                unnest $$22 <- scan-collection(array: [ 0, 1 ])
                 -- UNNEST  |UNPARTITIONED|
+                  empty-tuple-source
                   -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-13.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-13.plan
index c266c21..b4793ca 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-13.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-13.plan
@@ -1,12 +1,24 @@
+distribute result [$$19]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$19(ASC) ]  |PARTITIONED|
+    order (ASC, $$19)
     -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$19])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$tenk.getField(7), 0))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$19] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                  data-scan []<-[$$17, $$tenk] <- test.tenk
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-4.plan
index c266c21..b4793ca 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-4.plan
@@ -1,12 +1,24 @@
+distribute result [$$19]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$19(ASC) ]  |PARTITIONED|
+    order (ASC, $$19)
     -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$19])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$tenk.getField(7), 0))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$19] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                  data-scan []<-[$$17, $$tenk] <- test.tenk
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-6.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-6.plan
index 86e54c9..d8276e8 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-6.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-6.plan
@@ -1,12 +1,24 @@
+distribute result [$$23]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+    order (ASC, $$23)
     -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$23])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and(eq($$tenk.getField(7), 0), eq($$tenk.getField(8), 0)))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$23] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                  data-scan []<-[$$20, $$tenk] <- test.tenk
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-7.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-7.plan
index 86e54c9..d8276e8 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-7.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-7.plan
@@ -1,12 +1,24 @@
+distribute result [$$23]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+    order (ASC, $$23)
     -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$23])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and(eq($$tenk.getField(7), 0), eq($$tenk.getField(8), 0)))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$23] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                  data-scan []<-[$$20, $$tenk] <- test.tenk
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-8.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-8.plan
index 86e54c9..d8276e8 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-8.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-8.plan
@@ -1,12 +1,24 @@
+distribute result [$$23]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+    order (ASC, $$23)
     -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$23])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and(eq($$tenk.getField(7), 0), eq($$tenk.getField(8), 0)))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$23] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                  data-scan []<-[$$20, $$tenk] <- test.tenk
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-9.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-9.plan
index c266c21..b4793ca 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-9.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-skip-index/hints-skip-index-9.plan
@@ -1,12 +1,24 @@
+distribute result [$$19]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$19(ASC) ]  |PARTITIONED|
+    order (ASC, $$19)
     -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$19])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$tenk.getField(7), 0))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$19] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                  data-scan []<-[$$17, $$tenk] <- test.tenk
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-use-index/hints-use-index-18.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-use-index/hints-use-index-18.plan
index c266c21..b4793ca 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-use-index/hints-use-index-18.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-use-index/hints-use-index-18.plan
@@ -1,12 +1,24 @@
+distribute result [$$19]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$19(ASC) ]  |PARTITIONED|
+    order (ASC, $$19)
     -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$19])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$tenk.getField(7), 0))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$19] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                  data-scan []<-[$$17, $$tenk] <- test.tenk
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-use-index/hints-use-index-19.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-use-index/hints-use-index-19.plan
index c266c21..b4793ca 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-use-index/hints-use-index-19.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-use-index/hints-use-index-19.plan
@@ -1,12 +1,24 @@
+distribute result [$$19]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$19(ASC) ]  |PARTITIONED|
+    order (ASC, $$19)
     -- STABLE_SORT [$$19(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$19])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$tenk.getField(7), 0))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$19] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                  data-scan []<-[$$17, $$tenk] <- test.tenk
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-use-index/hints-use-index-7.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-use-index/hints-use-index-7.plan
index 86e54c9..d8276e8 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-use-index/hints-use-index-7.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index-selection/hints-use-index/hints-use-index-7.plan
@@ -1,12 +1,24 @@
+distribute result [$$23]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+    order (ASC, $$23)
     -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        project ([$$23])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (and(eq($$tenk.getField(7), 0), eq($$tenk.getField(8), 0)))
           -- STREAM_SELECT  |PARTITIONED|
+            assign [$$23] <- [$$tenk.getField(0)]
             -- ASSIGN  |PARTITIONED|
+              project ([$$tenk])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.tenk)  |PARTITIONED|
+                  data-scan []<-[$$20, $$tenk] <- test.tenk
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-composite-key-03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-composite-key-03.plan
index e431bd0..2b77f25 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-composite-key-03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-composite-key-03.plan
@@ -1,8 +1,16 @@
+distribute result [$$l]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (and(eq($$l.getField(1), "Julio"), eq($$l.getField(2), "Isa")))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$l])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (test.employee)  |PARTITIONED|
+          data-scan []<-[$$17, $$l] <- test.employee
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-33.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-33.plan
index 5454dab..cfdfb0d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-33.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-33.plan
@@ -1,8 +1,16 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (gt($$emp.getField(1), "Roger"))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+          data-scan []<-[$$14, $$emp] <- test.testdst
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-34.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-34.plan
index 5454dab..c04d339 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-34.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-34.plan
@@ -1,8 +1,16 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (ge($$emp.getField(1), "Susan"))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+          data-scan []<-[$$14, $$emp] <- test.testdst
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-35.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-35.plan
index 5454dab..8ee67da 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-35.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-35.plan
@@ -1,8 +1,16 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (lt($$emp.getField(1), "Isa"))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+          data-scan []<-[$$14, $$emp] <- test.testdst
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-36.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-36.plan
index 5454dab..1f3784f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-36.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-36.plan
@@ -1,8 +1,16 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (le($$emp.getField(1), "Vanpatten"))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+          data-scan []<-[$$14, $$emp] <- test.testdst
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-40.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-40.plan
index 5454dab..d083382 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-40.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-40.plan
@@ -1,8 +1,16 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (and(eq($$emp.getField(1), "Young Seok"), eq($$emp.getField(2), "Kim")))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+          data-scan []<-[$$17, $$emp] <- test.testdst
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-42.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-42.plan
index 5454dab..abdc887 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-42.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-42.plan
@@ -1,8 +1,16 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (and(gt($$emp.getField(1), "Alex"), lt($$emp.getField(2), "Zach")))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+          data-scan []<-[$$17, $$emp] <- test.testdst
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-43.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-43.plan
index 5454dab..0806a13 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-43.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-43.plan
@@ -1,8 +1,16 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (and(gt($$emp.getField(1), "Allan"), lt($$emp.getField(2), "Zubi")))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+          data-scan []<-[$$17, $$emp] <- test.testdst
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-44.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-44.plan
index 5454dab..4562e83 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-44.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-44.plan
@@ -1,8 +1,16 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (and(gt($$emp.getField(1), "Allan"), eq($$emp.getField(2), "Xu")))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+          data-scan []<-[$$17, $$emp] <- test.testdst
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-45.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-45.plan
index 5454dab..eef6382 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-45.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-45.plan
@@ -1,8 +1,16 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (and(eq($$emp.getField(1), "Julio"), lt($$emp.getField(2), "Xu")))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+          data-scan []<-[$$17, $$emp] <- test.testdst
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-46.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-46.plan
index 5454dab..a6aea81 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-46.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-46.plan
@@ -1,8 +1,16 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (and(ge($$emp.getField(1), "Michael"), le($$emp.getField(2), "Xu")))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+          data-scan []<-[$$17, $$emp] <- test.testdst
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-47.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-47.plan
index 124330a..84a99b1 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-47.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-47.plan
@@ -1,10 +1,20 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$emp])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (and(lt($$21, "Tomes"), gt($$21, "Kevin"), gt($$22, "Craig"), lt($$22, "Mary")))
       -- STREAM_SELECT  |PARTITIONED|
+        assign [$$22, $$21] <- [$$emp.getField(1), $$emp.getField(2)]
         -- ASSIGN  |PARTITIONED|
+          project ([$$emp])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+              data-scan []<-[$$23, $$emp] <- test.testdst
+              -- DATASOURCE_SCAN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  empty-tuple-source
                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-48.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-48.plan
index 124330a..46e1271 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-48.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-48.plan
@@ -1,10 +1,20 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$emp])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (and(le($$21, "Tomes"), ge($$21, "Kevin"), ge($$22, "Craig"), le($$22, "Mary")))
       -- STREAM_SELECT  |PARTITIONED|
+        assign [$$22, $$21] <- [$$emp.getField(1), $$emp.getField(2)]
         -- ASSIGN  |PARTITIONED|
+          project ([$$emp])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+              data-scan []<-[$$23, $$emp] <- test.testdst
+              -- DATASOURCE_SCAN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  empty-tuple-source
                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-49.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-49.plan
index 5454dab..030cf4c 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-49.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-49.plan
@@ -1,8 +1,16 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (and(le($$emp.getField(1), "Craig"), gt($$emp.getField(2), "Kevin")))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+          data-scan []<-[$$17, $$emp] <- test.testdst
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-51.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-51.plan
index 124330a..fcbacfa 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-51.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-51.plan
@@ -1,10 +1,20 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$emp])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (and(le($$21, "Tomes"), gt($$21, "Kevin"), gt($$22, "Craig"), le($$22, "Mary")))
       -- STREAM_SELECT  |PARTITIONED|
+        assign [$$22, $$21] <- [$$emp.getField(1), $$emp.getField(2)]
         -- ASSIGN  |PARTITIONED|
+          project ([$$emp])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+              data-scan []<-[$$23, $$emp] <- test.testdst
+              -- DATASOURCE_SCAN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  empty-tuple-source
                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-52.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-52.plan
index 124330a..002d807 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-52.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-52.plan
@@ -1,10 +1,20 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$emp])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (and(lt($$21, "Tomes"), ge($$21, "Kevin"), ge($$22, "Craig"), lt($$22, "Mary")))
       -- STREAM_SELECT  |PARTITIONED|
+        assign [$$22, $$21] <- [$$emp.getField(1), $$emp.getField(2)]
         -- ASSIGN  |PARTITIONED|
+          project ([$$emp])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+              data-scan []<-[$$23, $$emp] <- test.testdst
+              -- DATASOURCE_SCAN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  empty-tuple-source
                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-53.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-53.plan
index 124330a..3e14fb4 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-53.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-53.plan
@@ -1,10 +1,20 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$emp])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (and(ge($$21, "Tomes"), le($$21, "Kevin"), ge($$22, "Craig"), le($$22, "Mary")))
       -- STREAM_SELECT  |PARTITIONED|
+        assign [$$22, $$21] <- [$$emp.getField(1), $$emp.getField(2)]
         -- ASSIGN  |PARTITIONED|
+          project ([$$emp])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+              data-scan []<-[$$23, $$emp] <- test.testdst
+              -- DATASOURCE_SCAN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  empty-tuple-source
                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-54.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-54.plan
index 5454dab..c012831 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-54.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-54.plan
@@ -1,8 +1,16 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (gt($$emp.getField(1), "Max"))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+          data-scan []<-[$$14, $$emp] <- test.testdst
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-55.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-55.plan
index 5454dab..382e307 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-55.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-55.plan
@@ -1,8 +1,16 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (ge($$emp.getField(1), "Sofia"))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+          data-scan []<-[$$14, $$emp] <- test.testdst
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-56.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-56.plan
index 5454dab..8866024 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-56.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-56.plan
@@ -1,8 +1,16 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (lt($$emp.getField(1), "Chen"))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+          data-scan []<-[$$14, $$emp] <- test.testdst
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-57.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-57.plan
index 5454dab..fb119cc 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-57.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-57.plan
@@ -1,8 +1,16 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (le($$emp.getField(1), "Julio"))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+          data-scan []<-[$$14, $$emp] <- test.testdst
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-58.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-58.plan
index 124330a..881586e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-58.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-58.plan
@@ -1,10 +1,20 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$emp])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (and(gt($$17, "Neil"), lt($$17, "Roger")))
       -- STREAM_SELECT  |PARTITIONED|
+        assign [$$17] <- [$$emp.getField(1)]
         -- ASSIGN  |PARTITIONED|
+          project ([$$emp])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+              data-scan []<-[$$18, $$emp] <- test.testdst
+              -- DATASOURCE_SCAN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  empty-tuple-source
                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-59.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-59.plan
index 124330a..d95595d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-59.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-59.plan
@@ -1,10 +1,20 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$emp])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (and(ge($$17, "Max"), le($$17, "Roger")))
       -- STREAM_SELECT  |PARTITIONED|
+        assign [$$17] <- [$$emp.getField(1)]
         -- ASSIGN  |PARTITIONED|
+          project ([$$emp])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+              data-scan []<-[$$18, $$emp] <- test.testdst
+              -- DATASOURCE_SCAN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  empty-tuple-source
                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-60.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-60.plan
index 5454dab..a6f2c2b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-60.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-60.plan
@@ -1,8 +1,16 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (eq($$emp.getField(1), "Max"))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+          data-scan []<-[$$14, $$emp] <- test.testdst
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-61.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-61.plan
index 124330a..bf59b3b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-61.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-61.plan
@@ -1,10 +1,20 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$emp])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (and(lt($$21, "Tomes"), gt($$21, "Kevin"), gt($$22, "Craig"), le($$22, "Mary")))
       -- STREAM_SELECT  |PARTITIONED|
+        assign [$$22, $$21] <- [$$emp.getField(1), $$emp.getField(2)]
         -- ASSIGN  |PARTITIONED|
+          project ([$$emp])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+              data-scan []<-[$$23, $$emp] <- test.testdst
+              -- DATASOURCE_SCAN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  empty-tuple-source
                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-62.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-62.plan
index 5454dab..46bccca 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-62.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-62.plan
@@ -1,8 +1,16 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (and(eq($$emp.getField(1), "Julio"), gt($$emp.getField(2), "Xu")))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+          data-scan []<-[$$17, $$emp] <- test.testdst
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-63.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-63.plan
index 5454dab..fcfb398 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-63.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-63.plan
@@ -1,8 +1,16 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (and(lt($$emp.getField(1), "Julio"), eq($$emp.getField(2), "Xu")))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+          data-scan []<-[$$17, $$emp] <- test.testdst
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-68.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-68.plan
index 4cd09cb..ec6e668 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-68.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-68.plan
@@ -1,14 +1,28 @@
+distribute result [$$24]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$24])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$24] <- [{"o_custkey": $$27, "o_orderkey": $$28, "o_orderstatus": $$33}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$27(ASC), $$28(ASC) ]  |PARTITIONED|
+          order (ASC, $$27) (ASC, $$28)
           -- STABLE_SORT [$$27(ASC), $$28(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$27, $$28, $$33])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (and(eq($$Orders.getField(5), "1-URGENT"), le($$27, 43), ge($$27, 40)))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$33, $$27] <- [$$Orders.getField(2), $$Orders.getField(1)]
                   -- ASSIGN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                      data-scan []<-[$$28, $$Orders] <- tpch.Orders
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-68_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-68_ps.plan
index c7a7d7c..2efa4b9 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-68_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-secondary-68_ps.plan
@@ -1,33 +1,66 @@
+distribute result [$$24]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$24])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$24] <- [{"o_custkey": $$27, "o_orderkey": $$28, "o_orderstatus": $$33}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$27) (ASC, $$28)
           -- STABLE_SORT [$$27(ASC), $$28(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$27(ASC), $$28(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$37
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$27, $$28, $$33])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (and(eq($$Orders.getField(5), "1-URGENT"), le($$27, 43), ge($$27, 40)))
                         -- STREAM_SELECT  |PARTITIONED|
+                          assign [$$33, $$27] <- [$$Orders.getField(2), $$Orders.getField(1)]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                              data-scan []<-[$$28, $$Orders] <- tpch.Orders
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$37] <- [agg-range-map($$34, $$35, $$36)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$34, $$35, $$36] <- [agg-local-sampling($$27, $$28), agg-null-writer($$27), agg-null-writer($$28)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$27, $$28])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$27, $$28, $$33])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  select (and(eq($$Orders.getField(5), "1-URGENT"), le($$27, 43), ge($$27, 40)))
                                   -- STREAM_SELECT  |PARTITIONED|
+                                    assign [$$33, $$27] <- [$$Orders.getField(2), $$Orders.getField(1)]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                                        data-scan []<-[$$28, $$Orders] <- tpch.Orders
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-sidx-idxonly-01-disable-idxonly.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-sidx-idxonly-01-disable-idxonly.plan
index 8dd4216..3d5788b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-sidx-idxonly-01-disable-idxonly.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-sidx-idxonly-01-disable-idxonly.plan
@@ -1,12 +1,24 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$17] <- [{"pk": $$20, "sk": $$19}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$20(ASC) ]  |PARTITIONED|
+          select (lt($$19, 3))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$20, $$19])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$19] <- [$$o.getField(1)]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.MyData)  |PARTITIONED|
+                  data-scan []<-[$$20, $$o] <- test.MyData
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-sidx-idxonly-01-disable-idxonly_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-sidx-idxonly-01-disable-idxonly_ps.plan
index 3ebae2c..c1e3603 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-sidx-idxonly-01-disable-idxonly_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-sidx-idxonly-01-disable-idxonly_ps.plan
@@ -1,33 +1,66 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$17] <- [{"pk": $$20, "sk": $$19}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$20(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$25
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      select (lt($$19, 3))
                       -- STREAM_SELECT  |PARTITIONED|
+                        project ([$$20, $$19])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$19] <- [$$o.getField(1)]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (test.MyData)  |PARTITIONED|
+                              data-scan []<-[$$20, $$o] <- test.MyData
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$25] <- [agg-range-map($$23, $$24)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$23, $$24] <- [agg-local-sampling($$20), agg-null-writer($$20)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$20])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                select (lt($$19, 3))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  project ([$$20, $$19])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$19] <- [$$o.getField(1)]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (test.MyData)  |PARTITIONED|
+                                        data-scan []<-[$$20, $$o] <- test.MyData
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-sidx-idxonly-01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-sidx-idxonly-01.plan
index 8dd4216..3d5788b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-sidx-idxonly-01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-sidx-idxonly-01.plan
@@ -1,12 +1,24 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$17] <- [{"pk": $$20, "sk": $$19}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$20(ASC) ]  |PARTITIONED|
+          select (lt($$19, 3))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$20, $$19])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$19] <- [$$o.getField(1)]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.MyData)  |PARTITIONED|
+                  data-scan []<-[$$20, $$o] <- test.MyData
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-sidx-idxonly-01_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-sidx-idxonly-01_ps.plan
index 3ebae2c..c1e3603 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-sidx-idxonly-01_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-sidx-idxonly-01_ps.plan
@@ -1,33 +1,66 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$17] <- [{"pk": $$20, "sk": $$19}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$20(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$25
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      select (lt($$19, 3))
                       -- STREAM_SELECT  |PARTITIONED|
+                        project ([$$20, $$19])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$19] <- [$$o.getField(1)]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (test.MyData)  |PARTITIONED|
+                              data-scan []<-[$$20, $$o] <- test.MyData
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$25] <- [agg-range-map($$23, $$24)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$23, $$24] <- [agg-local-sampling($$20), agg-null-writer($$20)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$20])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                select (lt($$19, 3))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  project ([$$20, $$19])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$19] <- [$$o.getField(1)]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (test.MyData)  |PARTITIONED|
+                                        data-scan []<-[$$20, $$o] <- test.MyData
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-sidx-idxonly-10.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-sidx-idxonly-10.plan
index 33aec0b..723aa71 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-sidx-idxonly-10.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-index/btree-sidx-idxonly-10.plan
@@ -1,15 +1,30 @@
+distribute result [$$70]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    aggregate [$$70] <- [agg-sql-sum($$77)]
     -- AGGREGATE  |UNPARTITIONED|
+      exchange
       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+        aggregate [$$77] <- [agg-sql-count(1)]
         -- AGGREGATE  |PARTITIONED|
+          select (and(ge($$66, 0), lt($$66, 1000000), lt($$71, date: { 2002-11-09 }), ge($$71, date: { 1997-05-19 })))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$66, $$71])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$66, $$71] <- [$$69.getField(10), $$69.getField(6)]
               -- ASSIGN  |PARTITIONED|
+                project ([$$69])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$69] <- [$$t.getField(12)]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$t])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (twitter.ds_tweet)  |PARTITIONED|
+                        data-scan []<-[$$68, $$t] <- twitter.ds_tweet
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-ternary-inlj/query4.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-ternary-inlj/query4.plan
index 9b920b4..077de27 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-ternary-inlj/query4.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/btree-ternary-inlj/query4.plan
@@ -1,32 +1,64 @@
+distribute result [$$66]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$66])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$66] <- [{"$1": $$71}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$71] <- [agg-sql-sum($$76)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$76] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- BTREE_SEARCH (tpcds.customer_address.customer_address)  |PARTITIONED|
+                unnest-map [$$69, $$ca] <- index-search("customer_address", 0, "tpcds", "customer_address", true, true, 1, $$74, 1, $$74, true, true, true)
+                -- BTREE_SEARCH  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- STABLE_SORT [$$78(ASC)]  |PARTITIONED|
-                      -- HASH_PARTITION_EXCHANGE [$$78]  |PARTITIONED|
+                    order (ASC, $$74)
+                    -- STABLE_SORT [$$74(ASC)]  |PARTITIONED|
+                      exchange
+                      -- HASH_PARTITION_EXCHANGE [$$74]  |PARTITIONED|
+                        project ([$$74])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- BTREE_SEARCH (tpcds.customer_demographics.customer_demographics)  |PARTITIONED|
+                            unnest-map [$$68, $$cd2] <- index-search("customer_demographics", 0, "tpcds", "customer_demographics", true, true, 1, $$72, 1, $$72, true, true, true)
+                            -- BTREE_SEARCH  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- STABLE_SORT [$$76(ASC)]  |PARTITIONED|
-                                  -- HASH_PARTITION_EXCHANGE [$$76]  |PARTITIONED|
+                                order (ASC, $$72)
+                                -- STABLE_SORT [$$72(ASC)]  |PARTITIONED|
+                                  exchange
+                                  -- HASH_PARTITION_EXCHANGE [$$72]  |PARTITIONED|
+                                    project ([$$74, $$72])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- HYBRID_HASH_JOIN [$$61][$$74]  |PARTITIONED|
+                                        join (eq($$70, $$57))
+                                        -- HYBRID_HASH_JOIN [$$57][$$70]  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$74, $$57, $$72])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$74, $$57, $$72] <- [$$c.getField(4), $$c.getField(12), $$c.getField(2)]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$c])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (tpcds.customer)  |PARTITIONED|
+                                                    data-scan []<-[$$67, $$c] <- tpcds.customer
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                          exchange
                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                            unnest $$70 <- scan-collection(array: [ 4, 5 ])
                                             -- UNNEST  |UNPARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/ch2/ch2_q16.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/ch2/ch2_q16.plan
index 2214a1e..bb083fd 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/ch2/ch2_q16.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/ch2/ch2_q16.plan
@@ -1,65 +1,124 @@
+distribute result [$$120]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$120])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$120] <- [{"i_name": $$i_name, "brand": $#1, "i_price": $$i_price, "supplier_cnt": $$131}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$131(DESC) ]  |PARTITIONED|
+          order (DESC, $$131)
           -- STABLE_SORT [$$131(DESC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- PRE_CLUSTERED_GROUP_BY[$$121, $$122, $$123]  |PARTITIONED|
-                      {
+              group by ([$$i_name := $$121; $#1 := $$122; $$i_price := $$123]) decor ([]) {
+                        aggregate [$$131] <- [agg-sql-count($$142)]
                         -- AGGREGATE  |LOCAL|
+                          distinct ([$$142])
                           -- MICRO_PRE_SORTED_DISTINCT_BY  |LOCAL|
+                            order (ASC, $$142)
                             -- MICRO_STABLE_SORT [$$142(ASC)]  |LOCAL|
+                              assign [$$142] <- [numeric-mod(numeric-multiply($$135, $$136), 10000)]
                               -- ASSIGN  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- PRE_CLUSTERED_GROUP_BY[$$121, $$122, $$123]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  order (ASC, $$121) (ASC, $$122) (ASC, $$123)
                   -- STABLE_SORT [$$121(ASC), $$122(ASC), $$123(ASC)]  |PARTITIONED|
+                    exchange
                     -- HASH_PARTITION_EXCHANGE [$$121, $$122, $$123]  |PARTITIONED|
+                      project ([$$135, $$136, $$121, $$122, $$123])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$122] <- [substring1($$124, 1, 3)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$121, $$123, $$124, $$136, $$135])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            select ($$103)
                             -- STREAM_SELECT  |PARTITIONED|
+                              project ([$$103, $$121, $$123, $$124, $$136, $$135])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- PRE_CLUSTERED_GROUP_BY[$$125, $$126]  |PARTITIONED|
-                                          {
+                                  group by ([$$138 := $$125; $$139 := $$126]) decor ([$$121; $$123; $$124; $$136 := $$130; $$135 := $$133]) {
+                                            aggregate [$$103] <- [empty-stream()]
                                             -- AGGREGATE  |LOCAL|
+                                              select (not(is-missing($$137)))
                                               -- STREAM_SELECT  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                         }
+                                  -- PRE_CLUSTERED_GROUP_BY[$$125, $$126]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      order (ASC, $$125) (ASC, $$126)
                                       -- STABLE_SORT [$$125(ASC), $$126(ASC)]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$121, $$123, $$124, $$137, $$125, $$126, $$130, $$133])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              left outer join (not(if-missing-or-null(neq(numeric-mod(numeric-multiply($$133, $$130), 10000), $$97), false)))
                                               -- NESTED_LOOP  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  project ([$$121, $$123, $$124, $$125, $$126, $$130, $$133])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      join (eq($$129, $$130))
                                                       -- HYBRID_HASH_JOIN [$$130][$$129]  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          project ([$$125, $$130, $$133])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            assign [$$130, $$133] <- [$$s.getField("s_i_id"), $$s.getField("s_w_id")]
                                                             -- ASSIGN  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- DATASOURCE_SCAN (test.stock)  |PARTITIONED|
+                                                                data-scan []<-[$$125, $$s] <- test.stock
+                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    empty-tuple-source
                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                        exchange
                                                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                          select (not(like($$124, "zz%")))
                                                           -- STREAM_SELECT  |PARTITIONED|
+                                                            project ([$$126, $$123, $$121, $$124, $$129])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$123, $$121, $$124, $$129] <- [$$i.getField("i_price"), $$i.getField("i_name"), $$i.getField("i_data"), $$i.getField("i_id")]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- DATASOURCE_SCAN (test.item)  |PARTITIONED|
+                                                                  data-scan []<-[$$126, $$i] <- test.item
+                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      empty-tuple-source
                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                exchange
                                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                  assign [$$137] <- [true]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$97])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      select (like($$su.getField("su_comment"), "%Customer%Complaints%"))
                                                       -- STREAM_SELECT  |PARTITIONED|
+                                                        assign [$$97] <- [$$su.getField("su_suppkey")]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          project ([$$su])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- DATASOURCE_SCAN (test.supplier)  |PARTITIONED|
+                                                              data-scan []<-[$$127, $$su] <- test.supplier
+                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  empty-tuple-source
                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/ch2/ch2_q2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/ch2/ch2_q2.plan
index 6d36713..751bc95 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/ch2/ch2_q2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/ch2/ch2_q2.plan
@@ -1,162 +1,318 @@
+distribute result [$$220]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    limit 100
     -- STREAM_LIMIT  |UNPARTITIONED|
+      project ([$$220])
       -- STREAM_PROJECT  |PARTITIONED|
+        assign [$$220] <- [{"su_suppkey": $$228, "su_name": $$261, "n_name": $$260, "i_id": $$226, "i_name": $$265, "su_address": $$266, "su_phone": $$267, "su_comment": $$268}]
         -- ASSIGN  |PARTITIONED|
-          -- SORT_MERGE_EXCHANGE [$$274(ASC), $$275(ASC), $$240(ASC) ]  |PARTITIONED|
+          exchange
+          -- SORT_MERGE_EXCHANGE [$$260(ASC), $$261(ASC), $$226(ASC) ]  |PARTITIONED|
+            limit 100
             -- STREAM_LIMIT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- STABLE_SORT [topK: 100] [$$274(ASC), $$275(ASC), $$240(ASC)]  |PARTITIONED|
+                order (topK: 100) (ASC, $$260) (ASC, $$261) (ASC, $$226)
+                -- STABLE_SORT [topK: 100] [$$260(ASC), $$261(ASC), $$226(ASC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$228, $$261, $$260, $$226, $$265, $$266, $$267, $$268])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- HYBRID_HASH_JOIN [$$252][$$253]  |PARTITIONED|
-                          -- HASH_PARTITION_EXCHANGE [$$252]  |PARTITIONED|
+                        join (eq($$238, $$239))
+                        -- HYBRID_HASH_JOIN [$$238][$$239]  |PARTITIONED|
+                          exchange
+                          -- HASH_PARTITION_EXCHANGE [$$238]  |PARTITIONED|
+                            project ([$$228, $$261, $$260, $$226, $$265, $$266, $$267, $$268, $$238])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- HYBRID_HASH_JOIN [$$259][$$260]  |PARTITIONED|
-                                  -- HASH_PARTITION_EXCHANGE [$$259]  |PARTITIONED|
+                                join (eq($$245, $$246))
+                                -- HYBRID_HASH_JOIN [$$245][$$246]  |PARTITIONED|
+                                  exchange
+                                  -- HASH_PARTITION_EXCHANGE [$$245]  |PARTITIONED|
+                                    project ([$$228, $$261, $$226, $$265, $$266, $$267, $$268, $$245])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- HYBRID_HASH_JOIN [$$265][$$242]  |PARTITIONED|
-                                          -- HASH_PARTITION_EXCHANGE [$$265]  |PARTITIONED|
+                                        join (eq($$251, $$228))
+                                        -- HYBRID_HASH_JOIN [$$251][$$228]  |PARTITIONED|
+                                          exchange
+                                          -- HASH_PARTITION_EXCHANGE [$$251]  |PARTITIONED|
+                                            project ([$$226, $$265, $$251])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$251] <- [numeric-mod(numeric-multiply($$258, $$227), 10000)]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$226, $$265, $$258, $$227])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- HYBRID_HASH_JOIN [$$240, $$254][$$241, $$263]  |PARTITIONED|
-                                                      -- HASH_PARTITION_EXCHANGE [$$240, $$254]  |PARTITIONED|
+                                                    join (and(eq($$226, $$227), eq($$249, $$240)))
+                                                    -- HYBRID_HASH_JOIN [$$226, $$240][$$227, $$249]  |PARTITIONED|
+                                                      exchange
+                                                      -- HASH_PARTITION_EXCHANGE [$$226, $$240]  |PARTITIONED|
+                                                        project ([$$226, $$265, $$240])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- HYBRID_HASH_JOIN [$$s_i_id][$$240]  |PARTITIONED|
+                                                            join (eq($$226, $$s_i_id))
+                                                            -- HYBRID_HASH_JOIN [$$s_i_id][$$226]  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- SORT_GROUP_BY[$$285]  |PARTITIONED|
-                                                                        {
+                                                                group by ([$$s_i_id := $$271]) decor ([]) {
+                                                                          aggregate [$$240] <- [agg-global-sql-min($$270)]
                                                                           -- AGGREGATE  |LOCAL|
+                                                                            nested tuple source
                                                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                        }
-                                                                  -- HASH_PARTITION_EXCHANGE [$$285]  |PARTITIONED|
-                                                                    -- SORT_GROUP_BY[$$239]  |PARTITIONED|
-                                                                            {
+                                                                       }
+                                                                -- SORT_GROUP_BY[$$271]  |PARTITIONED|
+                                                                  exchange
+                                                                  -- HASH_PARTITION_EXCHANGE [$$271]  |PARTITIONED|
+                                                                    group by ([$$271 := $$225]) decor ([]) {
+                                                                              aggregate [$$270] <- [agg-local-sql-min($$177)]
                                                                               -- AGGREGATE  |LOCAL|
+                                                                                nested tuple source
                                                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                            }
+                                                                           }
+                                                                    -- SORT_GROUP_BY[$$225]  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        project ([$$177, $$225])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                            -- HYBRID_HASH_JOIN [$$255][$$256]  |PARTITIONED|
-                                                                              -- HASH_PARTITION_EXCHANGE [$$255]  |PARTITIONED|
+                                                                            join (eq($$241, $$242))
+                                                                            -- HYBRID_HASH_JOIN [$$241][$$242]  |PARTITIONED|
+                                                                              exchange
+                                                                              -- HASH_PARTITION_EXCHANGE [$$241]  |PARTITIONED|
+                                                                                project ([$$177, $$225, $$241])
                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                    -- HYBRID_HASH_JOIN [$$257][$$269]  |PARTITIONED|
-                                                                                      -- HASH_PARTITION_EXCHANGE [$$257]  |PARTITIONED|
+                                                                                    join (eq($$243, $$255))
+                                                                                    -- HYBRID_HASH_JOIN [$$243][$$255]  |PARTITIONED|
+                                                                                      exchange
+                                                                                      -- HASH_PARTITION_EXCHANGE [$$243]  |PARTITIONED|
+                                                                                        project ([$$177, $$225, $$243])
                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                            -- HYBRID_HASH_JOIN [$$261][$$270]  |PARTITIONED|
-                                                                                              -- HASH_PARTITION_EXCHANGE [$$261]  |PARTITIONED|
+                                                                                            join (eq($$247, $$256))
+                                                                                            -- HYBRID_HASH_JOIN [$$247][$$256]  |PARTITIONED|
+                                                                                              exchange
+                                                                                              -- HASH_PARTITION_EXCHANGE [$$247]  |PARTITIONED|
+                                                                                                project ([$$177, $$225, $$247])
                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                  assign [$$247] <- [numeric-mod(numeric-multiply($$s1.getField("s_w_id"), $$225), 10000)]
                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                    assign [$$225, $$177] <- [$$s1.getField("s_i_id"), $$s1.getField("s_quantity")]
                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                      exchange
                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                        replicate
                                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                                          exchange
                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                            project ([$$s1])
                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                              exchange
                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                -- DATASOURCE_SCAN (test.stock)  |PARTITIONED|
+                                                                                                                data-scan []<-[$$229, $$s1] <- test.stock
+                                                                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                  exchange
                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                    empty-tuple-source
                                                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                                                              -- HASH_PARTITION_EXCHANGE [$$270]  |PARTITIONED|
+                                                                                              exchange
+                                                                                              -- HASH_PARTITION_EXCHANGE [$$256]  |PARTITIONED|
+                                                                                                project ([$$243, $$256])
                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                  assign [$$256, $$243] <- [$$su1.getField("su_suppkey"), $$su1.getField("su_nationkey")]
                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                    exchange
                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                      replicate
                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                        exchange
                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                          project ([$$su1])
                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                            exchange
                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                              -- DATASOURCE_SCAN (test.supplier)  |PARTITIONED|
+                                                                                                              data-scan []<-[$$230, $$su1] <- test.supplier
+                                                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                exchange
                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                  empty-tuple-source
                                                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                                                      -- HASH_PARTITION_EXCHANGE [$$269]  |PARTITIONED|
+                                                                                      exchange
+                                                                                      -- HASH_PARTITION_EXCHANGE [$$255]  |PARTITIONED|
+                                                                                        project ([$$241, $$255])
                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                          assign [$$255, $$241] <- [$$n1.getField("n_nationkey"), $$n1.getField("n_regionkey")]
                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                            exchange
                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                              replicate
                                                                                               -- REPLICATE  |PARTITIONED|
+                                                                                                exchange
                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                  project ([$$n1])
                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                    exchange
                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                      -- DATASOURCE_SCAN (test.nation)  |PARTITIONED|
+                                                                                                      data-scan []<-[$$231, $$n1] <- test.nation
+                                                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                        exchange
                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                          empty-tuple-source
                                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                replicate
                                                                                 -- REPLICATE  |PARTITIONED|
-                                                                                  -- HASH_PARTITION_EXCHANGE [$$256]  |PARTITIONED|
+                                                                                  exchange
+                                                                                  -- HASH_PARTITION_EXCHANGE [$$242]  |PARTITIONED|
+                                                                                    project ([$$242])
                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                      select (like($$r1.getField("r_name"), "Europ%"))
                                                                                       -- STREAM_SELECT  |PARTITIONED|
+                                                                                        assign [$$242] <- [$$r1.getField("r_regionkey")]
                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                          project ([$$r1])
                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                            exchange
                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                              -- DATASOURCE_SCAN (test.region)  |PARTITIONED|
+                                                                                              data-scan []<-[$$232, $$r1] <- test.region
+                                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                exchange
                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                  empty-tuple-source
                                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                              -- HASH_PARTITION_EXCHANGE [$$240]  |PARTITIONED|
+                                                              exchange
+                                                              -- HASH_PARTITION_EXCHANGE [$$226]  |PARTITIONED|
+                                                                project ([$$226, $$265])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  select (like($$i.getField("i_data"), "%b"))
                                                                   -- STREAM_SELECT  |PARTITIONED|
+                                                                    assign [$$265, $$226] <- [$$i.getField("i_name"), $$i.getField("i_id")]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      project ([$$i])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                          -- DATASOURCE_SCAN (test.item)  |PARTITIONED|
+                                                                          data-scan []<-[$$233, $$i] <- test.item
+                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              empty-tuple-source
                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                      -- HASH_PARTITION_EXCHANGE [$$241, $$263]  |PARTITIONED|
+                                                      exchange
+                                                      -- HASH_PARTITION_EXCHANGE [$$227, $$249]  |PARTITIONED|
+                                                        project ([$$258, $$227, $$249])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$258, $$249, $$227] <- [$$s.getField("s_w_id"), $$s.getField("s_quantity"), $$s.getField("s_i_id")]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            project ([$$s])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$s] <- [$$s1]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  replicate
                                                                   -- REPLICATE  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      project ([$$s1])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                          -- DATASOURCE_SCAN (test.stock)  |PARTITIONED|
+                                                                          data-scan []<-[$$229, $$s1] <- test.stock
+                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              empty-tuple-source
                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                          -- HASH_PARTITION_EXCHANGE [$$242]  |PARTITIONED|
+                                          exchange
+                                          -- HASH_PARTITION_EXCHANGE [$$228]  |PARTITIONED|
+                                            project ([$$228, $$261, $$266, $$267, $$268, $$245])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$268, $$267, $$266, $$261, $$245, $$228] <- [$$su.getField("su_comment"), $$su.getField("su_phone"), $$su.getField("su_address"), $$su.getField("su_name"), $$su.getField("su_nationkey"), $$su.getField("su_suppkey")]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$su])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$su] <- [$$su1]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      replicate
                                                       -- REPLICATE  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          project ([$$su1])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- DATASOURCE_SCAN (test.supplier)  |PARTITIONED|
+                                                              data-scan []<-[$$230, $$su1] <- test.supplier
+                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  empty-tuple-source
                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                  -- HASH_PARTITION_EXCHANGE [$$260]  |PARTITIONED|
+                                  exchange
+                                  -- HASH_PARTITION_EXCHANGE [$$246]  |PARTITIONED|
+                                    project ([$$260, $$238, $$246])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$260, $$238, $$246] <- [$$n.getField("n_name"), $$n.getField("n_regionkey"), $$n.getField("n_nationkey")]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$n])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$n] <- [$$n1]
                                           -- ASSIGN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              replicate
                                               -- REPLICATE  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  project ([$$n1])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.nation)  |PARTITIONED|
+                                                      data-scan []<-[$$231, $$n1] <- test.nation
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$239])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              assign [$$239] <- [$$242]
                               -- ASSIGN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  replicate
                                   -- REPLICATE  |PARTITIONED|
-                                    -- HASH_PARTITION_EXCHANGE [$$256]  |PARTITIONED|
+                                    exchange
+                                    -- HASH_PARTITION_EXCHANGE [$$242]  |PARTITIONED|
+                                      project ([$$242])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        select (like($$r1.getField("r_name"), "Europ%"))
                                         -- STREAM_SELECT  |PARTITIONED|
+                                          assign [$$242] <- [$$r1.getField("r_regionkey")]
                                           -- ASSIGN  |PARTITIONED|
+                                            project ([$$r1])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- DATASOURCE_SCAN (test.region)  |PARTITIONED|
+                                                data-scan []<-[$$232, $$r1] <- test.region
+                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/ch2/ch2_q21.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/ch2/ch2_q21.plan
index 555eb0b..bec0f11 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/ch2/ch2_q21.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/ch2/ch2_q21.plan
@@ -1,116 +1,220 @@
+distribute result [$$318]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    limit 100
     -- STREAM_LIMIT  |UNPARTITIONED|
+      project ([$$318])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$su_name(ASC) ]  |PARTITIONED|
+          project ([$$su_name, $$318])
           -- STREAM_PROJECT  |PARTITIONED|
+            assign [$$318] <- [{"su_name": $$su_name, "numwait": $$343}]
             -- ASSIGN  |PARTITIONED|
+              limit 100
               -- STREAM_LIMIT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- SORT_GROUP_BY[$$378]  |PARTITIONED|
-                          {
+                  group by ([$$su_name := $$378]) decor ([]) {
+                            aggregate [$$343] <- [agg-sql-sum($$377)]
                             -- AGGREGATE  |LOCAL|
+                              nested tuple source
                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                          }
+                         }
+                  -- SORT_GROUP_BY[$$378]  |PARTITIONED|
+                    exchange
                     -- HASH_PARTITION_EXCHANGE [$$378]  |PARTITIONED|
-                      -- SORT_GROUP_BY[$$su_name]  |PARTITIONED|
-                              {
+                      group by ([$$378 := $$su_name]) decor ([]) {
+                                aggregate [$$377] <- [agg-sql-count(1)]
                                 -- AGGREGATE  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- SORT_GROUP_BY[$$su_name]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$su_name])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            select (eq($$342, 0))
                             -- STREAM_SELECT  |PARTITIONED|
+                              project ([$$342, $$su_name])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- SORT_GROUP_BY[$$369, $$370, $$371, $$372, $$373, $$374, $$375, $$376]  |PARTITIONED|
-                                          {
+                                  group by ([$$o_w_id := $$369; $$o_d_id := $$370; $$o_id := $$371; $$n_nationkey := $$372; $$su_suppkey := $$373; $$s_w_id := $$374; $$s_i_id := $$375; $$su_name := $$376]) decor ([]) {
+                                            aggregate [$$342] <- [agg-sql-sum($$368)]
                                             -- AGGREGATE  |LOCAL|
+                                              nested tuple source
                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                          }
+                                         }
+                                  -- SORT_GROUP_BY[$$369, $$370, $$371, $$372, $$373, $$374, $$375, $$376]  |PARTITIONED|
+                                    exchange
                                     -- HASH_PARTITION_EXCHANGE [$$369, $$370, $$371, $$372, $$373, $$374, $$375, $$376]  |PARTITIONED|
-                                      -- SORT_GROUP_BY[$$331, $$357, $$356, $$333, $$334, $$330, $$329, $$358]  |PARTITIONED|
-                                              {
+                                      group by ([$$369 := $$331; $$370 := $$357; $$371 := $$356; $$372 := $$333; $$373 := $$334; $$374 := $$330; $$375 := $$329; $$376 := $$358]) decor ([]) {
+                                                aggregate [$$368] <- [agg-sql-count($$305)]
                                                 -- AGGREGATE  |LOCAL|
+                                                  nested tuple source
                                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                              }
+                                             }
+                                      -- SORT_GROUP_BY[$$331, $$357, $$356, $$333, $$334, $$330, $$329, $$358]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          project ([$$305, $$331, $$357, $$356, $$333, $$334, $$330, $$329, $$358])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              left outer join (and(eq($$362, $$357), gt($$363, $$332), eq($$360, $$356), eq($$361, $$331)))
                                               -- NESTED_LOOP  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  project ([$$331, $$357, $$356, $$333, $$334, $$330, $$329, $$358, $$332])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      join (eq($$344, $$333))
                                                       -- HYBRID_HASH_JOIN [$$333][$$344]  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          project ([$$333])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            select (eq($$n.getField("n_name"), "Peru"))
                                                             -- STREAM_SELECT  |PARTITIONED|
+                                                              assign [$$333] <- [$$n.getField("n_nationkey")]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                project ([$$n])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (test.nation)  |PARTITIONED|
+                                                                    data-scan []<-[$$336, $$n] <- test.nation
+                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        empty-tuple-source
                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                        exchange
                                                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                          project ([$$331, $$357, $$356, $$334, $$330, $$329, $$358, $$332, $$344])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              join (eq($$345, $$334))
                                                               -- HYBRID_HASH_JOIN [$$334][$$345]  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  project ([$$334, $$358, $$344])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    assign [$$358, $$334, $$344] <- [$$su.getField("su_name"), $$su.getField("su_suppkey"), $$su.getField("su_nationkey")]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      project ([$$su])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                          -- DATASOURCE_SCAN (test.supplier)  |PARTITIONED|
+                                                                          data-scan []<-[$$337, $$su] <- test.supplier
+                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              empty-tuple-source
                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                exchange
                                                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                  project ([$$331, $$357, $$356, $$330, $$329, $$332, $$345])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      join (and(eq($$331, $$330), eq($$341, $$329)))
                                                                       -- HYBRID_HASH_JOIN [$$330, $$329][$$331, $$341]  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          assign [$$345] <- [numeric-mod(numeric-multiply($$330, $$329), 10000)]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            project ([$$330, $$329])
                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                              assign [$$330, $$329] <- [$$s.getField("s_w_id"), $$s.getField("s_i_id")]
                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                project ([$$s])
                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                    -- DATASOURCE_SCAN (test.stock)  |PARTITIONED|
+                                                                                    data-scan []<-[$$338, $$s] <- test.stock
+                                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                        empty-tuple-source
                                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                        exchange
                                                                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                          project ([$$331, $$357, $$356, $$332, $$341])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            select (gt($$332, string(numeric-add(date($$328), duration: {P150D }))))
                                                                             -- STREAM_SELECT  |PARTITIONED|
+                                                                              project ([$$357, $$356, $$331, $$328, $$341, $$332])
                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                assign [$$341, $$332] <- [$$ol1.getField("ol_i_id"), $$ol1.getField("ol_delivery_d")]
                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                  project ([$$357, $$356, $$331, $$328, $$ol1])
                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                    unnest $$ol1 <- scan-collection($$355)
                                                                                     -- UNNEST  |PARTITIONED|
+                                                                                      select (and(le($$328, "2017-12-31 00:00:00"), ge($$328, "2017-12-01 00:00:00")))
                                                                                       -- STREAM_SELECT  |PARTITIONED|
+                                                                                        project ([$$357, $$356, $$331, $$328, $$355])
                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                          assign [$$357, $$356, $$331, $$328, $$355] <- [$$o1.getField("o_d_id"), $$o1.getField("o_id"), $$o1.getField("o_w_id"), $$o1.getField("o_entry_d"), $$o1.getField("o_orderline")]
                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                            exchange
                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                              replicate
                                                                                               -- REPLICATE  |PARTITIONED|
+                                                                                                exchange
                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                  project ([$$o1])
                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                    exchange
                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                      -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                                                                                      data-scan []<-[$$339, $$o1] <- test.orders
+                                                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                        exchange
                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                          empty-tuple-source
                                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                exchange
                                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                  assign [$$305] <- [{"o_id": $$360, "o_w_id": $$361, "o_d_id": $$362, "ol_delivery_d": $$363}.getField("o_id")]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$362, $$361, $$360, $$363])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      assign [$$363] <- [$$ol2.getField("ol_delivery_d")]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        project ([$$362, $$361, $$360, $$ol2])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          unnest $$ol2 <- scan-collection($$359)
                                                           -- UNNEST  |PARTITIONED|
+                                                            project ([$$362, $$361, $$360, $$359])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              select (and(le($$335, "2017-12-31 00:00:00"), ge($$335, "2017-12-01 00:00:00")))
                                                               -- STREAM_SELECT  |PARTITIONED|
+                                                                project ([$$362, $$361, $$360, $$335, $$359])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  assign [$$362, $$361, $$360, $$335, $$359] <- [$$o2.getField("o_d_id"), $$o2.getField("o_w_id"), $$o2.getField("o_id"), $$o2.getField("o_entry_d"), $$o2.getField("o_orderline")]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    project ([$$o2])
                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                      assign [$$o2] <- [$$o1]
                                                                       -- ASSIGN  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          replicate
                                                                           -- REPLICATE  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                              project ([$$o1])
                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                  -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                                                                  data-scan []<-[$$339, $$o1] <- test.orders
+                                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                    exchange
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                      empty-tuple-source
                                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/ch2/ch2_q5.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/ch2/ch2_q5.plan
index 95ff63d3..28f2c95 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/ch2/ch2_q5.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/ch2/ch2_q5.plan
@@ -1,97 +1,188 @@
+distribute result [$$229]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$229])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$229] <- [{"n_name": $$n_name, "revenue": $#2}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$#2(DESC) ]  |PARTITIONED|
+          order (DESC, $#2)
           -- STABLE_SORT [$#2(DESC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$n_name, $#2])
               -- STREAM_PROJECT  |PARTITIONED|
+                assign [$#2] <- [round($$256, 2)]
                 -- ASSIGN  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- SORT_GROUP_BY[$$291]  |PARTITIONED|
-                            {
+                    group by ([$$n_name := $$277]) decor ([]) {
+                              aggregate [$$256] <- [agg-global-sql-sum($$276)]
                               -- AGGREGATE  |LOCAL|
+                                nested tuple source
                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                            }
-                      -- HASH_PARTITION_EXCHANGE [$$291]  |PARTITIONED|
-                        -- SORT_GROUP_BY[$$275]  |PARTITIONED|
-                                {
+                           }
+                    -- SORT_GROUP_BY[$$277]  |PARTITIONED|
+                      exchange
+                      -- HASH_PARTITION_EXCHANGE [$$277]  |PARTITIONED|
+                        group by ([$$277 := $$261]) decor ([]) {
+                                  aggregate [$$276] <- [agg-local-sql-sum($$266)]
                                   -- AGGREGATE  |LOCAL|
+                                    nested tuple source
                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                }
+                               }
+                        -- SORT_GROUP_BY[$$261]  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$266, $$261])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- HYBRID_HASH_JOIN [$$257][$$256]  |PARTITIONED|
-                                  -- HASH_PARTITION_EXCHANGE [$$257]  |PARTITIONED|
+                                join (eq($$242, $$243))
+                                -- HYBRID_HASH_JOIN [$$243][$$242]  |PARTITIONED|
+                                  exchange
+                                  -- HASH_PARTITION_EXCHANGE [$$243]  |PARTITIONED|
+                                    project ([$$243])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      select (eq($$r.getField("r_name"), "Asia"))
                                       -- STREAM_SELECT  |PARTITIONED|
+                                        assign [$$243] <- [$$r.getField("r_regionkey")]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$r])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.region)  |PARTITIONED|
+                                              data-scan []<-[$$237, $$r] <- test.region
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                  -- HASH_PARTITION_EXCHANGE [$$256]  |PARTITIONED|
+                                  exchange
+                                  -- HASH_PARTITION_EXCHANGE [$$242]  |PARTITIONED|
+                                    project ([$$266, $$261, $$242])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- HYBRID_HASH_JOIN [$$274, $$268][$$266, $$269]  |PARTITIONED|
-                                          -- HASH_PARTITION_EXCHANGE [$$274, $$268]  |PARTITIONED|
+                                        join (and(eq($$252, $$260), eq($$254, $$255)))
+                                        -- HYBRID_HASH_JOIN [$$260, $$254][$$252, $$255]  |PARTITIONED|
+                                          exchange
+                                          -- HASH_PARTITION_EXCHANGE [$$260, $$254]  |PARTITIONED|
+                                            project ([$$266, $$261, $$242, $$260, $$254])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- HYBRID_HASH_JOIN [$$258][$$274]  |PARTITIONED|
-                                                  -- HASH_PARTITION_EXCHANGE [$$258]  |PARTITIONED|
+                                                join (eq($$244, $$260))
+                                                -- HYBRID_HASH_JOIN [$$244][$$260]  |PARTITIONED|
+                                                  exchange
+                                                  -- HASH_PARTITION_EXCHANGE [$$244]  |PARTITIONED|
+                                                    project ([$$266, $$254, $$244])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- HYBRID_HASH_JOIN [$$260, $$254, $$263][$$276, $$277, $$278]  |PARTITIONED|
-                                                          -- HASH_PARTITION_EXCHANGE [$$260, $$254, $$263]  |PARTITIONED|
+                                                        join (and(eq($$262, $$246), eq($$263, $$240), eq($$264, $$249)))
+                                                        -- HYBRID_HASH_JOIN [$$246, $$240, $$249][$$262, $$263, $$264]  |PARTITIONED|
+                                                          exchange
+                                                          -- HASH_PARTITION_EXCHANGE [$$246, $$240, $$249]  |PARTITIONED|
+                                                            project ([$$266, $$254, $$246, $$240, $$249])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- HYBRID_HASH_JOIN [$$245, $$246][$$254, $$281]  |PARTITIONED|
-                                                                  -- HASH_PARTITION_EXCHANGE [$$245, $$246]  |PARTITIONED|
+                                                                join (and(eq($$240, $$231), eq($$267, $$232)))
+                                                                -- HYBRID_HASH_JOIN [$$231, $$232][$$240, $$267]  |PARTITIONED|
+                                                                  exchange
+                                                                  -- HASH_PARTITION_EXCHANGE [$$231, $$232]  |PARTITIONED|
+                                                                    assign [$$254] <- [numeric-mod(numeric-multiply($$231, $$232), 10000)]
                                                                     -- ASSIGN  |PARTITIONED|
+                                                                      project ([$$232, $$231])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        assign [$$232, $$231] <- [$$s.getField("s_i_id"), $$s.getField("s_w_id")]
                                                                         -- ASSIGN  |PARTITIONED|
+                                                                          project ([$$s])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            exchange
                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                              -- DATASOURCE_SCAN (test.stock)  |PARTITIONED|
+                                                                              data-scan []<-[$$233, $$s] <- test.stock
+                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                exchange
                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                  empty-tuple-source
                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                                  -- HASH_PARTITION_EXCHANGE [$$254, $$281]  |PARTITIONED|
+                                                                  exchange
+                                                                  -- HASH_PARTITION_EXCHANGE [$$240, $$267]  |PARTITIONED|
+                                                                    project ([$$266, $$246, $$240, $$249, $$267])
                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                      assign [$$267, $$266] <- [$$ol.getField("ol_i_id"), $$ol.getField("ol_amount")]
                                                                       -- ASSIGN  |PARTITIONED|
+                                                                        project ([$$249, $$246, $$240, $$ol])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          unnest $$ol <- scan-collection($$257)
                                                                           -- UNNEST  |PARTITIONED|
+                                                                            project ([$$249, $$246, $$240, $$257])
                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                              select (and(ge($$239, "2016-01-01 00:00:00.000000"), lt($$239, "2017-01-01 00:00:00.000000")))
                                                                               -- STREAM_SELECT  |PARTITIONED|
+                                                                                project ([$$249, $$246, $$240, $$239, $$257])
                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                  assign [$$249, $$246, $$240, $$239, $$257] <- [$$o.getField("o_d_id"), $$o.getField("o_c_id"), $$o.getField("o_w_id"), $$o.getField("o_entry_d"), $$o.getField("o_orderline")]
                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                    project ([$$o])
                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                        -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                                                                        data-scan []<-[$$234, $$o] <- test.orders
+                                                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                            empty-tuple-source
                                                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                          -- HASH_PARTITION_EXCHANGE [$$276, $$277, $$278]  |PARTITIONED|
+                                                          exchange
+                                                          -- HASH_PARTITION_EXCHANGE [$$262, $$263, $$264]  |PARTITIONED|
+                                                            project ([$$244, $$262, $$263, $$264])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$244, $$264, $$263, $$262] <- [get-item(string-to-codepoint($$c.getField("c_state")), 0), $$c.getField("c_d_id"), $$c.getField("c_w_id"), $$c.getField("c_id")]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                project ([$$c])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (test.customer)  |PARTITIONED|
+                                                                    data-scan []<-[$$235, $$c] <- test.customer
+                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        empty-tuple-source
                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                  -- HASH_PARTITION_EXCHANGE [$$274]  |PARTITIONED|
+                                                  exchange
+                                                  -- HASH_PARTITION_EXCHANGE [$$260]  |PARTITIONED|
+                                                    project ([$$261, $$242, $$260])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      assign [$$261, $$260, $$242] <- [$$n.getField("n_name"), $$n.getField("n_nationkey"), $$n.getField("n_regionkey")]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        project ([$$n])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- DATASOURCE_SCAN (test.nation)  |PARTITIONED|
+                                                            data-scan []<-[$$236, $$n] <- test.nation
+                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                empty-tuple-source
                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                          -- HASH_PARTITION_EXCHANGE [$$266, $$269]  |PARTITIONED|
+                                          exchange
+                                          -- HASH_PARTITION_EXCHANGE [$$252, $$255]  |PARTITIONED|
+                                            project ([$$252, $$255])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$255, $$252] <- [$$su.getField("su_suppkey"), $$su.getField("su_nationkey")]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$su])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (test.supplier)  |PARTITIONED|
+                                                    data-scan []<-[$$238, $$su] <- test.supplier
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/ch2/ch2_q7.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/ch2/ch2_q7.plan
index 98a1725..2008d6a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/ch2/ch2_q7.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/ch2/ch2_q7.plan
@@ -1,103 +1,200 @@
+distribute result [$$256]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$256])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$256] <- [{"supp_nation": $$su_nationkey, "cust_nation": $#1, "l_year": $#2, "revenue": round($$286, 2)}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$su_nationkey(ASC), $#1(ASC), $#2(ASC) ]  |PARTITIONED|
-          -- SORT_GROUP_BY[$$325, $$326, $$327]  |PARTITIONED|
-                  {
+          group by ([$$su_nationkey := $$310; $#1 := $$311; $#2 := $$312]) decor ([]) {
+                    aggregate [$$286] <- [agg-global-sql-sum($$309)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
-            -- HASH_PARTITION_EXCHANGE [$$325, $$326, $$327]  |PARTITIONED|
-              -- SORT_GROUP_BY[$$277, $$273, $$274]  |PARTITIONED|
-                      {
+                 }
+          -- SORT_GROUP_BY[$$310, $$311, $$312]  |PARTITIONED|
+            exchange
+            -- HASH_PARTITION_EXCHANGE [$$310, $$311, $$312]  |PARTITIONED|
+              group by ([$$310 := $$262; $$311 := $$258; $$312 := $$259]) decor ([]) {
+                        aggregate [$$309] <- [agg-local-sql-sum($$298)]
                         -- AGGREGATE  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SORT_GROUP_BY[$$262, $$258, $$259]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$298, $$262, $$258, $$259])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$259, $$258] <- [get-year(date($$294)), substring1($$270, 1, 1)]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$298, $$262, $$294, $$270])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (or(and(eq($$271, "Germany"), eq($$272, "Cambodia")), and(eq($$271, "Cambodia"), eq($$272, "Germany"))))
                         -- STREAM_SELECT  |PARTITIONED|
+                          project ([$$298, $$262, $$294, $$270, $$271, $$272])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- HYBRID_HASH_JOIN [$$288][$$304]  |PARTITIONED|
-                                -- HASH_PARTITION_EXCHANGE [$$288]  |PARTITIONED|
+                              join (eq($$273, $$289))
+                              -- HYBRID_HASH_JOIN [$$273][$$289]  |PARTITIONED|
+                                exchange
+                                -- HASH_PARTITION_EXCHANGE [$$273]  |PARTITIONED|
+                                  project ([$$298, $$262, $$294, $$270, $$273, $$271])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- HYBRID_HASH_JOIN [$$277][$$303]  |PARTITIONED|
-                                        -- HASH_PARTITION_EXCHANGE [$$277]  |PARTITIONED|
+                                      join (eq($$262, $$288))
+                                      -- HYBRID_HASH_JOIN [$$262][$$288]  |PARTITIONED|
+                                        exchange
+                                        -- HASH_PARTITION_EXCHANGE [$$262]  |PARTITIONED|
+                                          project ([$$298, $$262, $$294, $$270, $$273])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- HYBRID_HASH_JOIN [$$299][$$300]  |PARTITIONED|
-                                                -- HASH_PARTITION_EXCHANGE [$$299]  |PARTITIONED|
+                                              join (eq($$284, $$285))
+                                              -- HYBRID_HASH_JOIN [$$284][$$285]  |PARTITIONED|
+                                                exchange
+                                                -- HASH_PARTITION_EXCHANGE [$$284]  |PARTITIONED|
+                                                  project ([$$298, $$294, $$270, $$273, $$284])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- HYBRID_HASH_JOIN [$$291, $$293, $$295][$$305, $$306, $$307]  |PARTITIONED|
-                                                        -- HASH_PARTITION_EXCHANGE [$$291, $$293, $$295]  |PARTITIONED|
+                                                      join (and(eq($$290, $$276), eq($$291, $$278), eq($$292, $$280)))
+                                                      -- HYBRID_HASH_JOIN [$$276, $$278, $$280][$$290, $$291, $$292]  |PARTITIONED|
+                                                        exchange
+                                                        -- HASH_PARTITION_EXCHANGE [$$276, $$278, $$280]  |PARTITIONED|
+                                                          project ([$$298, $$294, $$284, $$276, $$278, $$280])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- HYBRID_HASH_JOIN [$$275, $$276][$$310, $$311]  |PARTITIONED|
-                                                                -- HASH_PARTITION_EXCHANGE [$$275, $$276]  |PARTITIONED|
+                                                              join (and(eq($$295, $$260), eq($$296, $$261)))
+                                                              -- HYBRID_HASH_JOIN [$$260, $$261][$$295, $$296]  |PARTITIONED|
+                                                                exchange
+                                                                -- HASH_PARTITION_EXCHANGE [$$260, $$261]  |PARTITIONED|
+                                                                  assign [$$284] <- [numeric-mod(numeric-multiply($$260, $$261), 10000)]
                                                                   -- ASSIGN  |PARTITIONED|
+                                                                    project ([$$261, $$260])
                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                      assign [$$261, $$260] <- [$$s.getField("s_i_id"), $$s.getField("s_w_id")]
                                                                       -- ASSIGN  |PARTITIONED|
+                                                                        project ([$$s])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                            -- DATASOURCE_SCAN (test.stock)  |PARTITIONED|
+                                                                            data-scan []<-[$$263, $$s] <- test.stock
+                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                empty-tuple-source
                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                                -- HASH_PARTITION_EXCHANGE [$$310, $$311]  |PARTITIONED|
+                                                                exchange
+                                                                -- HASH_PARTITION_EXCHANGE [$$295, $$296]  |PARTITIONED|
+                                                                  project ([$$298, $$294, $$276, $$278, $$280, $$295, $$296])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    select (and(ge($$269, "2017-01-01 00:00:00.000000"), le($$269, "2018-12-31 00:00:00.000000")))
                                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                                      project ([$$294, $$280, $$278, $$276, $$298, $$296, $$295, $$269])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        assign [$$298, $$296, $$295, $$269] <- [$$ol.getField("ol_amount"), $$ol.getField("ol_i_id"), $$ol.getField("ol_supply_w_id"), $$ol.getField("ol_delivery_d")]
                                                                         -- ASSIGN  |PARTITIONED|
+                                                                          project ([$$294, $$280, $$278, $$276, $$ol])
                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                            unnest $$ol <- scan-collection($$287)
                                                                             -- UNNEST  |PARTITIONED|
+                                                                              project ([$$294, $$280, $$278, $$276, $$287])
                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                assign [$$294, $$280, $$278, $$276, $$287] <- [$$o.getField("o_entry_d"), $$o.getField("o_d_id"), $$o.getField("o_w_id"), $$o.getField("o_c_id"), $$o.getField("o_orderline")]
                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                  project ([$$o])
                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                    exchange
                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                      -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                                                                      data-scan []<-[$$264, $$o] <- test.orders
+                                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                        exchange
                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                          empty-tuple-source
                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                        -- HASH_PARTITION_EXCHANGE [$$305, $$306, $$307]  |PARTITIONED|
+                                                        exchange
+                                                        -- HASH_PARTITION_EXCHANGE [$$290, $$291, $$292]  |PARTITIONED|
+                                                          assign [$$273] <- [get-item(string-to-codepoint($$270), 0)]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            project ([$$292, $$291, $$290, $$270])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              assign [$$292, $$291, $$290, $$270] <- [$$c.getField("c_d_id"), $$c.getField("c_w_id"), $$c.getField("c_id"), $$c.getField("c_state")]
                                                               -- ASSIGN  |PARTITIONED|
+                                                                project ([$$c])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (test.customer)  |PARTITIONED|
+                                                                    data-scan []<-[$$265, $$c] <- test.customer
+                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        empty-tuple-source
                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                -- HASH_PARTITION_EXCHANGE [$$300]  |PARTITIONED|
+                                                exchange
+                                                -- HASH_PARTITION_EXCHANGE [$$285]  |PARTITIONED|
+                                                  project ([$$262, $$285])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    assign [$$285, $$262] <- [$$su.getField("su_suppkey"), $$su.getField("su_nationkey")]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      project ([$$su])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- DATASOURCE_SCAN (test.supplier)  |PARTITIONED|
+                                                          data-scan []<-[$$268, $$su] <- test.supplier
+                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                              empty-tuple-source
                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          replicate
                                           -- REPLICATE  |PARTITIONED|
-                                            -- HASH_PARTITION_EXCHANGE [$$303]  |PARTITIONED|
+                                            exchange
+                                            -- HASH_PARTITION_EXCHANGE [$$288]  |PARTITIONED|
+                                              project ([$$271, $$288])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                assign [$$288, $$271] <- [$$n1.getField("n_nationkey"), $$n1.getField("n_name")]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  project ([$$n1])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.nation)  |PARTITIONED|
+                                                      data-scan []<-[$$266, $$n1] <- test.nation
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$272, $$289])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$272, $$289] <- [$$271, $$288]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        replicate
                                         -- REPLICATE  |PARTITIONED|
-                                          -- HASH_PARTITION_EXCHANGE [$$303]  |PARTITIONED|
+                                          exchange
+                                          -- HASH_PARTITION_EXCHANGE [$$288]  |PARTITIONED|
+                                            project ([$$271, $$288])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              assign [$$288, $$271] <- [$$n1.getField("n_nationkey"), $$n1.getField("n_name")]
                                               -- ASSIGN  |PARTITIONED|
+                                                project ([$$n1])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (test.nation)  |PARTITIONED|
+                                                    data-scan []<-[$$266, $$n1] <- test.nation
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/ch2/ch2_q8.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/ch2/ch2_q8.plan
index 9d2969e..1d848fb 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/ch2/ch2_q8.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/ch2/ch2_q8.plan
@@ -1,127 +1,248 @@
+distribute result [$$277]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$277])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$277] <- [{"l_year": $#1, "mkt_share": round(numeric-divide($$306, $$307), 2)}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$#1(ASC) ]  |PARTITIONED|
-          -- SORT_GROUP_BY[$$349]  |PARTITIONED|
-                  {
+          group by ([$#1 := $$333]) decor ([]) {
+                    aggregate [$$306, $$307] <- [agg-global-sql-sum($$331), agg-global-sql-sum($$332)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
-            -- HASH_PARTITION_EXCHANGE [$$349]  |PARTITIONED|
-              -- SORT_GROUP_BY[$$294]  |PARTITIONED|
-                      {
+                 }
+          -- SORT_GROUP_BY[$$333]  |PARTITIONED|
+            exchange
+            -- HASH_PARTITION_EXCHANGE [$$333]  |PARTITIONED|
+              group by ([$$333 := $$278]) decor ([]) {
+                        aggregate [$$331, $$332] <- [agg-local-sql-sum(switch-case(true, eq($$326, "Germany"), $$319, 0)), agg-local-sql-sum($$319)]
                         -- AGGREGATE  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SORT_GROUP_BY[$$278]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$326, $$319, $$278])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$278] <- [get-year(date($$289))]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$319, $$289, $$326])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- HYBRID_HASH_JOIN [$$325][$$326]  |PARTITIONED|
-                            -- HASH_PARTITION_EXCHANGE [$$325]  |PARTITIONED|
+                          join (eq($$309, $$310))
+                          -- HYBRID_HASH_JOIN [$$309][$$310]  |PARTITIONED|
+                            exchange
+                            -- HASH_PARTITION_EXCHANGE [$$309]  |PARTITIONED|
+                              project ([$$319, $$289, $$309])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- HYBRID_HASH_JOIN [$$320][$$341]  |PARTITIONED|
-                                    -- HASH_PARTITION_EXCHANGE [$$320]  |PARTITIONED|
+                                  join (eq($$304, $$325))
+                                  -- HYBRID_HASH_JOIN [$$304][$$325]  |PARTITIONED|
+                                    exchange
+                                    -- HASH_PARTITION_EXCHANGE [$$304]  |PARTITIONED|
+                                      project ([$$319, $$289, $$304])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- HYBRID_HASH_JOIN [$$308][$$309]  |PARTITIONED|
-                                            -- HASH_PARTITION_EXCHANGE [$$308]  |PARTITIONED|
+                                          join (eq($$292, $$293))
+                                          -- HYBRID_HASH_JOIN [$$292][$$293]  |PARTITIONED|
+                                            exchange
+                                            -- HASH_PARTITION_EXCHANGE [$$292]  |PARTITIONED|
+                                              project ([$$319, $$289, $$304, $$292])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- HYBRID_HASH_JOIN [$$311][$$331]  |PARTITIONED|
-                                                    -- HASH_PARTITION_EXCHANGE [$$311]  |PARTITIONED|
+                                                  join (eq($$315, $$295))
+                                                  -- HYBRID_HASH_JOIN [$$295][$$315]  |PARTITIONED|
+                                                    exchange
+                                                    -- HASH_PARTITION_EXCHANGE [$$295]  |PARTITIONED|
+                                                      project ([$$319, $$289, $$304, $$295])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- HYBRID_HASH_JOIN [$$313, $$315, $$317][$$333, $$334, $$332]  |PARTITIONED|
-                                                            -- HASH_PARTITION_EXCHANGE [$$313, $$315, $$317]  |PARTITIONED|
+                                                          join (and(eq($$317, $$297), eq($$318, $$299), eq($$316, $$301)))
+                                                          -- HYBRID_HASH_JOIN [$$297, $$299, $$301][$$317, $$318, $$316]  |PARTITIONED|
+                                                            exchange
+                                                            -- HASH_PARTITION_EXCHANGE [$$297, $$299, $$301]  |PARTITIONED|
+                                                              project ([$$319, $$289, $$304, $$297, $$299, $$301])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- HYBRID_HASH_JOIN [$$306][$$324]  |PARTITIONED|
-                                                                    -- HASH_PARTITION_EXCHANGE [$$306]  |PARTITIONED|
+                                                                  join (eq($$308, $$290))
+                                                                  -- HYBRID_HASH_JOIN [$$290][$$308]  |PARTITIONED|
+                                                                    exchange
+                                                                    -- HASH_PARTITION_EXCHANGE [$$290]  |PARTITIONED|
+                                                                      project ([$$319, $$289, $$304, $$297, $$299, $$301, $$290])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                          -- HYBRID_HASH_JOIN [$$296, $$295][$$306, $$336]  |PARTITIONED|
-                                                                            -- HASH_PARTITION_EXCHANGE [$$296, $$295]  |PARTITIONED|
+                                                                          join (and(eq($$290, $$280), eq($$320, $$279)))
+                                                                          -- HYBRID_HASH_JOIN [$$280, $$279][$$290, $$320]  |PARTITIONED|
+                                                                            exchange
+                                                                            -- HASH_PARTITION_EXCHANGE [$$280, $$279]  |PARTITIONED|
+                                                                              assign [$$304] <- [numeric-mod(numeric-multiply($$279, $$280), 10000)]
                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                project ([$$280, $$279])
                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                  assign [$$280, $$279] <- [$$s.getField("s_i_id"), $$s.getField("s_w_id")]
                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                    project ([$$s])
                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                        -- DATASOURCE_SCAN (test.stock)  |PARTITIONED|
+                                                                                        data-scan []<-[$$281, $$s] <- test.stock
+                                                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                            empty-tuple-source
                                                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                                            -- HASH_PARTITION_EXCHANGE [$$306, $$336]  |PARTITIONED|
+                                                                            exchange
+                                                                            -- HASH_PARTITION_EXCHANGE [$$290, $$320]  |PARTITIONED|
+                                                                              select (lt($$290, 1000))
                                                                               -- STREAM_SELECT  |PARTITIONED|
+                                                                                project ([$$301, $$299, $$297, $$289, $$320, $$319, $$290])
                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                  assign [$$320, $$319, $$290] <- [$$ol.getField("ol_supply_w_id"), $$ol.getField("ol_amount"), $$ol.getField("ol_i_id")]
                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                    project ([$$301, $$299, $$297, $$289, $$ol])
                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                      unnest $$ol <- scan-collection($$311)
                                                                                       -- UNNEST  |PARTITIONED|
+                                                                                        select (and(le($$289, "2018-12-31 00:00:00.000000"), ge($$289, "2017-01-01 00:00:00.000000")))
                                                                                         -- STREAM_SELECT  |PARTITIONED|
+                                                                                          project ([$$301, $$299, $$297, $$289, $$311])
                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                            assign [$$301, $$299, $$297, $$289, $$311] <- [$$o.getField("o_c_id"), $$o.getField("o_d_id"), $$o.getField("o_w_id"), $$o.getField("o_entry_d"), $$o.getField("o_orderline")]
                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                              project ([$$o])
                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                exchange
                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                  -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                                                                                  data-scan []<-[$$282, $$o] <- test.orders
+                                                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                    exchange
                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                      empty-tuple-source
                                                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                                    -- HASH_PARTITION_EXCHANGE [$$324]  |PARTITIONED|
+                                                                    exchange
+                                                                    -- HASH_PARTITION_EXCHANGE [$$308]  |PARTITIONED|
+                                                                      project ([$$308])
                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                        select (like($$i.getField("i_data"), "%b"))
                                                                         -- STREAM_SELECT  |PARTITIONED|
+                                                                          assign [$$308] <- [$$i.getField("i_id")]
                                                                           -- ASSIGN  |PARTITIONED|
+                                                                            project ([$$i])
                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                -- DATASOURCE_SCAN (test.item)  |PARTITIONED|
+                                                                                data-scan []<-[$$283, $$i] <- test.item
+                                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    empty-tuple-source
                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                            -- HASH_PARTITION_EXCHANGE [$$333, $$334, $$332]  |PARTITIONED|
+                                                            exchange
+                                                            -- HASH_PARTITION_EXCHANGE [$$317, $$318, $$316]  |PARTITIONED|
+                                                              project ([$$295, $$317, $$318, $$316])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$295, $$318, $$317, $$316] <- [get-item(string-to-codepoint($$c.getField("c_state")), 0), $$c.getField("c_d_id"), $$c.getField("c_w_id"), $$c.getField("c_id")]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  project ([$$c])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- DATASOURCE_SCAN (test.customer)  |PARTITIONED|
+                                                                      data-scan []<-[$$284, $$c] <- test.customer
+                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          empty-tuple-source
                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                    -- HASH_PARTITION_EXCHANGE [$$331]  |PARTITIONED|
+                                                    exchange
+                                                    -- HASH_PARTITION_EXCHANGE [$$315]  |PARTITIONED|
+                                                      project ([$$292, $$315])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$315, $$292] <- [$$n1.getField("n_nationkey"), $$n1.getField("n_regionkey")]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            replicate
                                                             -- REPLICATE  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                project ([$$n1])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (test.nation)  |PARTITIONED|
+                                                                    data-scan []<-[$$285, $$n1] <- test.nation
+                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        empty-tuple-source
                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                            -- HASH_PARTITION_EXCHANGE [$$309]  |PARTITIONED|
+                                            exchange
+                                            -- HASH_PARTITION_EXCHANGE [$$293]  |PARTITIONED|
+                                              project ([$$293])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                select (eq($$r.getField("r_name"), "Europe"))
                                                 -- STREAM_SELECT  |PARTITIONED|
+                                                  assign [$$293] <- [$$r.getField("r_regionkey")]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$r])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.region)  |PARTITIONED|
+                                                        data-scan []<-[$$286, $$r] <- test.region
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                    -- HASH_PARTITION_EXCHANGE [$$341]  |PARTITIONED|
+                                    exchange
+                                    -- HASH_PARTITION_EXCHANGE [$$325]  |PARTITIONED|
+                                      project ([$$309, $$325])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$325, $$309] <- [$$su.getField("su_suppkey"), $$su.getField("su_nationkey")]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$su])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.supplier)  |PARTITIONED|
+                                              data-scan []<-[$$287, $$su] <- test.supplier
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                            -- HASH_PARTITION_EXCHANGE [$$326]  |PARTITIONED|
+                            exchange
+                            -- HASH_PARTITION_EXCHANGE [$$310]  |PARTITIONED|
+                              project ([$$326, $$310])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$326, $$310] <- [$$n2.getField("n_name"), $$n2.getField("n_nationkey")]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$n2])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$n2] <- [$$n1]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        replicate
                                         -- REPLICATE  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            project ([$$n1])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- DATASOURCE_SCAN (test.nation)  |PARTITIONED|
+                                                data-scan []<-[$$285, $$n1] <- test.nation
+                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/ch2/ch2_q9.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/ch2/ch2_q9.plan
index 9eafc6f..a172b58 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/ch2/ch2_q9.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/ch2/ch2_q9.plan
@@ -1,80 +1,154 @@
+distribute result [$$184]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$184])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$184] <- [{"n_name": $$n_name, "l_year": $#1, "SUM_profit": round($$200, 2)}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$n_name(ASC), $#1(DESC) ]  |PARTITIONED|
-          -- SORT_GROUP_BY[$$229, $$230]  |PARTITIONED|
-                  {
+          group by ([$$n_name := $$217; $#1 := $$218]) decor ([]) {
+                    aggregate [$$200] <- [agg-global-sql-sum($$216)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
-            -- HASH_PARTITION_EXCHANGE [$$229, $$230]  |PARTITIONED|
-              -- SORT_GROUP_BY[$$225, $$198]  |PARTITIONED|
-                      {
+                 }
+          -- SORT_GROUP_BY[$$217, $$218]  |PARTITIONED|
+            exchange
+            -- HASH_PARTITION_EXCHANGE [$$217, $$218]  |PARTITIONED|
+              group by ([$$217 := $$213; $$218 := $$186]) decor ([]) {
+                        aggregate [$$216] <- [agg-local-sql-sum($$206)]
                         -- AGGREGATE  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SORT_GROUP_BY[$$213, $$186]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$206, $$213, $$186])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$186] <- [get-year(date($$207))]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$206, $$207, $$213])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- HYBRID_HASH_JOIN [$$213][$$214]  |PARTITIONED|
-                            -- HASH_PARTITION_EXCHANGE [$$213]  |PARTITIONED|
+                          join (eq($$201, $$202))
+                          -- HYBRID_HASH_JOIN [$$201][$$202]  |PARTITIONED|
+                            exchange
+                            -- HASH_PARTITION_EXCHANGE [$$201]  |PARTITIONED|
+                              project ([$$206, $$207, $$201])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- HYBRID_HASH_JOIN [$$210][$$224]  |PARTITIONED|
-                                    -- HASH_PARTITION_EXCHANGE [$$210]  |PARTITIONED|
+                                  join (eq($$198, $$212))
+                                  -- HYBRID_HASH_JOIN [$$198][$$212]  |PARTITIONED|
+                                    exchange
+                                    -- HASH_PARTITION_EXCHANGE [$$198]  |PARTITIONED|
+                                      project ([$$206, $$207, $$198])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- HYBRID_HASH_JOIN [$$206][$$207]  |PARTITIONED|
-                                            -- HASH_PARTITION_EXCHANGE [$$206]  |PARTITIONED|
+                                          join (eq($$194, $$195))
+                                          -- HYBRID_HASH_JOIN [$$194][$$195]  |PARTITIONED|
+                                            exchange
+                                            -- HASH_PARTITION_EXCHANGE [$$194]  |PARTITIONED|
+                                              project ([$$206, $$207, $$198, $$194])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- HYBRID_HASH_JOIN [$$200, $$199][$$206, $$217]  |PARTITIONED|
-                                                    -- HASH_PARTITION_EXCHANGE [$$200, $$199]  |PARTITIONED|
+                                                  join (and(eq($$194, $$188), eq($$205, $$187)))
+                                                  -- HYBRID_HASH_JOIN [$$188, $$187][$$194, $$205]  |PARTITIONED|
+                                                    exchange
+                                                    -- HASH_PARTITION_EXCHANGE [$$188, $$187]  |PARTITIONED|
+                                                      assign [$$198] <- [numeric-mod(numeric-multiply($$187, $$188), 10000)]
                                                       -- ASSIGN  |PARTITIONED|
+                                                        project ([$$188, $$187])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$188, $$187] <- [$$s.getField("s_i_id"), $$s.getField("s_w_id")]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            project ([$$s])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- DATASOURCE_SCAN (test.stock)  |PARTITIONED|
+                                                                data-scan []<-[$$189, $$s] <- test.stock
+                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    empty-tuple-source
                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                    -- HASH_PARTITION_EXCHANGE [$$206, $$217]  |PARTITIONED|
+                                                    exchange
+                                                    -- HASH_PARTITION_EXCHANGE [$$194, $$205]  |PARTITIONED|
+                                                      project ([$$206, $$207, $$194, $$205])
                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                        assign [$$206, $$205, $$194] <- [$$ol.getField("ol_amount"), $$ol.getField("ol_supply_w_id"), $$ol.getField("ol_i_id")]
                                                         -- ASSIGN  |PARTITIONED|
+                                                          project ([$$207, $$ol])
                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                            unnest $$ol <- scan-collection($$203)
                                                             -- UNNEST  |PARTITIONED|
+                                                              project ([$$207, $$203])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                assign [$$207, $$203] <- [$$o.getField("o_entry_d"), $$o.getField("o_orderline")]
                                                                 -- ASSIGN  |PARTITIONED|
+                                                                  project ([$$o])
                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                                                      data-scan []<-[$$190, $$o] <- test.orders
+                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                        exchange
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                          empty-tuple-source
                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                            -- HASH_PARTITION_EXCHANGE [$$207]  |PARTITIONED|
+                                            exchange
+                                            -- HASH_PARTITION_EXCHANGE [$$195]  |PARTITIONED|
+                                              project ([$$195])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                select (like($$i.getField("i_data"), "%bb"))
                                                 -- STREAM_SELECT  |PARTITIONED|
+                                                  assign [$$195] <- [$$i.getField("i_id")]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$i])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.item)  |PARTITIONED|
+                                                        data-scan []<-[$$191, $$i] <- test.item
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                    -- HASH_PARTITION_EXCHANGE [$$224]  |PARTITIONED|
+                                    exchange
+                                    -- HASH_PARTITION_EXCHANGE [$$212]  |PARTITIONED|
+                                      project ([$$201, $$212])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$212, $$201] <- [$$su.getField("su_suppkey"), $$su.getField("su_nationkey")]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$su])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.supplier)  |PARTITIONED|
+                                              data-scan []<-[$$192, $$su] <- test.supplier
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                            -- HASH_PARTITION_EXCHANGE [$$214]  |PARTITIONED|
+                            exchange
+                            -- HASH_PARTITION_EXCHANGE [$$202]  |PARTITIONED|
+                              project ([$$213, $$202])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                assign [$$213, $$202] <- [$$n.getField("n_name"), $$n.getField("n_nationkey")]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$n])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.nation)  |PARTITIONED|
+                                      data-scan []<-[$$193, $$n] <- test.nation
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/extract-common-operators/extract-common-operators.01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/extract-common-operators/extract-common-operators.01.plan
index 29aafbf..56adb39 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/extract-common-operators/extract-common-operators.01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/extract-common-operators/extract-common-operators.01.plan
@@ -1,90 +1,180 @@
+distribute result [$$373]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$373])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$373] <- [{"DataverseName": $$381, "SynonymName": $$382}]
       -- ASSIGN  |PARTITIONED|
-        -- SORT_MERGE_EXCHANGE [$$405(ASC), $$406(ASC) ]  |PARTITIONED|
-          -- STABLE_SORT [$$405(ASC), $$406(ASC)]  |PARTITIONED|
+        exchange
+        -- SORT_MERGE_EXCHANGE [$$381(ASC), $$382(ASC) ]  |PARTITIONED|
+          order (ASC, $$381) (ASC, $$382)
+          -- STABLE_SORT [$$381(ASC), $$382(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$381, $$382])
               -- STREAM_PROJECT  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- HYBRID_HASH_JOIN [$$414][$$410]  |PARTITIONED|
-                    -- HASH_PARTITION_MERGE_EXCHANGE MERGE:[$$405(ASC), $$406(ASC)] HASH:[$$414]  |PARTITIONED|
-                      -- STABLE_SORT [$$405(ASC), $$406(ASC)]  |PARTITIONED|
+                  left outer join (eq($$390, $$386))
+                  -- HYBRID_HASH_JOIN [$$390][$$386]  |PARTITIONED|
+                    exchange
+                    -- HASH_PARTITION_MERGE_EXCHANGE MERGE:[$$381(ASC), $$382(ASC)] HASH:[$$390]  |PARTITIONED|
+                      order (ASC, $$381) (ASC, $$382)
+                      -- STABLE_SORT [$$381(ASC), $$382(ASC)]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$381, $$382, $$390])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- HYBRID_HASH_JOIN [$$414][$$408]  |PARTITIONED|
-                                -- HASH_PARTITION_EXCHANGE [$$414]  |PARTITIONED|
+                              left outer join (eq($$384, $$390))
+                              -- HYBRID_HASH_JOIN [$$390][$$384]  |PARTITIONED|
+                                exchange
+                                -- HASH_PARTITION_EXCHANGE [$$390]  |PARTITIONED|
+                                  project ([$$381, $$382, $$390])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$390] <- [$$s.getField(3)]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$381, $$382, $$s])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$381, $$382, $$s] <- [$$385, $$386, $$s]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- DATASOURCE_SCAN (Metadata.Synonym)  |PARTITIONED|
+                                                data-scan []<-[$$385, $$386, $$s] <- Metadata.Synonym
+                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                -- HASH_PARTITION_EXCHANGE [$$408]  |PARTITIONED|
+                                exchange
+                                -- HASH_PARTITION_EXCHANGE [$$384]  |PARTITIONED|
+                                  project ([$$384])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- HYBRID_HASH_JOIN [$$408][$$ds_name]  |PARTITIONED|
+                                      join (eq($$384, $$ds_name))
+                                      -- HYBRID_HASH_JOIN [$$384][$$ds_name]  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          replicate
                                           -- REPLICATE  |PARTITIONED|
+                                            exchange
                                             -- RANDOM_PARTITION_EXCHANGE  |PARTITIONED|
+                                              project ([$$384])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- BTREE_SEARCH (Metadata.Dataset.Dataset)  |PARTITIONED|
+                                                  unnest-map [$$383, $$384, $$d] <- index-search("Dataset", 0, "Metadata", "Dataset", true, true, 1, $$dv_name, 1, $$dv_name, true, true, true)
+                                                  -- BTREE_SEARCH  |PARTITIONED|
+                                                    exchange
                                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                      unnest $$dv_name <- scan-collection(array: [ "test2", "test1" ])
                                                       -- UNNEST  |UNPARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          replicate
                                           -- REPLICATE  |PARTITIONED|
+                                            exchange
                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                              unnest $$ds_name <- scan-collection(array: [ "ds2", "ds1" ])
                                               -- UNNEST  |UNPARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
-                    -- HASH_PARTITION_EXCHANGE [$$410]  |PARTITIONED|
+                    exchange
+                    -- HASH_PARTITION_EXCHANGE [$$386]  |PARTITIONED|
+                      project ([$$386])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- HYBRID_HASH_JOIN [$$428][$$412]  |PARTITIONED|
-                            -- HASH_PARTITION_EXCHANGE [$$428]  |PARTITIONED|
+                          left outer join (eq($$388, $$404))
+                          -- HYBRID_HASH_JOIN [$$404][$$388]  |PARTITIONED|
+                            exchange
+                            -- HASH_PARTITION_EXCHANGE [$$404]  |PARTITIONED|
+                              project ([$$386, $$404])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- HYBRID_HASH_JOIN [$$410][$$syn_name]  |PARTITIONED|
+                                  join (eq($$386, $$syn_name))
+                                  -- HYBRID_HASH_JOIN [$$386][$$syn_name]  |PARTITIONED|
+                                    exchange
                                     -- RANDOM_PARTITION_EXCHANGE  |PARTITIONED|
+                                      project ([$$386, $$404])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$404] <- [$$s.getField(3)]
                                         -- ASSIGN  |PARTITIONED|
+                                          project ([$$386, $$s])
                                           -- STREAM_PROJECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              replicate
                                               -- REPLICATE  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- DATASOURCE_SCAN (Metadata.Synonym)  |PARTITIONED|
+                                                  data-scan []<-[$$385, $$386, $$s] <- Metadata.Synonym
+                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      empty-tuple-source
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                      unnest $$syn_name <- scan-collection(array: [ "syn2", "syn1" ])
                                       -- UNNEST  |UNPARTITIONED|
+                                        empty-tuple-source
                                         -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
-                            -- HASH_PARTITION_EXCHANGE [$$412]  |PARTITIONED|
+                            exchange
+                            -- HASH_PARTITION_EXCHANGE [$$388]  |PARTITIONED|
+                              project ([$$388])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- HYBRID_HASH_JOIN [$$412][$$ds_name]  |PARTITIONED|
+                                  join (eq($$388, $$ds_name))
+                                  -- HYBRID_HASH_JOIN [$$388][$$ds_name]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$388])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$388] <- [$$384]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- RANDOM_PARTITION_EXCHANGE  |PARTITIONED|
+                                                project ([$$384])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- BTREE_SEARCH (Metadata.Dataset.Dataset)  |PARTITIONED|
+                                                    unnest-map [$$383, $$384, $$d] <- index-search("Dataset", 0, "Metadata", "Dataset", true, true, 1, $$dv_name, 1, $$dv_name, true, true, true)
+                                                    -- BTREE_SEARCH  |PARTITIONED|
+                                                      exchange
                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                        unnest $$dv_name <- scan-collection(array: [ "test2", "test1" ])
                                                         -- UNNEST  |UNPARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$ds_name])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$ds_name] <- [$$ds_name]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            replicate
                                             -- REPLICATE  |PARTITIONED|
+                                              exchange
                                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                unnest $$ds_name <- scan-collection(array: [ "ds2", "ds1" ])
                                                 -- UNNEST  |UNPARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/filter/inverted-btree-search-return-optional-field.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/filter/inverted-btree-search-return-optional-field.plan
index 6993f25..c8613c4 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/filter/inverted-btree-search-return-optional-field.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/filter/inverted-btree-search-return-optional-field.plan
@@ -1,26 +1,52 @@
+distribute result [$$37]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    limit 2147483647 offset 0
     -- STREAM_LIMIT  |UNPARTITIONED|
+      project ([$$37])
       -- STREAM_PROJECT  |PARTITIONED|
+        assign [$$37] <- [{"place.bounding_box": $$44, "user.id": $$45, "id": $$40, "coordinate": $$47, "create_at": $$39}]
         -- ASSIGN  |PARTITIONED|
+          exchange
           -- SORT_MERGE_EXCHANGE [$$39(DESC) ]  |PARTITIONED|
+            limit 2147483647
             -- STREAM_LIMIT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (topK: 2147483647) (DESC, $$39)
                 -- STABLE_SORT [topK: 2147483647] [$$39(DESC)]  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([$$44, $$45, $$40, $$47, $$39])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        join (eq($$41, $$26))
                         -- HYBRID_HASH_JOIN [$$26][$$41]  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$44, $$45, $$40, $$47, $$39, $$26])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              select (and(ftcontains($$t.getField(2), array: [ "francisco" ], "mode", "all"), ge($$39, datetime: { 2018-02-22T10:53:07.888 }), lt($$39, datetime: { 2018-02-22T18:50:39.301 })))
                               -- STREAM_SELECT  |PARTITIONED|
+                                assign [$$26, $$44, $$45, $$47, $$39] <- [$$t.getField(14).getField(0), $$t.getField(13).getField(6), $$t.getField(12).getField(0), $$t.getField(6), $$t.getField(0)]
                                 -- ASSIGN  |PARTITIONED|
+                                  project ([$$40, $$t])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (twitter.ds_tweet)  |PARTITIONED|
+                                      data-scan []<-[$$40, $$t] <- twitter.ds_tweet with filter on min:[$$51] max:[$$52]
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                          assign [$$51, $$52] <- [datetime: { 2018-02-22T10:53:07.888 }, datetime: { 2018-02-22T18:50:39.301 }]
                                           -- ASSIGN  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                            unnest $$41 <- scan-collection(array: [ 51, 37, 24, 11 ])
                             -- UNNEST  |UNPARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/filter_on_meta_with_idx_2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/filter_on_meta_with_idx_2.plan
deleted file mode 100644
index 05da710..0000000
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/filter_on_meta_with_idx_2.plan
+++ /dev/null
@@ -1,25 +0,0 @@
--- DISTRIBUTE_RESULT  |PARTITIONED|
-  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- STREAM_PROJECT  |PARTITIONED|
-      -- ASSIGN  |PARTITIONED|
-        -- STREAM_PROJECT  |PARTITIONED|
-          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- HYBRID_HASH_JOIN [$$37][$$38]  |PARTITIONED|
-              -- HASH_PARTITION_EXCHANGE [$$37]  |PARTITIONED|
-                -- STREAM_PROJECT  |PARTITIONED|
-                  -- STREAM_SELECT  |PARTITIONED|
-                    -- ASSIGN  |PARTITIONED|
-                      -- STREAM_PROJECT  |PARTITIONED|
-                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (test.KVStore)  |PARTITIONED|
-                            -- BROADCAST_EXCHANGE  |PARTITIONED|
-                              -- ASSIGN  |PARTITIONED|
-                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-              -- HASH_PARTITION_EXCHANGE [$$38]  |PARTITIONED|
-                -- STREAM_PROJECT  |PARTITIONED|
-                  -- ASSIGN  |PARTITIONED|
-                    -- STREAM_PROJECT  |PARTITIONED|
-                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.OfficerLocations)  |PARTITIONED|
-                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/group-by/listify-3.1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/group-by/listify-3.1.plan
index ec40853..ce04f7a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/group-by/listify-3.1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/group-by/listify-3.1.plan
@@ -1,43 +1,86 @@
+distribute result [$$136]
 -- DISTRIBUTE_RESULT  |LOCAL|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+    project ([$$136])
     -- STREAM_PROJECT  |LOCAL|
+      assign [$$136] <- [{"std": round-half-to-even(sqrt($$137), 2)}]
       -- ASSIGN  |LOCAL|
+        aggregate [$$137] <- [agg-global-sql-avg($$154)]
         -- AGGREGATE  |LOCAL|
+          aggregate [$$154] <- [agg-local-sql-avg($$134)]
           -- AGGREGATE  |LOCAL|
+            project ([$$134])
             -- STREAM_PROJECT  |LOCAL|
+              assign [$$134] <- [power(numeric-subtract(numeric-add(numeric-subtract($$144, $$t), $$145), 1), 2)]
               -- ASSIGN  |LOCAL|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                  join (true)
                   -- NESTED_LOOP  |LOCAL|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+                      unnest $$t <- range(1, 10)
                       -- UNNEST  |UNPARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                      join (true)
                       -- NESTED_LOOP  |LOCAL|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                          project ([$$144])
                           -- STREAM_PROJECT  |LOCAL|
+                            assign [$$144] <- [get-item($$105, 0).getField(0)]
                             -- ASSIGN  |LOCAL|
+                              project ([$$105])
                               -- STREAM_PROJECT  |LOCAL|
+                                assign [$$105] <- [$$121]
                                 -- ASSIGN  |LOCAL|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                                    replicate
                                     -- REPLICATE  |LOCAL|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                                        aggregate [$$121] <- [listify($$120)]
                                         -- AGGREGATE  |LOCAL|
+                                          project ([$$120])
                                           -- STREAM_PROJECT  |LOCAL|
+                                            assign [$$120] <- [{"mean": $$150, "min": $$151}]
                                             -- ASSIGN  |LOCAL|
+                                              aggregate [$$150, $$151] <- [agg-global-sql-avg($$155), agg-global-sql-min($$156)]
                                               -- AGGREGATE  |LOCAL|
+                                                aggregate [$$155, $$156] <- [agg-local-sql-avg($$140), agg-local-sql-min($$140)]
                                                 -- AGGREGATE  |LOCAL|
+                                                  unnest $$140 <- range(1, 10)
                                                   -- UNNEST  |UNPARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                          project ([$$145])
                           -- STREAM_PROJECT  |LOCAL|
+                            assign [$$145] <- [get-item($$121, 0).getField(1)]
                             -- ASSIGN  |LOCAL|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                                replicate
                                 -- REPLICATE  |LOCAL|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
+                                    aggregate [$$121] <- [listify($$120)]
                                     -- AGGREGATE  |LOCAL|
+                                      project ([$$120])
                                       -- STREAM_PROJECT  |LOCAL|
+                                        assign [$$120] <- [{"mean": $$150, "min": $$151}]
                                         -- ASSIGN  |LOCAL|
+                                          aggregate [$$150, $$151] <- [agg-global-sql-avg($$155), agg-global-sql-min($$156)]
                                           -- AGGREGATE  |LOCAL|
+                                            aggregate [$$155, $$156] <- [agg-local-sql-avg($$140), agg-local-sql-min($$140)]
                                             -- AGGREGATE  |LOCAL|
+                                              unnest $$140 <- range(1, 10)
                                               -- UNNEST  |UNPARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/hash-join-with-redundant-variable/hash-join-with-redundant-variable.1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/hash-join-with-redundant-variable/hash-join-with-redundant-variable.1.plan
index 65df3c2..a8830cc 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/hash-join-with-redundant-variable/hash-join-with-redundant-variable.1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/hash-join-with-redundant-variable/hash-join-with-redundant-variable.1.plan
@@ -1,74 +1,148 @@
+distribute result [$$124]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    aggregate [$$124] <- [agg-sql-sum($$134)]
     -- AGGREGATE  |UNPARTITIONED|
+      exchange
       -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+        aggregate [$$134] <- [agg-sql-count(1)]
         -- AGGREGATE  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+            join (eq($$129, $$130))
             -- HYBRID_HASH_JOIN [$$130][$$129]  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$130]  |PARTITIONED|
+                project ([$$130])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (eq($$r.getField("r_name"), "EUROPE"))
                   -- STREAM_SELECT  |PARTITIONED|
+                    assign [$$130] <- [$$r.getField("r_regionkey")]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$r])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (test.region)  |PARTITIONED|
+                          data-scan []<-[$$118, $$r] <- test.region
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- HASH_PARTITION_EXCHANGE [$$129]  |PARTITIONED|
+                project ([$$129])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    join (and(eq($$127, $$128), eq($$131, $$132)))
                     -- HYBRID_HASH_JOIN [$$127, $$131][$$128, $$132]  |PARTITIONED|
+                      exchange
                       -- HASH_PARTITION_EXCHANGE [$$127, $$131]  |PARTITIONED|
+                        project ([$$127, $$131])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$127, $$131] <- [$$l.getField("l_suppkey"), $$l.getField("l_orderkey")]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$l])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.lineitem)  |PARTITIONED|
+                                data-scan []<-[$$122, $$l] <- test.lineitem
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      exchange
                       -- HASH_PARTITION_EXCHANGE [$$128, $$132]  |PARTITIONED|
+                        project ([$$132, $$129, $$128])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            join (eq($$125, $$126))
                             -- HYBRID_HASH_JOIN [$$126][$$125]  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$126]  |PARTITIONED|
+                                project ([$$132, $$126])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  select (and(ge($$114, "1993-01-01"), lt($$114, "1993-04-01")))
                                   -- STREAM_SELECT  |PARTITIONED|
+                                    project ([$$132, $$126, $$114])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$132, $$126, $$114] <- [$$o.getField("o_orderkey"), $$o.getField("o_custkey"), $$o.getField("o_orderdate")]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$o])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (test.orders)  |PARTITIONED|
+                                            data-scan []<-[$$121, $$o] <- test.orders
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- HASH_PARTITION_EXCHANGE [$$125]  |PARTITIONED|
+                                project ([$$129, $$125, $$128])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    join (eq($$116, $$117))
                                     -- HYBRID_HASH_JOIN [$$117][$$116]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$117, $$129, $$125])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            join (eq($$115, $$117))
                                             -- HYBRID_HASH_JOIN [$$117][$$115]  |PARTITIONED|
+                                              exchange
                                               -- HASH_PARTITION_EXCHANGE [$$117]  |PARTITIONED|
+                                                project ([$$117, $$129])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$117, $$129] <- [$$n.getField("n_nationkey"), $$n.getField("n_regionkey")]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$n])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.nation)  |PARTITIONED|
+                                                        data-scan []<-[$$119, $$n] <- test.nation
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                              exchange
                                               -- HASH_PARTITION_EXCHANGE [$$115]  |PARTITIONED|
+                                                project ([$$115, $$125])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$115, $$125] <- [$$c.getField("c_nationkey"), $$c.getField("c_custkey")]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$c])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.customer)  |PARTITIONED|
+                                                        data-scan []<-[$$120, $$c] <- test.customer
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                      exchange
                                       -- HASH_PARTITION_EXCHANGE [$$116]  |PARTITIONED|
+                                        project ([$$128, $$116])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$128, $$116] <- [$$s.getField("s_suppkey"), $$s.getField("s_nationkey")]
                                           -- ASSIGN  |PARTITIONED|
+                                            project ([$$s])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- DATASOURCE_SCAN (test.supplier)  |PARTITIONED|
+                                                data-scan []<-[$$123, $$s] <- test.supplier
+                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/inverted-index-basic/ngram-contains.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/inverted-index-basic/ngram-contains.plan
index 8a9e3fa..529a662 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/inverted-index-basic/ngram-contains.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/inverted-index-basic/ngram-contains.plan
@@ -1,9 +1,18 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$o])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- SORT_MERGE_EXCHANGE [$$15(ASC) ]  |PARTITIONED|
+        select (contains($$o.getField(2), "Multimedia"))
         -- STREAM_SELECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+            data-scan []<-[$$15, $$o] <- test.DBLP
+            -- DATASOURCE_SCAN  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                empty-tuple-source
                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/inverted-index-basic/ngram-contains_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/inverted-index-basic/ngram-contains_ps.plan
index 93ca5bd..d6a002c 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/inverted-index-basic/ngram-contains_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/inverted-index-basic/ngram-contains_ps.plan
@@ -1,28 +1,56 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$o])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$15)
         -- STABLE_SORT [$$15(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$15(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$20
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (contains($$o.getField(2), "Multimedia"))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                        data-scan []<-[$$15, $$o] <- test.DBLP
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$20] <- [agg-range-map($$18, $$19)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$18, $$19] <- [agg-local-sampling($$15), agg-null-writer($$15)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$15])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (contains($$o.getField(2), "Multimedia"))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                  data-scan []<-[$$15, $$o] <- test.DBLP
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/joins/nlj_partitioning_property_1.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/joins/nlj_partitioning_property_1.plan
index 91a6aca..cc4df29 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/joins/nlj_partitioning_property_1.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/joins/nlj_partitioning_property_1.plan
@@ -1,31 +1,62 @@
+distribute result [$$70]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$70])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$70] <- [{"count": $$77}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$77] <- [agg-sql-sum($$79)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$79] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                join (true)
                 -- NESTED_LOOP  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    project ([])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- HYBRID_HASH_JOIN [$$76][$$78]  |PARTITIONED|
+                        join (eq($$71, $$73))
+                        -- HYBRID_HASH_JOIN [$$71][$$73]  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$71])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (tpch.Supplier)  |PARTITIONED|
+                                data-scan []<-[$$71, $$s] <- tpch.Supplier
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                          exchange
                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                            project ([$$73])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (tpch.Partsupp)  |PARTITIONED|
+                                data-scan []<-[$$72, $$73, $$ps] <- tpch.Partsupp
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    project ([])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (tpch.Part)  |PARTITIONED|
+                        data-scan []<-[$$74, $$p] <- tpch.Part
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/joins/nlj_partitioning_property_2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/joins/nlj_partitioning_property_2.plan
index c1554e2..66c9edc 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/joins/nlj_partitioning_property_2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/joins/nlj_partitioning_property_2.plan
@@ -1,29 +1,58 @@
+distribute result [$$67]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$67])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$67] <- [{"count": $$72}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$72] <- [agg-sql-sum($$73)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$73] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                join (true)
                 -- NESTED_LOOP  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    join (true)
                     -- NESTED_LOOP  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (tpch.Supplier)  |PARTITIONED|
+                            data-scan []<-[$$68, $$s] <- tpch.Supplier
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      exchange
                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                        project ([])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (tpch.Partsupp)  |PARTITIONED|
+                            data-scan []<-[$$69, $$70, $$ps] <- tpch.Partsupp
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  exchange
                   -- BROADCAST_EXCHANGE  |PARTITIONED|
+                    project ([])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (tpch.Part)  |PARTITIONED|
+                        data-scan []<-[$$71, $$p] <- tpch.Part
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/meta/indexes_on_dataset_with_meta_05.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/meta/indexes_on_dataset_with_meta_05.plan
index 6013ad8..5611b54 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/meta/indexes_on_dataset_with_meta_05.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/meta/indexes_on_dataset_with_meta_05.plan
@@ -1,18 +1,36 @@
+distribute result [$$27]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$27])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$27] <- [{"ds2": $$ds2, "ds1": $$ds1}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$ds2, $$ds1])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- SORT_MERGE_EXCHANGE [$$29(ASC) ]  |PARTITIONED|
+            project ([$$ds2, $$ds1, $$29])
             -- STREAM_PROJECT  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- BTREE_SEARCH (test.DS2.DS2)  |PARTITIONED|
+                unnest-map [$$29, $$ds2, $$30] <- index-search("DS2", 0, "test", "DS2", true, true, 1, $$34, 1, $$34, true, true, true)
+                -- BTREE_SEARCH  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    order (ASC, $$34)
                     -- STABLE_SORT [$$34(ASC)]  |PARTITIONED|
+                      exchange
                       -- HASH_PARTITION_EXCHANGE [$$34]  |PARTITIONED|
+                        assign [$$34] <- [$$ds1.getField(0)]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$ds1])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (test.DS1)  |PARTITIONED|
+                              data-scan []<-[$$31, $$ds1, $$32] <- test.DS1
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/meta/indexes_on_dataset_with_meta_08.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/meta/indexes_on_dataset_with_meta_08.plan
index 2561ec6..b15b9b7 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/meta/indexes_on_dataset_with_meta_08.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/meta/indexes_on_dataset_with_meta_08.plan
@@ -1,10 +1,20 @@
+distribute result [$$15]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$15])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$15] <- [{"DS1": $$DS1}]
       -- ASSIGN  |PARTITIONED|
+        select (eq($$DS1.getField(0), "2"))
         -- STREAM_SELECT  |PARTITIONED|
+          project ([$$DS1])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- DATASOURCE_SCAN (test.DS1)  |PARTITIONED|
+              data-scan []<-[$$16, $$DS1, $$17] <- test.DS1
+              -- DATASOURCE_SCAN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  empty-tuple-source
                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/multipart-dataverse/index/index-01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/multipart-dataverse/index/index-01.plan
index a794105..78851a9 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/multipart-dataverse/index/index-01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/multipart-dataverse/index/index-01.plan
@@ -1,8 +1,16 @@
+distribute result [$$l]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (and(eq($$l.getField(1), "Julio"), eq($$l.getField(2), "Isa")))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$l])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (x.y.employee)  |PARTITIONED|
+          data-scan []<-[$$17, $$l] <- x.y.employee
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/multipart-dataverse/index/index-02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/multipart-dataverse/index/index-02.plan
index a794105..78851a9 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/multipart-dataverse/index/index-02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/multipart-dataverse/index/index-02.plan
@@ -1,8 +1,16 @@
+distribute result [$$l]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (and(eq($$l.getField(1), "Julio"), eq($$l.getField(2), "Isa")))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$l])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (x.y.employee)  |PARTITIONED|
+          data-scan []<-[$$17, $$l] <- x.y.employee
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-index/btree-index-join/ASTERIXDB-2199.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-index/btree-index-join/ASTERIXDB-2199.plan
deleted file mode 100644
index 46dbf81..0000000
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-index/btree-index-join/ASTERIXDB-2199.plan
+++ /dev/null
@@ -1,15 +0,0 @@
--- DISTRIBUTE_RESULT  |PARTITIONED|
-  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- STREAM_PROJECT  |PARTITIONED|
-      -- ASSIGN  |PARTITIONED|
-        -- STREAM_PROJECT  |PARTITIONED|
-          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- HYBRID_HASH_JOIN [$$36][$$37]  |PARTITIONED|
-              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (Facebook.Friendship)  |PARTITIONED|
-                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- DATASOURCE_SCAN (Facebook.Friendship)  |PARTITIONED|
-                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-index/inverted-index-basic/ngram-contains_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-index/inverted-index-basic/ngram-contains_ps.plan
index 5a051c1..06cbf5e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-index/inverted-index-basic/ngram-contains_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-index/inverted-index-basic/ngram-contains_ps.plan
@@ -1,28 +1,56 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$o])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$17)
         -- STABLE_SORT [$$17(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$17(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$23
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (contains($$o.getField(0).getField(2), "Multimedia"))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                        data-scan []<-[$$17, $$o] <- test.DBLP
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$23] <- [agg-range-map($$21, $$22)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$21, $$22] <- [agg-local-sampling($$17), agg-null-writer($$17)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$17])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (contains($$o.getField(0).getField(2), "Multimedia"))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                  data-scan []<-[$$17, $$o] <- test.DBLP
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/05.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/05.plan
deleted file mode 100644
index 9ae6c48..0000000
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index-join/non-enforced-composite-key-equi-join/05.plan
+++ /dev/null
@@ -1,30 +0,0 @@
--- DISTRIBUTE_RESULT  |PARTITIONED|
-  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- STREAM_PROJECT  |PARTITIONED|
-      -- ASSIGN  |PARTITIONED|
-        -- SORT_MERGE_EXCHANGE [$$48(ASC), $$49(ASC) ]  |PARTITIONED|
-          -- STABLE_SORT [$$48(ASC), $$49(ASC)]  |PARTITIONED|
-            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- STREAM_PROJECT  |PARTITIONED|
-                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- HYBRID_HASH_JOIN [$$45][$$46]  |PARTITIONED|
-                    -- HASH_PARTITION_EXCHANGE [$$45]  |PARTITIONED|
-                      -- STREAM_PROJECT  |PARTITIONED|
-                        -- ASSIGN  |PARTITIONED|
-                          -- STREAM_PROJECT  |PARTITIONED|
-                            -- ASSIGN  |PARTITIONED|
-                              -- STREAM_PROJECT  |PARTITIONED|
-                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.TestOpen1)  |PARTITIONED|
-                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                    -- HASH_PARTITION_EXCHANGE [$$46]  |PARTITIONED|
-                      -- STREAM_PROJECT  |PARTITIONED|
-                        -- ASSIGN  |PARTITIONED|
-                          -- STREAM_PROJECT  |PARTITIONED|
-                            -- ASSIGN  |PARTITIONED|
-                              -- STREAM_PROJECT  |PARTITIONED|
-                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.TestOpen2)  |PARTITIONED|
-                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/01.plan
index 5454dab..cf5f353 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/01.plan
@@ -1,8 +1,16 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (gt($$emp.getField("nested").getField("fname"), "Roger"))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+          data-scan []<-[$$15, $$emp] <- test.testdst
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/02.plan
index 5454dab..4457e66 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/02.plan
@@ -1,8 +1,16 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    select (gt($$emp.getField("nested").getField("address").getField("zip"), "97777"))
     -- STREAM_SELECT  |PARTITIONED|
+      project ([$$emp])
       -- STREAM_PROJECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+          data-scan []<-[$$16, $$emp] <- test.testdst
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/03.plan
index d874441..bb62274 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/03.plan
@@ -1,15 +1,30 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$17] <- [{"res": $$21}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$21(ASC) ]  |PARTITIONED|
+          order (ASC, $$21)
           -- STABLE_SORT [$$21(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$21])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (eq($$t.getField("nested").getField("c_i64"), 2))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$21] <- [$$t.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$t])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                        data-scan []<-[$$19, $$t] <- test.TestOpen
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/04.plan
index 58cd521..342d0fc 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/04.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/04.plan
@@ -1,17 +1,34 @@
+distribute result [$$18]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$18])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$18] <- [{"res": $$24}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$24(ASC) ]  |PARTITIONED|
+          order (ASC, $$24)
           -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$24])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (eq($$26.getField("c_s"), "world"))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$24] <- [$$26.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$26])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$26] <- [$$t.getField("nested")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$t])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                            data-scan []<-[$$22, $$t] <- test.TestOpen
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/05.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/05.plan
index 58cd521..ed35956 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/05.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/05.plan
@@ -1,17 +1,34 @@
+distribute result [$$18]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$18])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$18] <- [{"res": $$24}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$24(ASC) ]  |PARTITIONED|
+          order (ASC, $$24)
           -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$24])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (eq($$26.getField("c_i64"), 2))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$24] <- [$$26.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$26])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$26] <- [$$t.getField("nested")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$t])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                            data-scan []<-[$$22, $$t] <- test.TestOpen
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/06.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/06.plan
index 58cd521..da8942a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/06.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/06.plan
@@ -1,17 +1,34 @@
+distribute result [$$18]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$18])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$18] <- [{"res": $$24}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$24(ASC) ]  |PARTITIONED|
+          order (ASC, $$24)
           -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$24])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (gt($$26.getField("c_i64"), 2))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$24] <- [$$26.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$26])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$26] <- [$$t.getField("nested")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$t])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                            data-scan []<-[$$22, $$t] <- test.TestOpen
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/07.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/07.plan
index 58cd521..93c1a06 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/07.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/07.plan
@@ -1,17 +1,34 @@
+distribute result [$$18]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$18])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$18] <- [{"res": $$24}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$24(ASC) ]  |PARTITIONED|
+          order (ASC, $$24)
           -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$24])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (gt($$26.getField("c_i64"), 2.0))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$24] <- [$$26.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$26])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$26] <- [$$t.getField("nested")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$t])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                            data-scan []<-[$$22, $$t] <- test.TestOpen
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/08.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/08.plan
index 58cd521..2277b8f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/08.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/08.plan
@@ -1,17 +1,34 @@
+distribute result [$$18]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$18])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$18] <- [{"res": $$24}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$24(ASC) ]  |PARTITIONED|
+          order (ASC, $$24)
           -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$24])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (gt($$26.getField("c_i8"), 2))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$24] <- [$$26.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$26])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$26] <- [$$t.getField("nested")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$t])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                            data-scan []<-[$$22, $$t] <- test.TestOpen
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/09.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/09.plan
index 58cd521..48527e5 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/09.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/09.plan
@@ -1,17 +1,34 @@
+distribute result [$$18]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$18])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$18] <- [{"res": $$24}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$24(ASC) ]  |PARTITIONED|
+          order (ASC, $$24)
           -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$24])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (gt($$26.getField("c_i8"), 2.5))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$24] <- [$$26.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$26])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$26] <- [$$t.getField("nested")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$t])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                            data-scan []<-[$$22, $$t] <- test.TestOpen
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/10.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/10.plan
index 58cd521..dcb49ae 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/10.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/10.plan
@@ -1,17 +1,34 @@
+distribute result [$$18]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$18])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$18] <- [{"res": $$24}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$24(ASC) ]  |PARTITIONED|
+          order (ASC, $$24)
           -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$24])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (ge($$26.getField("c_d"), 3.25))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$24] <- [$$26.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$26])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$26] <- [$$t.getField("nested")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$t])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                            data-scan []<-[$$22, $$t] <- test.TestOpen
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/11.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/11.plan
index bbd2dba..48d021d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/11.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/11.plan
@@ -1,18 +1,36 @@
+distribute result [$$22]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$22])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$22] <- [{"res": $$29}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$29(ASC) ]  |PARTITIONED|
+          order (ASC, $$29)
           -- STABLE_SORT [$$29(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$29])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (and(gt($$25, 499), lt($$25, 99999)))
                 -- STREAM_SELECT  |PARTITIONED|
+                  project ([$$29, $$25])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$29, $$25] <- [$$31.getField("c_x"), $$31.getField("c_i8")]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$31])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        assign [$$31] <- [$$t.getField("nested")]
                         -- ASSIGN  |PARTITIONED|
+                          project ([$$t])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                              data-scan []<-[$$27, $$t] <- test.TestOpen
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/12.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/12.plan
index fde8db4..9e1edf1 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/12.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/btree-index/non-enforced-composite-key/12.plan
@@ -1,17 +1,34 @@
+distribute result [$$22]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$22])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$22] <- [{"res": $$29}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$29(ASC) ]  |PARTITIONED|
+          order (ASC, $$29)
           -- STABLE_SORT [$$29(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$29])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (and(gt($$31.getField("c_i8"), 2), lt($$31.getField("c_i64"), 3)))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$29] <- [$$31.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$31])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      assign [$$31] <- [$$t.getField("nested")]
                       -- ASSIGN  |PARTITIONED|
+                        project ([$$t])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                            data-scan []<-[$$26, $$t] <- test.TestOpen
+                            -- DATASOURCE_SCAN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                empty-tuple-source
                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/inverted-index-basic/ngram-contains_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/inverted-index-basic/ngram-contains_ps.plan
index 5a051c1..36c0dff 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/inverted-index-basic/ngram-contains_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/nested-open-index/inverted-index-basic/ngram-contains_ps.plan
@@ -1,28 +1,56 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$o])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$17)
         -- STABLE_SORT [$$17(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$17(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$23
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (contains($$o.getField(0).getField("title"), "Multimedia"))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                        data-scan []<-[$$17, $$o] <- test.DBLP
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$23] <- [agg-range-map($$21, $$22)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$21, $$22] <- [agg-local-sampling($$17), agg-null-writer($$17)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$17])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (contains($$o.getField(0).getField("title"), "Multimedia"))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                  data-scan []<-[$$17, $$o] <- test.DBLP
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-enforced/inverted-index-basic/ngram-contains_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-enforced/inverted-index-basic/ngram-contains_ps.plan
index 93ca5bd..f138fa5 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-enforced/inverted-index-basic/ngram-contains_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-enforced/inverted-index-basic/ngram-contains_ps.plan
@@ -1,28 +1,56 @@
+distribute result [$$o]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$o])
     -- STREAM_PROJECT  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$15)
         -- STABLE_SORT [$$15(ASC)]  |PARTITIONED|
+          exchange
           -- RANGE_PARTITION_EXCHANGE [$$15(ASC)]  |PARTITIONED|
+            forward: shared-variable = $$20
             -- FORWARD  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                replicate
                 -- REPLICATE  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                    select (contains($$o.getField("title"), "Multimedia"))
                     -- STREAM_SELECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                        data-scan []<-[$$15, $$o] <- test.DBLP
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                aggregate [$$20] <- [agg-range-map($$18, $$19)]
                 -- AGGREGATE  |UNPARTITIONED|
+                  exchange
                   -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                    aggregate [$$18, $$19] <- [agg-local-sampling($$15), agg-null-writer($$15)]
                     -- AGGREGATE  |PARTITIONED|
+                      project ([$$15])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              select (contains($$o.getField("title"), "Multimedia"))
                               -- STREAM_SELECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.DBLP)  |PARTITIONED|
+                                  data-scan []<-[$$15, $$o] <- test.DBLP
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-composite-key-non-enforced/btree-composite-key-non-enforced-03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-composite-key-non-enforced/btree-composite-key-non-enforced-03.plan
index f1a1616..c617764 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-composite-key-non-enforced/btree-composite-key-non-enforced-03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-composite-key-non-enforced/btree-composite-key-non-enforced-03.plan
@@ -1,10 +1,20 @@
+distribute result [$$18]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$18])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (and(eq($$t.getField("c_x"), "x2"), eq($$t.getField("c_z"), "z2")))
       -- STREAM_SELECT  |PARTITIONED|
+        assign [$$18] <- [$$t.getField("c_value")]
         -- ASSIGN  |PARTITIONED|
+          project ([$$t])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+              data-scan []<-[$$19, $$t] <- test.TestOpen
+              -- DATASOURCE_SCAN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  empty-tuple-source
                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-composite-key-non-enforced/btree-composite-key-non-enforced-04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-composite-key-non-enforced/btree-composite-key-non-enforced-04.plan
index f1a1616..d8093e9 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-composite-key-non-enforced/btree-composite-key-non-enforced-04.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-composite-key-non-enforced/btree-composite-key-non-enforced-04.plan
@@ -1,10 +1,20 @@
+distribute result [$$20]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$20])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (and(eq($$t.getField("c_x"), "x2"), gt($$t.getField("c_y"), 1), eq($$t.getField("c_z"), "z2")))
       -- STREAM_SELECT  |PARTITIONED|
+        assign [$$20] <- [$$t.getField("c_value")]
         -- ASSIGN  |PARTITIONED|
+          project ([$$t])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+              data-scan []<-[$$21, $$t] <- test.TestOpen
+              -- DATASOURCE_SCAN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  empty-tuple-source
                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-07.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-07.plan
deleted file mode 100644
index 8d30fd0..0000000
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-07.plan
+++ /dev/null
@@ -1,26 +0,0 @@
--- DISTRIBUTE_RESULT  |PARTITIONED|
-  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- STREAM_PROJECT  |PARTITIONED|
-      -- ASSIGN  |PARTITIONED|
-        -- SORT_MERGE_EXCHANGE [$$40(ASC), $$41(ASC) ]  |PARTITIONED|
-          -- STABLE_SORT [$$40(ASC), $$41(ASC)]  |PARTITIONED|
-            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- STREAM_PROJECT  |PARTITIONED|
-                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- HYBRID_HASH_JOIN [$$37][$$38]  |PARTITIONED|
-                    -- HASH_PARTITION_EXCHANGE [$$37]  |PARTITIONED|
-                      -- STREAM_PROJECT  |PARTITIONED|
-                        -- ASSIGN  |PARTITIONED|
-                          -- STREAM_PROJECT  |PARTITIONED|
-                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (test.TestOpen1)  |PARTITIONED|
-                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                    -- HASH_PARTITION_EXCHANGE [$$38]  |PARTITIONED|
-                      -- STREAM_PROJECT  |PARTITIONED|
-                        -- ASSIGN  |PARTITIONED|
-                          -- STREAM_PROJECT  |PARTITIONED|
-                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (test.TestOpen2)  |PARTITIONED|
-                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-07_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-07_ps.plan
deleted file mode 100644
index 6c25f6d..0000000
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-equi-join-non-enforced/btree-equi-join-non-enforced-07_ps.plan
+++ /dev/null
@@ -1,56 +0,0 @@
--- DISTRIBUTE_RESULT  |PARTITIONED|
-  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- STREAM_PROJECT  |PARTITIONED|
-      -- ASSIGN  |PARTITIONED|
-        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- STABLE_SORT [$$40(ASC), $$41(ASC)]  |PARTITIONED|
-            -- RANGE_PARTITION_EXCHANGE [$$40(ASC), $$41(ASC)]  |PARTITIONED|
-              -- FORWARD  |PARTITIONED|
-                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- REPLICATE  |PARTITIONED|
-                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- STREAM_PROJECT  |PARTITIONED|
-                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- HYBRID_HASH_JOIN [$$37][$$38]  |PARTITIONED|
-                            -- HASH_PARTITION_EXCHANGE [$$37]  |PARTITIONED|
-                              -- STREAM_PROJECT  |PARTITIONED|
-                                -- ASSIGN  |PARTITIONED|
-                                  -- STREAM_PROJECT  |PARTITIONED|
-                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.TestOpen1)  |PARTITIONED|
-                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                            -- HASH_PARTITION_EXCHANGE [$$38]  |PARTITIONED|
-                              -- STREAM_PROJECT  |PARTITIONED|
-                                -- ASSIGN  |PARTITIONED|
-                                  -- STREAM_PROJECT  |PARTITIONED|
-                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (test.TestOpen2)  |PARTITIONED|
-                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                -- BROADCAST_EXCHANGE  |PARTITIONED|
-                  -- AGGREGATE  |UNPARTITIONED|
-                    -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
-                      -- AGGREGATE  |PARTITIONED|
-                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- REPLICATE  |PARTITIONED|
-                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- STREAM_PROJECT  |PARTITIONED|
-                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- HYBRID_HASH_JOIN [$$37][$$38]  |PARTITIONED|
-                                    -- HASH_PARTITION_EXCHANGE [$$37]  |PARTITIONED|
-                                      -- STREAM_PROJECT  |PARTITIONED|
-                                        -- ASSIGN  |PARTITIONED|
-                                          -- STREAM_PROJECT  |PARTITIONED|
-                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.TestOpen1)  |PARTITIONED|
-                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                    -- HASH_PARTITION_EXCHANGE [$$38]  |PARTITIONED|
-                                      -- STREAM_PROJECT  |PARTITIONED|
-                                        -- ASSIGN  |PARTITIONED|
-                                          -- STREAM_PROJECT  |PARTITIONED|
-                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.TestOpen2)  |PARTITIONED|
-                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-04.plan
index 0b23e02..d624767 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-04.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-04.plan
@@ -1,15 +1,30 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"res": $$20}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$20(ASC) ]  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$20])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (eq($$t.getField("c_s"), "world"))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$20] <- [$$t.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$t])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                        data-scan []<-[$$18, $$t] <- test.TestOpen
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-04_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-04_ps.plan
index 8d94902..904f2c8 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-04_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-04_ps.plan
@@ -1,34 +1,68 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"res": $$20}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$20(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$24
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$20])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (eq($$t.getField("c_s"), "world"))
                         -- STREAM_SELECT  |PARTITIONED|
+                          assign [$$20] <- [$$t.getField("c_x")]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$t])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                                data-scan []<-[$$18, $$t] <- test.TestOpen
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$24] <- [agg-range-map($$22, $$23)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$22, $$23] <- [agg-local-sampling($$20), agg-null-writer($$20)]
                       -- AGGREGATE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$20])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                select (eq($$t.getField("c_s"), "world"))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  assign [$$20] <- [$$t.getField("c_x")]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$t])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                                        data-scan []<-[$$18, $$t] <- test.TestOpen
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-05.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-05.plan
index 0b23e02..d91f285 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-05.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-05.plan
@@ -1,15 +1,30 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"res": $$20}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$20(ASC) ]  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$20])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (eq($$t.getField("c_i64"), 2))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$20] <- [$$t.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$t])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                        data-scan []<-[$$18, $$t] <- test.TestOpen
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-05_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-05_ps.plan
index 8d94902..817842a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-05_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-05_ps.plan
@@ -1,34 +1,68 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"res": $$20}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$20(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$24
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$20])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (eq($$t.getField("c_i64"), 2))
                         -- STREAM_SELECT  |PARTITIONED|
+                          assign [$$20] <- [$$t.getField("c_x")]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$t])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                                data-scan []<-[$$18, $$t] <- test.TestOpen
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$24] <- [agg-range-map($$22, $$23)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$22, $$23] <- [agg-local-sampling($$20), agg-null-writer($$20)]
                       -- AGGREGATE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$20])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                select (eq($$t.getField("c_i64"), 2))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  assign [$$20] <- [$$t.getField("c_x")]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$t])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                                        data-scan []<-[$$18, $$t] <- test.TestOpen
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-06.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-06.plan
index 0b23e02..fc30099 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-06.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-06.plan
@@ -1,15 +1,30 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"res": $$20}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$20(ASC) ]  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$20])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (gt($$t.getField("c_i64"), 2))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$20] <- [$$t.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$t])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                        data-scan []<-[$$18, $$t] <- test.TestOpen
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-06_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-06_ps.plan
index 8d94902..d8878ab 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-06_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-06_ps.plan
@@ -1,34 +1,68 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"res": $$20}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$20(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$24
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$20])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (gt($$t.getField("c_i64"), 2))
                         -- STREAM_SELECT  |PARTITIONED|
+                          assign [$$20] <- [$$t.getField("c_x")]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$t])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                                data-scan []<-[$$18, $$t] <- test.TestOpen
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$24] <- [agg-range-map($$22, $$23)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$22, $$23] <- [agg-local-sampling($$20), agg-null-writer($$20)]
                       -- AGGREGATE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$20])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                select (gt($$t.getField("c_i64"), 2))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  assign [$$20] <- [$$t.getField("c_x")]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$t])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                                        data-scan []<-[$$18, $$t] <- test.TestOpen
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-07.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-07.plan
index 0b23e02..bf81e71 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-07.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-07.plan
@@ -1,15 +1,30 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"res": $$20}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$20(ASC) ]  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$20])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (gt($$t.getField("c_i64"), 2.0))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$20] <- [$$t.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$t])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                        data-scan []<-[$$18, $$t] <- test.TestOpen
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-07_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-07_ps.plan
index 8d94902..5a02d6e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-07_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-07_ps.plan
@@ -1,34 +1,68 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"res": $$20}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$20(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$24
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$20])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (gt($$t.getField("c_i64"), 2.0))
                         -- STREAM_SELECT  |PARTITIONED|
+                          assign [$$20] <- [$$t.getField("c_x")]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$t])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                                data-scan []<-[$$18, $$t] <- test.TestOpen
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$24] <- [agg-range-map($$22, $$23)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$22, $$23] <- [agg-local-sampling($$20), agg-null-writer($$20)]
                       -- AGGREGATE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$20])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                select (gt($$t.getField("c_i64"), 2.0))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  assign [$$20] <- [$$t.getField("c_x")]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$t])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                                        data-scan []<-[$$18, $$t] <- test.TestOpen
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-08.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-08.plan
index 0b23e02..173a515 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-08.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-08.plan
@@ -1,15 +1,30 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"res": $$20}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$20(ASC) ]  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$20])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (gt($$t.getField("c_i8"), 2))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$20] <- [$$t.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$t])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                        data-scan []<-[$$18, $$t] <- test.TestOpen
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-08_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-08_ps.plan
index 8d94902..0048eb6 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-08_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-08_ps.plan
@@ -1,34 +1,68 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"res": $$20}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$20(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$24
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$20])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (gt($$t.getField("c_i8"), 2))
                         -- STREAM_SELECT  |PARTITIONED|
+                          assign [$$20] <- [$$t.getField("c_x")]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$t])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                                data-scan []<-[$$18, $$t] <- test.TestOpen
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$24] <- [agg-range-map($$22, $$23)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$22, $$23] <- [agg-local-sampling($$20), agg-null-writer($$20)]
                       -- AGGREGATE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$20])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                select (gt($$t.getField("c_i8"), 2))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  assign [$$20] <- [$$t.getField("c_x")]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$t])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                                        data-scan []<-[$$18, $$t] <- test.TestOpen
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-09.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-09.plan
index 0b23e02..7c48cb5 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-09.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-09.plan
@@ -1,15 +1,30 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"res": $$20}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$20(ASC) ]  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$20])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (gt($$t.getField("c_i8"), 2.5))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$20] <- [$$t.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$t])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                        data-scan []<-[$$18, $$t] <- test.TestOpen
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-09_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-09_ps.plan
index 8d94902..528e13f 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-09_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-09_ps.plan
@@ -1,34 +1,68 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"res": $$20}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$20(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$24
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$20])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (gt($$t.getField("c_i8"), 2.5))
                         -- STREAM_SELECT  |PARTITIONED|
+                          assign [$$20] <- [$$t.getField("c_x")]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$t])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                                data-scan []<-[$$18, $$t] <- test.TestOpen
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$24] <- [agg-range-map($$22, $$23)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$22, $$23] <- [agg-local-sampling($$20), agg-null-writer($$20)]
                       -- AGGREGATE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$20])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                select (gt($$t.getField("c_i8"), 2.5))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  assign [$$20] <- [$$t.getField("c_x")]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$t])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                                        data-scan []<-[$$18, $$t] <- test.TestOpen
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-10.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-10.plan
index 0b23e02..229d851 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-10.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-10.plan
@@ -1,15 +1,30 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"res": $$20}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$20(ASC) ]  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$20])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (ge($$t.getField("c_d"), 3.25))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$20] <- [$$t.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$t])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                        data-scan []<-[$$18, $$t] <- test.TestOpen
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-105.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-105.plan
index c1080c7..3a850f0 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-105.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-105.plan
@@ -1,15 +1,30 @@
+distribute result [$$19]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$19])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$19] <- [{"res": $$24}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$24(ASC) ]  |PARTITIONED|
+          order (ASC, $$24)
           -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$24])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (and(gt($$t.getField("c_i8"), 2), lt($$t.getField("c_i64"), 3)))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$24] <- [$$t.getField("c_x")]
                   -- ASSIGN  |PARTITIONED|
+                    project ([$$t])
                     -- STREAM_PROJECT  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                        data-scan []<-[$$21, $$t] <- test.TestOpen
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            empty-tuple-source
                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-105_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-105_ps.plan
index be79cf5..613d1d5 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-105_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-105_ps.plan
@@ -1,34 +1,68 @@
+distribute result [$$19]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$19])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$19] <- [{"res": $$24}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$24)
           -- STABLE_SORT [$$24(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$24(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$28
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$24])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (and(gt($$t.getField("c_i8"), 2), lt($$t.getField("c_i64"), 3)))
                         -- STREAM_SELECT  |PARTITIONED|
+                          assign [$$24] <- [$$t.getField("c_x")]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$t])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                                data-scan []<-[$$21, $$t] <- test.TestOpen
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$28] <- [agg-range-map($$26, $$27)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$26, $$27] <- [agg-local-sampling($$24), agg-null-writer($$24)]
                       -- AGGREGATE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$24])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                select (and(gt($$t.getField("c_i8"), 2), lt($$t.getField("c_i64"), 3)))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  assign [$$24] <- [$$t.getField("c_x")]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$t])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                                        data-scan []<-[$$21, $$t] <- test.TestOpen
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-10_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-10_ps.plan
index 8d94902..3d80666 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-10_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-10_ps.plan
@@ -1,34 +1,68 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"res": $$20}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$20)
           -- STABLE_SORT [$$20(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$20(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$24
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$20])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (ge($$t.getField("c_d"), 3.25))
                         -- STREAM_SELECT  |PARTITIONED|
+                          assign [$$20] <- [$$t.getField("c_x")]
                           -- ASSIGN  |PARTITIONED|
+                            project ([$$t])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                                data-scan []<-[$$18, $$t] <- test.TestOpen
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$24] <- [agg-range-map($$22, $$23)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$22, $$23] <- [agg-local-sampling($$20), agg-null-writer($$20)]
                       -- AGGREGATE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$20])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                select (ge($$t.getField("c_d"), 3.25))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  assign [$$20] <- [$$t.getField("c_x")]
                                   -- ASSIGN  |PARTITIONED|
+                                    project ([$$t])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                                        data-scan []<-[$$18, $$t] <- test.TestOpen
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-11.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-11.plan
index 748b085..3001be5 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-11.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-11.plan
@@ -1,16 +1,32 @@
+distribute result [$$19]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$19])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$19] <- [{"res": $$23}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+          order (ASC, $$23)
           -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$23])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (and(gt($$21, 499), lt($$21, 99999)))
                 -- STREAM_SELECT  |PARTITIONED|
+                  project ([$$23, $$21])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    assign [$$23, $$21] <- [$$t.getField("c_x"), $$t.getField("c_i8")]
                     -- ASSIGN  |PARTITIONED|
+                      project ([$$t])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                          data-scan []<-[$$22, $$t] <- test.TestOpen
+                          -- DATASOURCE_SCAN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              empty-tuple-source
                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-11_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-11_ps.plan
index 35ffdd2..298eece 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-11_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/open-index-non-enforced/btree-index-non-enforced/btree-index-non-enforced-11_ps.plan
@@ -1,36 +1,72 @@
+distribute result [$$19]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$19])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$19] <- [{"res": $$23}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$23)
           -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$23(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$27
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$23])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (and(gt($$21, 499), lt($$21, 99999)))
                         -- STREAM_SELECT  |PARTITIONED|
+                          project ([$$23, $$21])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$23, $$21] <- [$$t.getField("c_x"), $$t.getField("c_i8")]
                             -- ASSIGN  |PARTITIONED|
+                              project ([$$t])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                                  data-scan []<-[$$22, $$t] <- test.TestOpen
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$27] <- [agg-range-map($$25, $$26)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$25, $$26] <- [agg-local-sampling($$23), agg-null-writer($$23)]
                       -- AGGREGATE  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          replicate
                           -- REPLICATE  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$23])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                select (and(gt($$21, 499), lt($$21, 99999)))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  project ([$$23, $$21])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$23, $$21] <- [$$t.getField("c_x"), $$t.getField("c_i8")]
                                     -- ASSIGN  |PARTITIONED|
+                                      project ([$$t])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+                                          data-scan []<-[$$22, $$t] <- test.TestOpen
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive-open_01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive-open_01.plan
index 2326c55..e5393c4 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive-open_01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive-open_01.plan
@@ -1,25 +1,24 @@
--- SINK  |PARTITIONED|
-  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- STREAM_PROJECT  |PARTITIONED|
-      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-        -- BULKLOAD  |PARTITIONED|
-          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- STABLE_SORT [$$2(ASC)]  |PARTITIONED|
-              -- HASH_PARTITION_EXCHANGE [$$2]  |PARTITIONED|
-                -- ASSIGN  |PARTITIONED|
-                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- DATASOURCE_SCAN (loadable_dv.loadable_ds)  |PARTITIONED|
-                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+distribute result [$$20]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$20])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$20] <- [{"o_orderkey": $$23, "o_custkey": $$22}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+          project ([$$23, $$22])
           -- STREAM_PROJECT  |PARTITIONED|
+            select (and(gt($$o.getField(3), 150000.0), eq($$22, 40)))
             -- STREAM_SELECT  |PARTITIONED|
+              assign [$$22] <- [$$o.getField(1)]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                  data-scan []<-[$$23, $$o] <- tpch.Orders
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive-open_01_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive-open_01_ps.plan
index 4bdc66b..0eeee17 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive-open_01_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive-open_01_ps.plan
@@ -1,46 +1,66 @@
--- SINK  |PARTITIONED|
-  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- STREAM_PROJECT  |PARTITIONED|
-      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-        -- BULKLOAD  |PARTITIONED|
-          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- STABLE_SORT [$$2(ASC)]  |PARTITIONED|
-              -- HASH_PARTITION_EXCHANGE [$$2]  |PARTITIONED|
-                -- ASSIGN  |PARTITIONED|
-                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- DATASOURCE_SCAN (loadable_dv.loadable_ds)  |PARTITIONED|
-                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+distribute result [$$20]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$20])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$20] <- [{"o_orderkey": $$23, "o_custkey": $$22}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$23)
           -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$23(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$29
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$23, $$22])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (and(gt($$o.getField(3), 150000.0), eq($$22, 40)))
                         -- STREAM_SELECT  |PARTITIONED|
+                          assign [$$22] <- [$$o.getField(1)]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                              data-scan []<-[$$23, $$o] <- tpch.Orders
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$29] <- [agg-range-map($$27, $$28)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$27, $$28] <- [agg-local-sampling($$23), agg-null-writer($$23)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$23])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$23, $$22])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  select (and(gt($$o.getField(3), 150000.0), eq($$22, 40)))
                                   -- STREAM_SELECT  |PARTITIONED|
+                                    assign [$$22] <- [$$o.getField(1)]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                                        data-scan []<-[$$23, $$o] <- tpch.Orders
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive-open_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive-open_02.plan
index eb1d57c..4144e84 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive-open_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive-open_02.plan
@@ -1,25 +1,24 @@
--- SINK  |PARTITIONED|
-  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- STREAM_PROJECT  |PARTITIONED|
-      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-        -- BULKLOAD  |PARTITIONED|
-          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- STABLE_SORT [$$2(ASC)]  |PARTITIONED|
-              -- HASH_PARTITION_EXCHANGE [$$2]  |PARTITIONED|
-                -- ASSIGN  |PARTITIONED|
-                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- DATASOURCE_SCAN (loadable_dv.loadable_ds)  |PARTITIONED|
-                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+distribute result [$$21]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$21])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$21] <- [{"o_orderkey": $$25, "o_custkey": $$23, "o_totalprice": $$24}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$25(ASC) ]  |PARTITIONED|
+          select (and(gt($$24, 150000.0), eq($$23, 40)))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$25, $$23, $$24])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$23, $$24] <- [$$o.getField(1), $$o.getField(3)]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                  data-scan []<-[$$25, $$o] <- tpch.Orders
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive-open_02_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive-open_02_ps.plan
index dce703e..a0eaccc 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive-open_02_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive-open_02_ps.plan
@@ -1,46 +1,66 @@
--- SINK  |PARTITIONED|
-  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- STREAM_PROJECT  |PARTITIONED|
-      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-        -- BULKLOAD  |PARTITIONED|
-          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- STABLE_SORT [$$2(ASC)]  |PARTITIONED|
-              -- HASH_PARTITION_EXCHANGE [$$2]  |PARTITIONED|
-                -- ASSIGN  |PARTITIONED|
-                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- DATASOURCE_SCAN (loadable_dv.loadable_ds)  |PARTITIONED|
-                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+distribute result [$$21]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$21])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$21] <- [{"o_orderkey": $$25, "o_custkey": $$23, "o_totalprice": $$24}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$25)
           -- STABLE_SORT [$$25(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$25(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$30
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      select (and(gt($$24, 150000.0), eq($$23, 40)))
                       -- STREAM_SELECT  |PARTITIONED|
+                        project ([$$25, $$23, $$24])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$23, $$24] <- [$$o.getField(1), $$o.getField(3)]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                              data-scan []<-[$$25, $$o] <- tpch.Orders
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$30] <- [agg-range-map($$28, $$29)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$28, $$29] <- [agg-local-sampling($$25), agg-null-writer($$25)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$25])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                select (and(gt($$24, 150000.0), eq($$23, 40)))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  project ([$$25, $$23, $$24])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$23, $$24] <- [$$o.getField(1), $$o.getField(3)]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                                        data-scan []<-[$$25, $$o] <- tpch.Orders
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive_01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive_01.plan
index 2326c55..e5393c4 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive_01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive_01.plan
@@ -1,25 +1,24 @@
--- SINK  |PARTITIONED|
-  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- STREAM_PROJECT  |PARTITIONED|
-      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-        -- BULKLOAD  |PARTITIONED|
-          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- STABLE_SORT [$$2(ASC)]  |PARTITIONED|
-              -- HASH_PARTITION_EXCHANGE [$$2]  |PARTITIONED|
-                -- ASSIGN  |PARTITIONED|
-                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- DATASOURCE_SCAN (loadable_dv.loadable_ds)  |PARTITIONED|
-                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+distribute result [$$20]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$20])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$20] <- [{"o_orderkey": $$23, "o_custkey": $$22}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$23(ASC) ]  |PARTITIONED|
+          project ([$$23, $$22])
           -- STREAM_PROJECT  |PARTITIONED|
+            select (and(gt($$o.getField(3), 150000.0), eq($$22, 40)))
             -- STREAM_SELECT  |PARTITIONED|
+              assign [$$22] <- [$$o.getField(1)]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                  data-scan []<-[$$23, $$o] <- tpch.Orders
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive_01_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive_01_ps.plan
index 4bdc66b..0eeee17 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive_01_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive_01_ps.plan
@@ -1,46 +1,66 @@
--- SINK  |PARTITIONED|
-  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- STREAM_PROJECT  |PARTITIONED|
-      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-        -- BULKLOAD  |PARTITIONED|
-          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- STABLE_SORT [$$2(ASC)]  |PARTITIONED|
-              -- HASH_PARTITION_EXCHANGE [$$2]  |PARTITIONED|
-                -- ASSIGN  |PARTITIONED|
-                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- DATASOURCE_SCAN (loadable_dv.loadable_ds)  |PARTITIONED|
-                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+distribute result [$$20]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$20])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$20] <- [{"o_orderkey": $$23, "o_custkey": $$22}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$23)
           -- STABLE_SORT [$$23(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$23(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$29
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$23, $$22])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (and(gt($$o.getField(3), 150000.0), eq($$22, 40)))
                         -- STREAM_SELECT  |PARTITIONED|
+                          assign [$$22] <- [$$o.getField(1)]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                              data-scan []<-[$$23, $$o] <- tpch.Orders
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$29] <- [agg-range-map($$27, $$28)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$27, $$28] <- [agg-local-sampling($$23), agg-null-writer($$23)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$23])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$23, $$22])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  select (and(gt($$o.getField(3), 150000.0), eq($$22, 40)))
                                   -- STREAM_SELECT  |PARTITIONED|
+                                    assign [$$22] <- [$$o.getField(1)]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                                        data-scan []<-[$$23, $$o] <- tpch.Orders
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive_02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive_02.plan
index eb1d57c..4144e84 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive_02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive_02.plan
@@ -1,25 +1,24 @@
--- SINK  |PARTITIONED|
-  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- STREAM_PROJECT  |PARTITIONED|
-      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-        -- BULKLOAD  |PARTITIONED|
-          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- STABLE_SORT [$$2(ASC)]  |PARTITIONED|
-              -- HASH_PARTITION_EXCHANGE [$$2]  |PARTITIONED|
-                -- ASSIGN  |PARTITIONED|
-                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- DATASOURCE_SCAN (loadable_dv.loadable_ds)  |PARTITIONED|
-                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+distribute result [$$21]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$21])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$21] <- [{"o_orderkey": $$25, "o_custkey": $$23, "o_totalprice": $$24}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$25(ASC) ]  |PARTITIONED|
+          select (and(gt($$24, 150000.0), eq($$23, 40)))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$25, $$23, $$24])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$23, $$24] <- [$$o.getField(1), $$o.getField(3)]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                  data-scan []<-[$$25, $$o] <- tpch.Orders
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive_02_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive_02_ps.plan
index dce703e..a0eaccc 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive_02_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/orders-index-search-conjunctive_02_ps.plan
@@ -1,46 +1,66 @@
--- SINK  |PARTITIONED|
-  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- STREAM_PROJECT  |PARTITIONED|
-      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-        -- BULKLOAD  |PARTITIONED|
-          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- STABLE_SORT [$$2(ASC)]  |PARTITIONED|
-              -- HASH_PARTITION_EXCHANGE [$$2]  |PARTITIONED|
-                -- ASSIGN  |PARTITIONED|
-                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- DATASOURCE_SCAN (loadable_dv.loadable_ds)  |PARTITIONED|
-                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+distribute result [$$21]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$21])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$21] <- [{"o_orderkey": $$25, "o_custkey": $$23, "o_totalprice": $$24}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$25)
           -- STABLE_SORT [$$25(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$25(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$30
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      select (and(gt($$24, 150000.0), eq($$23, 40)))
                       -- STREAM_SELECT  |PARTITIONED|
+                        project ([$$25, $$23, $$24])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$23, $$24] <- [$$o.getField(1), $$o.getField(3)]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                              data-scan []<-[$$25, $$o] <- tpch.Orders
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$30] <- [agg-range-map($$28, $$29)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$28, $$29] <- [agg-local-sampling($$25), agg-null-writer($$25)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$25])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                select (and(gt($$24, 150000.0), eq($$23, 40)))
                                 -- STREAM_SELECT  |PARTITIONED|
+                                  project ([$$25, $$23, $$24])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    assign [$$23, $$24] <- [$$o.getField(1), $$o.getField(3)]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                                        data-scan []<-[$$25, $$o] <- tpch.Orders
+                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            empty-tuple-source
                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/q08_group_by.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/q08_group_by.plan
index 1e558ec..4bd75cf 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/q08_group_by.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/q08_group_by.plan
@@ -1,78 +1,156 @@
+distribute result [$$191]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$191])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$191] <- [{"o_orderdate": $$216, "l_discount": $$219, "l_extendedprice": $$220, "l_suppkey": $$221, "s_nationkey": $$230}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$216, $$219, $$220, $$221, $$230])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- HYBRID_HASH_JOIN [$$230][$$212]  |PARTITIONED|
-              -- HASH_PARTITION_EXCHANGE [$$230]  |PARTITIONED|
+            join (eq($$200, $$218))
+            -- HYBRID_HASH_JOIN [$$218][$$200]  |PARTITIONED|
+              exchange
+              -- HASH_PARTITION_EXCHANGE [$$218]  |PARTITIONED|
+                project ([$$216, $$219, $$220, $$221, $$230, $$218])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- HYBRID_HASH_JOIN [$$216][$$211]  |PARTITIONED|
-                      -- HASH_PARTITION_EXCHANGE [$$216]  |PARTITIONED|
+                    join (eq($$204, $$199))
+                    -- HYBRID_HASH_JOIN [$$204][$$199]  |PARTITIONED|
+                      exchange
+                      -- HASH_PARTITION_EXCHANGE [$$204]  |PARTITIONED|
+                        project ([$$216, $$219, $$220, $$221, $$230, $$218, $$204])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- HYBRID_HASH_JOIN [$$218][$$210]  |PARTITIONED|
-                              -- HASH_PARTITION_EXCHANGE [$$218]  |PARTITIONED|
+                            join (eq($$206, $$198))
+                            -- HYBRID_HASH_JOIN [$$206][$$198]  |PARTITIONED|
+                              exchange
+                              -- HASH_PARTITION_EXCHANGE [$$206]  |PARTITIONED|
+                                project ([$$216, $$219, $$220, $$221, $$230, $$218, $$206])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- HYBRID_HASH_JOIN [$$221][$$209]  |PARTITIONED|
-                                      -- HASH_PARTITION_EXCHANGE [$$221]  |PARTITIONED|
+                                    join (eq($$197, $$209))
+                                    -- HYBRID_HASH_JOIN [$$209][$$197]  |PARTITIONED|
+                                      exchange
+                                      -- HASH_PARTITION_EXCHANGE [$$209]  |PARTITIONED|
+                                        project ([$$216, $$219, $$220, $$221, $$230, $$218, $$209])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- HYBRID_HASH_JOIN [$$206][$$208]  |PARTITIONED|
-                                              -- HASH_PARTITION_EXCHANGE [$$206]  |PARTITIONED|
+                                            join (eq($$194, $$196))
+                                            -- HYBRID_HASH_JOIN [$$194][$$196]  |PARTITIONED|
+                                              exchange
+                                              -- HASH_PARTITION_EXCHANGE [$$194]  |PARTITIONED|
+                                                project ([$$219, $$220, $$221, $$230, $$218, $$194])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- HYBRID_HASH_JOIN [$$205][$$233]  |PARTITIONED|
+                                                    join (eq($$193, $$221))
+                                                    -- HYBRID_HASH_JOIN [$$193][$$221]  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        project ([$$230, $$193])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$230] <- [$$s.getField(3)]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            exchange
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- DATASOURCE_SCAN (q08_group_by.Supplier)  |PARTITIONED|
+                                                              data-scan []<-[$$193, $$s] <- q08_group_by.Supplier
+                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                  empty-tuple-source
                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                      -- HASH_PARTITION_EXCHANGE [$$233]  |PARTITIONED|
+                                                      exchange
+                                                      -- HASH_PARTITION_EXCHANGE [$$221]  |PARTITIONED|
+                                                        project ([$$219, $$220, $$221, $$218, $$194])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          assign [$$221, $$220, $$219, $$218] <- [$$l.getField(2), $$l.getField(5), $$l.getField(6), $$l.getField(1)]
                                                           -- ASSIGN  |PARTITIONED|
+                                                            project ([$$194, $$l])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- DATASOURCE_SCAN (q08_group_by.LineItem)  |PARTITIONED|
+                                                                data-scan []<-[$$194, $$195, $$l] <- q08_group_by.LineItem
+                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    empty-tuple-source
                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                select (and(ge($$216, "1995-01-01"), le($$216, "1996-12-31")))
                                                 -- STREAM_SELECT  |PARTITIONED|
+                                                  project ([$$196, $$216, $$209])
                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                    assign [$$216, $$209] <- [$$o.getField(4), $$o.getField(1)]
                                                     -- ASSIGN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (q08_group_by.Orders)  |PARTITIONED|
+                                                        data-scan []<-[$$196, $$o] <- q08_group_by.Orders
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$206, $$197])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$206] <- [$$c.getField(3)]
                                           -- ASSIGN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (q08_group_by.Customer)  |PARTITIONED|
+                                              data-scan []<-[$$197, $$c] <- q08_group_by.Customer
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$204, $$198])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  assign [$$204] <- [$$n1.getField(2)]
                                   -- ASSIGN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (q08_group_by.Nation)  |PARTITIONED|
+                                      data-scan []<-[$$198, $$n1] <- q08_group_by.Nation
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$199])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          select (eq($$r1.getField(1), "AMERICA"))
                           -- STREAM_SELECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (q08_group_by.Region)  |PARTITIONED|
+                              data-scan []<-[$$199, $$r1] <- q08_group_by.Region
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$200])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  select (eq($$p.getField(4), "ECONOMY ANODIZED STEEL"))
                   -- STREAM_SELECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (q08_group_by.Part)  |PARTITIONED|
+                      data-scan []<-[$$200, $$p] <- q08_group_by.Part
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/q09_group_by.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/q09_group_by.plan
index 26a56eb..e34cd16 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/q09_group_by.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/q09_group_by.plan
@@ -1,55 +1,110 @@
+distribute result [$$137]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$137])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$137] <- [{"l_extendedprice": $$158, "l_discount": $$159, "l_quantity": $$160, "l_orderkey": $$144, "n_name": $$157, "ps_supplycost": $$169}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$158, $$159, $$160, $$144, $$169, $$157])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- HYBRID_HASH_JOIN [$$157][$$151]  |PARTITIONED|
-              -- HASH_PARTITION_EXCHANGE [$$157]  |PARTITIONED|
+            join (eq($$143, $$149))
+            -- HYBRID_HASH_JOIN [$$149][$$143]  |PARTITIONED|
+              exchange
+              -- HASH_PARTITION_EXCHANGE [$$149]  |PARTITIONED|
+                project ([$$158, $$159, $$160, $$144, $$169, $$149])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- HYBRID_HASH_JOIN [$$154][$$150]  |PARTITIONED|
-                      -- HASH_PARTITION_EXCHANGE [$$154]  |PARTITIONED|
+                    join (eq($$142, $$146))
+                    -- HYBRID_HASH_JOIN [$$146][$$142]  |PARTITIONED|
+                      exchange
+                      -- HASH_PARTITION_EXCHANGE [$$146]  |PARTITIONED|
+                        project ([$$158, $$159, $$160, $$144, $$169, $$146])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- HYBRID_HASH_JOIN [$$169, $$154][$$148, $$149]  |PARTITIONED|
-                              -- HASH_PARTITION_EXCHANGE [$$169, $$154]  |PARTITIONED|
+                            join (and(eq($$140, $$161), eq($$141, $$146)))
+                            -- HYBRID_HASH_JOIN [$$161, $$146][$$140, $$141]  |PARTITIONED|
+                              exchange
+                              -- HASH_PARTITION_EXCHANGE [$$161, $$146]  |PARTITIONED|
+                                project ([$$158, $$159, $$160, $$144, $$146, $$161])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- HYBRID_HASH_JOIN [$$147][$$169]  |PARTITIONED|
+                                    join (eq($$139, $$161))
+                                    -- HYBRID_HASH_JOIN [$$139][$$161]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$139])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          select (contains($$p.getField(1), "green"))
                                           -- STREAM_SELECT  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (q09_group_by.Part)  |PARTITIONED|
+                                              data-scan []<-[$$139, $$p] <- q09_group_by.Part
+                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                exchange
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                      -- HASH_PARTITION_EXCHANGE [$$169]  |PARTITIONED|
+                                      exchange
+                                      -- HASH_PARTITION_EXCHANGE [$$161]  |PARTITIONED|
+                                        project ([$$158, $$159, $$160, $$144, $$146, $$161])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          assign [$$161, $$160, $$159, $$158, $$146] <- [$$l.getField(1), $$l.getField(4), $$l.getField(6), $$l.getField(5), $$l.getField(2)]
                                           -- ASSIGN  |PARTITIONED|
+                                            project ([$$144, $$l])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- DATASOURCE_SCAN (q09_group_by.LineItem)  |PARTITIONED|
+                                                data-scan []<-[$$144, $$145, $$l] <- q09_group_by.LineItem
+                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    empty-tuple-source
                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$169, $$140, $$141])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  assign [$$169] <- [$$ps.getField(3)]
                                   -- ASSIGN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- DATASOURCE_SCAN (q09_group_by.Partsupp)  |PARTITIONED|
+                                      data-scan []<-[$$140, $$141, $$ps] <- q09_group_by.Partsupp
+                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          empty-tuple-source
                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        project ([$$149, $$142])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          assign [$$149] <- [$$s.getField(3)]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- DATASOURCE_SCAN (q09_group_by.Supplier)  |PARTITIONED|
+                              data-scan []<-[$$142, $$s] <- q09_group_by.Supplier
+                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  empty-tuple-source
                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                project ([$$157, $$143])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  assign [$$157] <- [$$n.getField(1)]
                   -- ASSIGN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- DATASOURCE_SCAN (q09_group_by.Nation)  |PARTITIONED|
+                      data-scan []<-[$$143, $$n] <- q09_group_by.Nation
+                      -- DATASOURCE_SCAN  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          empty-tuple-source
                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/query-ASTERIXDB-3334.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/query-ASTERIXDB-3334.plan
deleted file mode 100644
index bbb94e3..0000000
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/query-ASTERIXDB-3334.plan
+++ /dev/null
@@ -1,61 +0,0 @@
--- DISTRIBUTE_RESULT  |PARTITIONED|
-  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- STREAM_PROJECT  |PARTITIONED|
-      -- ASSIGN  |PARTITIONED|
-        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- SORT_GROUP_BY[$$1112]  |PARTITIONED|
-                  {
-                    -- AGGREGATE  |LOCAL|
-                      -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
-            -- HASH_PARTITION_EXCHANGE [$$1112]  |PARTITIONED|
-              -- SORT_GROUP_BY[$$1113]  |PARTITIONED|
-                      {
-                        -- AGGREGATE  |LOCAL|
-                          -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
-                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- STREAM_PROJECT  |PARTITIONED|
-                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- HYBRID_HASH_JOIN [$$1113, $$1114][$$Employee Name, $$Call Center Region]  |PARTITIONED|
-                        -- HASH_PARTITION_EXCHANGE [$$1114, $$1113]  |PARTITIONED|
-                          -- STREAM_PROJECT  |PARTITIONED|
-                            -- STREAM_SELECT  |PARTITIONED|
-                              -- ASSIGN  |PARTITIONED|
-                                -- STREAM_PROJECT  |PARTITIONED|
-                                  -- ASSIGN  |PARTITIONED|
-                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- REPLICATE  |PARTITIONED|
-                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- STREAM_PROJECT  |PARTITIONED|
-                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
-                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- STREAM_PROJECT  |PARTITIONED|
-                            -- STREAM_SELECT  |PARTITIONED|
-                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- SORT_GROUP_BY[$$1109, $$1110]  |PARTITIONED|
-                                        {
-                                          -- AGGREGATE  |LOCAL|
-                                            -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
-                                  -- HASH_PARTITION_EXCHANGE [$$1109, $$1110]  |PARTITIONED|
-                                    -- SORT_GROUP_BY[$$1117, $$1116]  |PARTITIONED|
-                                            {
-                                              -- AGGREGATE  |LOCAL|
-                                                -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                            }
-                                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- STREAM_PROJECT  |PARTITIONED|
-                                          -- STREAM_SELECT  |PARTITIONED|
-                                            -- ASSIGN  |PARTITIONED|
-                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- REPLICATE  |PARTITIONED|
-                                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- STREAM_PROJECT  |PARTITIONED|
-                                                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
-                                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/query_issue3316.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/query_issue3316.plan
index 8b22913..62a16f4 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/query_issue3316.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/query_issue3316.plan
@@ -1,998 +1,1951 @@
+distribute result [$$186]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    distinct ([$$186])
     -- PRE_SORTED_DISTINCT_BY  |PARTITIONED|
+      exchange
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+        order (ASC, $$186)
         -- STABLE_SORT [$$186(ASC)]  |PARTITIONED|
+          exchange
           -- HASH_PARTITION_EXCHANGE [$$186]  |PARTITIONED|
+            project ([$$186])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$186] <- [object-concat-strict(if-missing-or-null(to-object($$108), cast({  })), {"sub_query1": $$150, "sub_query2": $$185})]
               -- ASSIGN  |PARTITIONED|
+                project ([$$185, $$150, $$108])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- PRE_CLUSTERED_GROUP_BY[$$221]  |PARTITIONED|
-                            {
+                    group by ([$$312 := $$221]) decor ([$$150; $$108]) {
+                              aggregate [$$185] <- [listify($$184)]
                               -- AGGREGATE  |LOCAL|
+                                select (not(is-missing($$311)))
                                 -- STREAM_SELECT  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                            }
+                           }
+                    -- PRE_CLUSTERED_GROUP_BY[$$221]  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        order (ASC, $$221)
                         -- STABLE_SORT [$$221(ASC)]  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            project ([$$108, $$150, $$184, $$311, $$221])
                             -- STREAM_PROJECT  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                left outer join (eq($$221, $$382))
                                 -- HYBRID_HASH_JOIN [$$221][$$382]  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- PRE_CLUSTERED_GROUP_BY[$$187]  |PARTITIONED|
-                                            {
+                                    group by ([$$221 := $$187]) decor ([$$108]) {
+                                              aggregate [$$150] <- [listify($$149)]
                                               -- AGGREGATE  |LOCAL|
+                                                select (not(is-missing($$220)))
                                                 -- STREAM_SELECT  |LOCAL|
+                                                  nested tuple source
                                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                            }
+                                           }
+                                    -- PRE_CLUSTERED_GROUP_BY[$$187]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$108, $$149, $$220, $$187])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            left outer join (eq($$187, $$234))
                                             -- HYBRID_HASH_JOIN [$$187][$$234]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$108, $$187])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$108] <- [{"x_id": $$T0.getField("x_id")}]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                      data-scan []<-[$$187, $$T0] <- test.collection0
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                              exchange
                                               -- HASH_PARTITION_EXCHANGE [$$234]  |PARTITIONED|
+                                                project ([$$149, $$220, $$234])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$220, $$149] <- [true, {"u": $$207}]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$234, $$207])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        join (eq($$193, $$120))
                                                         -- HYBRID_HASH_JOIN [$$120][$$193]  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            project ([$$234, $$207, $$120])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              select ($$145)
                                                               -- STREAM_SELECT  |PARTITIONED|
+                                                                project ([$$145, $$234, $$120, $$207])
                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- PRE_CLUSTERED_GROUP_BY[$$219, $$188]  |PARTITIONED|
-                                                                            {
+                                                                    group by ([$$234 := $$219; $$235 := $$188]) decor ([$$120; $$207]) {
+                                                                              aggregate [$$145] <- [non-empty-stream()]
                                                                               -- AGGREGATE  |LOCAL|
+                                                                                select (not(is-missing($$233)))
                                                                                 -- STREAM_SELECT  |LOCAL|
+                                                                                  nested tuple source
                                                                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                            }
+                                                                           }
+                                                                    -- PRE_CLUSTERED_GROUP_BY[$$219, $$188]  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        order (ASC, $$219) (ASC, $$188)
                                                                         -- STABLE_SORT [$$219(ASC), $$188(ASC)]  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            project ([$$207, $$120, $$233, $$219, $$188])
                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                left outer join (and(eq($$219, $$248), eq($$188, $$249)))
                                                                                 -- HYBRID_HASH_JOIN [$$219, $$188][$$248, $$249]  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- HASH_PARTITION_EXCHANGE [$$219, $$188]  |PARTITIONED|
+                                                                                    project ([$$207, $$120, $$219, $$188])
                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                        join (eq($$201, $$217))
                                                                                         -- HYBRID_HASH_JOIN [$$217][$$201]  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                            project ([$$219, $$217])
                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                              assign [$$219, $$217] <- [$$429, $$439]
                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                exchange
                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                  replicate
                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                    exchange
                                                                                                     -- HASH_PARTITION_EXCHANGE [$$439]  |PARTITIONED|
+                                                                                                      project ([$$439, $$429])
                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                        assign [$$439, $$429] <- [$$385, $$393]
                                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                                          exchange
                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                            replicate
                                                                                                             -- REPLICATE  |PARTITIONED|
+                                                                                                              exchange
                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                project ([$$385, $$393])
                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                  assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                    exchange
                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                      -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                      data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                        exchange
                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                          empty-tuple-source
                                                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- HASH_PARTITION_EXCHANGE [$$201]  |PARTITIONED|
+                                                                                            project ([$$207, $$120, $$188, $$201])
                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                              select (eq($$H.getField("to_u"), "aaaaa"))
                                                                                               -- STREAM_SELECT  |PARTITIONED|
+                                                                                                assign [$$207, $$120, $$201] <- [$$H.getField("u"), $$H.getField("a"), $$H.getField("y_id")]
                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                  project ([$$188, $$H])
                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                    assign [$$188, $$H] <- [$$405, $$411]
                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                      exchange
                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                        replicate
                                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                                          exchange
                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                            -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                            data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                              exchange
                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                empty-tuple-source
                                                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    assign [$$233] <- [true]
                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                      project ([$$248, $$249])
                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                        select (eq($$227, $#7))
                                                                                         -- STREAM_SELECT  |PARTITIONED|
+                                                                                          project ([$$248, $$249, $$227, $#7])
                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                            unnest $#7 <- scan-collection($$142)
                                                                                             -- UNNEST  |PARTITIONED|
+                                                                                              exchange
                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                -- PRE_CLUSTERED_GROUP_BY[$$232, $$229]  |PARTITIONED|
-                                                                                                        {
+                                                                                                group by ([$$248 := $$232; $$249 := $$229]) decor ([$$227]) {
+                                                                                                          aggregate [$$142] <- [listify($$197)]
                                                                                                           -- AGGREGATE  |LOCAL|
+                                                                                                            aggregate [$$197] <- [agg-sql-max($$139)]
                                                                                                             -- AGGREGATE  |LOCAL|
+                                                                                                              select (not(is-missing($$247)))
                                                                                                               -- STREAM_SELECT  |LOCAL|
+                                                                                                                nested tuple source
                                                                                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                        }
+                                                                                                       }
+                                                                                                -- PRE_CLUSTERED_GROUP_BY[$$232, $$229]  |PARTITIONED|
+                                                                                                  exchange
                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                    order (ASC, $$232) (ASC, $$229)
                                                                                                     -- STABLE_SORT [$$232(ASC), $$229(ASC)]  |PARTITIONED|
+                                                                                                      exchange
                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                        project ([$$227, $$139, $$247, $$232, $$229])
                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                          exchange
                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                            left outer join (and(eq($$232, $$246), eq($$229, $$243)))
                                                                                                             -- HYBRID_HASH_JOIN [$$232, $$229][$$246, $$243]  |PARTITIONED|
+                                                                                                              exchange
                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                project ([$$227, $$232, $$229])
                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                  assign [$$227, $$232, $$229] <- [$$416, $$419, $$420]
                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                    exchange
                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                      replicate
                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                        exchange
                                                                                                                         -- HASH_PARTITION_EXCHANGE [$$419, $$420]  |PARTITIONED|
+                                                                                                                          project ([$$416, $$419, $$420])
                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                            exchange
                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                              join (eq($$427, $$428))
                                                                                                                               -- HYBRID_HASH_JOIN [$$428][$$427]  |PARTITIONED|
+                                                                                                                                exchange
                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                  project ([$$419, $$428])
                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                    assign [$$419, $$428] <- [$$429, $$439]
                                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                                      exchange
                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                        replicate
                                                                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                                                                          exchange
                                                                                                                                           -- HASH_PARTITION_EXCHANGE [$$439]  |PARTITIONED|
+                                                                                                                                            project ([$$439, $$429])
                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                              assign [$$439, $$429] <- [$$385, $$393]
                                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                                exchange
                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                  replicate
                                                                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                                                                    exchange
                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                      project ([$$385, $$393])
                                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                        assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                                                                                          exchange
                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                            -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                                                            data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                              exchange
                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                empty-tuple-source
                                                                                                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                exchange
                                                                                                                                 -- HASH_PARTITION_EXCHANGE [$$427]  |PARTITIONED|
+                                                                                                                                  project ([$$416, $$420, $$427])
                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                    select (eq($$422.getField("to_u"), "aaaaa"))
                                                                                                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                      exchange
                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                        replicate
                                                                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                                                                          exchange
                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                            assign [$$427, $$416] <- [$$422.getField("y_id"), $$422.getField("b")]
                                                                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                                                                              project ([$$420, $$422])
                                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                assign [$$420, $$422] <- [$$405, $$411]
                                                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                                                  exchange
                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                    replicate
                                                                                                                                                     -- REPLICATE  |PARTITIONED|
+                                                                                                                                                      exchange
                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                        -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                        data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                          exchange
                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                            empty-tuple-source
                                                                                                                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                              exchange
                                                                                                               -- HASH_PARTITION_EXCHANGE [$$246, $$243]  |PARTITIONED|
+                                                                                                                assign [$$247] <- [true]
                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                  project ([$$139, $$246, $$243])
                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                    exchange
                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                      join (eq($$236, $$237))
                                                                                                                       -- HYBRID_HASH_JOIN [$$237][$$236]  |PARTITIONED|
+                                                                                                                        exchange
                                                                                                                         -- HASH_PARTITION_EXCHANGE [$$237]  |PARTITIONED|
+                                                                                                                          project ([$$139, $$246, $$237])
                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                            exchange
                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                              join (eq($$204, $$237))
                                                                                                                               -- HYBRID_HASH_JOIN [$$204][$$237]  |PARTITIONED|
+                                                                                                                                exchange
                                                                                                                                 -- HASH_PARTITION_EXCHANGE [$$204]  |PARTITIONED|
+                                                                                                                                  project ([$$139, $$204])
                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                    exchange
                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                      join (eq($$192, $$129))
                                                                                                                                       -- HYBRID_HASH_JOIN [$$129][$$192]  |PARTITIONED|
+                                                                                                                                        exchange
                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                          project ([$$139, $$204, $$129])
                                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                            select (eq($$L.getField("to_u"), "aaaaa"))
                                                                                                                                             -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                              assign [$$129, $$204, $$139] <- [$$L.getField("a"), $$L.getField("y_id"), $$L.getField("b")]
                                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                                project ([$$L])
                                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                  assign [$$L] <- [$$435]
                                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                                    exchange
                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                      replicate
                                                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                                                        exchange
                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                          project ([$$435])
                                                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                            exchange
                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                              -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                              data-scan []<-[$$441, $$435] <- test.collection1
+                                                                                                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                exchange
                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                  empty-tuple-source
                                                                                                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                        exchange
                                                                                                                                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                                                                          unnest $$192 <- scan-collection(array: [ 66, 67, 26, 12, 13 ])
                                                                                                                                           -- UNNEST  |UNPARTITIONED|
+                                                                                                                                            empty-tuple-source
                                                                                                                                             -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                                                                                                                exchange
                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                  project ([$$246, $$237])
                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                    assign [$$246, $$237] <- [$$429, $$439]
                                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                                      exchange
                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                        replicate
                                                                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                                                                          exchange
                                                                                                                                           -- HASH_PARTITION_EXCHANGE [$$439]  |PARTITIONED|
+                                                                                                                                            project ([$$439, $$429])
                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                              assign [$$439, $$429] <- [$$385, $$393]
                                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                                exchange
                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                  replicate
                                                                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                                                                    exchange
                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                      project ([$$385, $$393])
                                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                        assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                                                                                          exchange
                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                            -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                                                            data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                              exchange
                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                empty-tuple-source
                                                                                                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                        exchange
                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                          project ([$$243, $$236])
                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                            assign [$$243, $$236] <- [$$430, $$442]
                                                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                                                              exchange
                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                replicate
                                                                                                                                 -- REPLICATE  |PARTITIONED|
+                                                                                                                                  exchange
                                                                                                                                   -- HASH_PARTITION_EXCHANGE [$$442]  |PARTITIONED|
+                                                                                                                                    project ([$$430, $$442])
                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                      select (eq($$444.getField("to_u"), "aaaaa"))
                                                                                                                                       -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                        project ([$$430, $$444, $$442])
                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                          assign [$$430, $$444, $$442] <- [$$391, $$386, $$384]
                                                                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                                                                            exchange
                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                              replicate
                                                                                                                                               -- REPLICATE  |PARTITIONED|
+                                                                                                                                                exchange
                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                  assign [$$384] <- [$$386.getField("y_id")]
                                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                                    project ([$$391, $$386])
                                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                      assign [$$391, $$386] <- [$$405, $$411]
                                                                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                                                                        exchange
                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                          replicate
                                                                                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                                                                                            exchange
                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                              -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                              data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                exchange
                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                  empty-tuple-source
                                                                                                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                          exchange
                                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                            unnest $$193 <- scan-collection(array: [ 66, 67, 26, 12, 13 ])
                                                             -- UNNEST  |UNPARTITIONED|
+                                                              empty-tuple-source
                                                               -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                  exchange
                                   -- HASH_PARTITION_EXCHANGE [$$382]  |PARTITIONED|
+                                    project ([$$184, $$311, $$382])
                                     -- STREAM_PROJECT  |PARTITIONED|
+                                      assign [$$311, $$184] <- [true, {"u": $$213}]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$382, $$213])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            join (eq($$196, $$156))
                                             -- HYBRID_HASH_JOIN [$$156][$$196]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$382, $$213, $$156])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    join (eq($$195, $$159))
                                                     -- HYBRID_HASH_JOIN [$$159][$$195]  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        project ([$$382, $$213, $$156, $$159])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          select ($$180)
                                                           -- STREAM_SELECT  |PARTITIONED|
+                                                            project ([$$180, $$382, $$213, $$156, $$159])
                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                              exchange
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- PRE_CLUSTERED_GROUP_BY[$$250, $$190]  |PARTITIONED|
-                                                                        {
+                                                                group by ([$$382 := $$250; $$383 := $$190]) decor ([$$213; $$156; $$159]) {
+                                                                          aggregate [$$180] <- [non-empty-stream()]
                                                                           -- AGGREGATE  |LOCAL|
+                                                                            select (not(is-missing($$381)))
                                                                             -- STREAM_SELECT  |LOCAL|
+                                                                              nested tuple source
                                                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                        }
+                                                                       }
+                                                                -- PRE_CLUSTERED_GROUP_BY[$$250, $$190]  |PARTITIONED|
+                                                                  exchange
                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                    order (ASC, $$250) (ASC, $$190)
                                                                     -- STABLE_SORT [$$250(ASC), $$190(ASC)]  |PARTITIONED|
+                                                                      exchange
                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                        project ([$$213, $$156, $$159, $$381, $$250, $$190])
                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                          exchange
                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                            left outer join (and(eq($$250, $$453), eq($$190, $$454)))
                                                                             -- HYBRID_HASH_JOIN [$$250, $$190][$$453, $$454]  |PARTITIONED|
+                                                                              exchange
                                                                               -- HASH_PARTITION_EXCHANGE [$$250, $$190]  |PARTITIONED|
+                                                                                project ([$$213, $$156, $$159, $$250, $$190])
                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                  exchange
                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                    join (eq($$208, $$252))
                                                                                     -- HYBRID_HASH_JOIN [$$252][$$208]  |PARTITIONED|
+                                                                                      exchange
                                                                                       -- HASH_PARTITION_EXCHANGE [$$252]  |PARTITIONED|
-                                                                                        -- PRE_CLUSTERED_GROUP_BY[$$251]  |PARTITIONED|
-                                                                                                {
+                                                                                        group by ([$$250 := $$251]) decor ([$$252]) {
+                                                                                                  aggregate [] <- []
                                                                                                   -- AGGREGATE  |LOCAL|
+                                                                                                    select (not(is-missing($$256)))
                                                                                                     -- STREAM_SELECT  |LOCAL|
+                                                                                                      nested tuple source
                                                                                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                }
+                                                                                               }
+                                                                                        -- PRE_CLUSTERED_GROUP_BY[$$251]  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                            project ([$$252, $$256, $$251])
                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                              exchange
                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                left outer join (eq($$251, $$255))
                                                                                                 -- HYBRID_HASH_JOIN [$$251][$$255]  |PARTITIONED|
+                                                                                                  exchange
                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                    project ([$$252, $$251])
                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                      assign [$$252, $$251] <- [$$385, $$393]
                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                        exchange
                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                          replicate
                                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                                            exchange
                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                              replicate
                                                                                                               -- REPLICATE  |PARTITIONED|
+                                                                                                                exchange
                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                  project ([$$385, $$393])
                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                    assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                      exchange
                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                        -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                        data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                          exchange
                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                            empty-tuple-source
                                                                                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                  exchange
                                                                                                   -- HASH_PARTITION_EXCHANGE [$$255]  |PARTITIONED|
+                                                                                                    assign [$$256] <- [true]
                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                      project ([$$255])
                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                        exchange
                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                          join (eq($$259, $$260))
                                                                                                           -- HYBRID_HASH_JOIN [$$260][$$259]  |PARTITIONED|
+                                                                                                            exchange
                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                              project ([$$255, $$260])
                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                select ($$261)
                                                                                                                 -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                  project ([$$261, $$255, $$260])
                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                    exchange
                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                      -- PRE_CLUSTERED_GROUP_BY[$$262, $$264]  |PARTITIONED|
-                                                                                                                              {
+                                                                                                                      group by ([$$255 := $$262; $$263 := $$264]) decor ([$$260]) {
+                                                                                                                                aggregate [$$261] <- [non-empty-stream()]
                                                                                                                                 -- AGGREGATE  |LOCAL|
+                                                                                                                                  select (not(is-missing($$274)))
                                                                                                                                   -- STREAM_SELECT  |LOCAL|
+                                                                                                                                    nested tuple source
                                                                                                                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                                              }
+                                                                                                                             }
+                                                                                                                      -- PRE_CLUSTERED_GROUP_BY[$$262, $$264]  |PARTITIONED|
+                                                                                                                        exchange
                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                          order (ASC, $$262) (ASC, $$264)
                                                                                                                           -- STABLE_SORT [$$262(ASC), $$264(ASC)]  |PARTITIONED|
+                                                                                                                            exchange
                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                              project ([$$260, $$274, $$262, $$264])
                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                exchange
                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                  left outer join (and(eq($$262, $$272), eq($$264, $$273)))
                                                                                                                                   -- HYBRID_HASH_JOIN [$$262, $$264][$$272, $$273]  |PARTITIONED|
+                                                                                                                                    exchange
                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                      project ([$$260, $$262, $$264])
                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                        assign [$$260, $$262, $$264] <- [$$401, $$403, $$405]
                                                                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                                                                          exchange
                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                            replicate
                                                                                                                                             -- REPLICATE  |PARTITIONED|
+                                                                                                                                              exchange
                                                                                                                                               -- HASH_PARTITION_EXCHANGE [$$403, $$405]  |PARTITIONED|
+                                                                                                                                                project ([$$401, $$403, $$405])
                                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                  exchange
                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                    join (eq($$409, $$408))
                                                                                                                                                     -- HYBRID_HASH_JOIN [$$408][$$409]  |PARTITIONED|
+                                                                                                                                                      exchange
                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                        project ([$$403, $$408])
                                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                          assign [$$403, $$408] <- [$$429, $$439]
                                                                                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                                                                                            exchange
                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                              replicate
                                                                                                                                                               -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                exchange
                                                                                                                                                                 -- HASH_PARTITION_EXCHANGE [$$439]  |PARTITIONED|
+                                                                                                                                                                  project ([$$439, $$429])
                                                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                    assign [$$439, $$429] <- [$$385, $$393]
                                                                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                      exchange
                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                        replicate
                                                                                                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                          exchange
                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                            project ([$$385, $$393])
                                                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                              assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                exchange
                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                  -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                                                                                  data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                    exchange
                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                      empty-tuple-source
                                                                                                                                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                      exchange
                                                                                                                                                       -- HASH_PARTITION_EXCHANGE [$$409]  |PARTITIONED|
+                                                                                                                                                        project ([$$401, $$405, $$409])
                                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                          select (eq($$411.getField("to_u"), "aaaaa"))
                                                                                                                                                           -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                            assign [$$409, $$401] <- [$$411.getField("y_id"), $$411.getField("a")]
                                                                                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                                                                                              exchange
                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                replicate
                                                                                                                                                                 -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                  exchange
                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                    -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                                    data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                      exchange
                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                        empty-tuple-source
                                                                                                                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                    exchange
                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                      assign [$$274] <- [true]
                                                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                                                        project ([$$272, $$273])
                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                          select (eq($$275, $$276))
                                                                                                                                           -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                            project ([$$272, $$273, $$275, $$276])
                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                              unnest $$276 <- scan-collection($$277)
                                                                                                                                               -- UNNEST  |PARTITIONED|
+                                                                                                                                                exchange
                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                  -- PRE_CLUSTERED_GROUP_BY[$$278, $$279]  |PARTITIONED|
-                                                                                                                                                          {
+                                                                                                                                                  group by ([$$272 := $$278; $$273 := $$279]) decor ([$$275]) {
+                                                                                                                                                            aggregate [$$277] <- [listify($$309)]
                                                                                                                                                             -- AGGREGATE  |LOCAL|
+                                                                                                                                                              aggregate [$$309] <- [agg-sql-max($$291)]
                                                                                                                                                               -- AGGREGATE  |LOCAL|
+                                                                                                                                                                select (not(is-missing($$290)))
                                                                                                                                                                 -- STREAM_SELECT  |LOCAL|
+                                                                                                                                                                  nested tuple source
                                                                                                                                                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                                                                          }
+                                                                                                                                                         }
+                                                                                                                                                  -- PRE_CLUSTERED_GROUP_BY[$$278, $$279]  |PARTITIONED|
+                                                                                                                                                    exchange
                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                      order (ASC, $$278) (ASC, $$279)
                                                                                                                                                       -- STABLE_SORT [$$278(ASC), $$279(ASC)]  |PARTITIONED|
+                                                                                                                                                        exchange
                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                          project ([$$275, $$291, $$290, $$278, $$279])
                                                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                            exchange
                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                              left outer join (and(eq($$278, $$288), eq($$279, $$289)))
                                                                                                                                                               -- HYBRID_HASH_JOIN [$$278, $$279][$$288, $$289]  |PARTITIONED|
+                                                                                                                                                                exchange
                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                  project ([$$275, $$278, $$279])
                                                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                    assign [$$275, $$278, $$279] <- [$$416, $$419, $$420]
                                                                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                      exchange
                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                        replicate
                                                                                                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                          exchange
                                                                                                                                                                           -- HASH_PARTITION_EXCHANGE [$$419, $$420]  |PARTITIONED|
+                                                                                                                                                                            project ([$$416, $$419, $$420])
                                                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                              exchange
                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                join (eq($$427, $$428))
                                                                                                                                                                                 -- HYBRID_HASH_JOIN [$$428][$$427]  |PARTITIONED|
+                                                                                                                                                                                  exchange
                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                    project ([$$419, $$428])
                                                                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                      assign [$$419, $$428] <- [$$429, $$439]
                                                                                                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                        exchange
                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                          replicate
                                                                                                                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                            exchange
                                                                                                                                                                                             -- HASH_PARTITION_EXCHANGE [$$439]  |PARTITIONED|
+                                                                                                                                                                                              project ([$$439, $$429])
                                                                                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                assign [$$439, $$429] <- [$$385, $$393]
                                                                                                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                  exchange
                                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                    replicate
                                                                                                                                                                                                     -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                      exchange
                                                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                        project ([$$385, $$393])
                                                                                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                          assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                            exchange
                                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                              -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                                                                                                              data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                                                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                exchange
                                                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                  empty-tuple-source
                                                                                                                                                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                                  exchange
                                                                                                                                                                                   -- HASH_PARTITION_EXCHANGE [$$427]  |PARTITIONED|
+                                                                                                                                                                                    project ([$$416, $$420, $$427])
                                                                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                      select (eq($$422.getField("to_u"), "aaaaa"))
                                                                                                                                                                                       -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                                                        exchange
                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                          replicate
                                                                                                                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                            exchange
                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                              assign [$$427, $$416] <- [$$422.getField("y_id"), $$422.getField("b")]
                                                                                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                project ([$$420, $$422])
                                                                                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                  assign [$$420, $$422] <- [$$405, $$411]
                                                                                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                    exchange
                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                      replicate
                                                                                                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                        exchange
                                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                          -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                                                                          data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                            exchange
                                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                              empty-tuple-source
                                                                                                                                                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                exchange
                                                                                                                                                                 -- HASH_PARTITION_EXCHANGE [$$288, $$289]  |PARTITIONED|
+                                                                                                                                                                  assign [$$290] <- [true]
                                                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                    project ([$$291, $$288, $$289])
                                                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                      exchange
                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                        join (eq($$301, $$298))
                                                                                                                                                                         -- HYBRID_HASH_JOIN [$$298][$$301]  |PARTITIONED|
+                                                                                                                                                                          exchange
                                                                                                                                                                           -- HASH_PARTITION_EXCHANGE [$$298]  |PARTITIONED|
+                                                                                                                                                                            project ([$$291, $$288, $$298])
                                                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                              exchange
                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                join (eq($$297, $$298))
                                                                                                                                                                                 -- HYBRID_HASH_JOIN [$$297][$$298]  |PARTITIONED|
+                                                                                                                                                                                  exchange
                                                                                                                                                                                   -- HASH_PARTITION_EXCHANGE [$$297]  |PARTITIONED|
+                                                                                                                                                                                    project ([$$291, $$297])
                                                                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                      exchange
                                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                        join (eq($$295, $$296))
                                                                                                                                                                                         -- HYBRID_HASH_JOIN [$$296][$$295]  |PARTITIONED|
+                                                                                                                                                                                          exchange
                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                            project ([$$291, $$297, $$296])
                                                                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                              assign [$$291, $$297, $$296] <- [$$432, $$438, $$437]
                                                                                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                exchange
                                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                  replicate
                                                                                                                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                    exchange
                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                      project ([$$432, $$438, $$437])
                                                                                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                        select (eq($$435.getField("to_u"), "aaaaa"))
                                                                                                                                                                                                         -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                                                                          assign [$$438, $$437, $$432] <- [$$435.getField("y_id"), $$435.getField("a"), $$435.getField("b")]
                                                                                                                                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                            exchange
                                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                              replicate
                                                                                                                                                                                                               -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                exchange
                                                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                  project ([$$435])
                                                                                                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                                      -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                                                                                      data-scan []<-[$$441, $$435] <- test.collection1
+                                                                                                                                                                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                        exchange
                                                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                          empty-tuple-source
                                                                                                                                                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                                          exchange
                                                                                                                                                                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                            unnest $$295 <- scan-collection(array: [ 66, 67, 26, 12, 13 ])
                                                                                                                                                                                             -- UNNEST  |UNPARTITIONED|
+                                                                                                                                                                                              empty-tuple-source
                                                                                                                                                                                               -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                                                                                                                                                                  exchange
                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                    project ([$$288, $$298])
                                                                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                      assign [$$288, $$298] <- [$$429, $$439]
                                                                                                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                        exchange
                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                          replicate
                                                                                                                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                            exchange
                                                                                                                                                                                             -- HASH_PARTITION_EXCHANGE [$$439]  |PARTITIONED|
+                                                                                                                                                                                              project ([$$439, $$429])
                                                                                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                assign [$$439, $$429] <- [$$385, $$393]
                                                                                                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                  exchange
                                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                    replicate
                                                                                                                                                                                                     -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                      exchange
                                                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                        project ([$$385, $$393])
                                                                                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                          assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                            exchange
                                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                              -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                                                                                                              data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                                                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                exchange
                                                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                  empty-tuple-source
                                                                                                                                                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                          exchange
                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                            project ([$$289, $$301])
                                                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                              assign [$$289, $$301] <- [$$430, $$442]
                                                                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                exchange
                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                  replicate
                                                                                                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                    exchange
                                                                                                                                                                                     -- HASH_PARTITION_EXCHANGE [$$442]  |PARTITIONED|
+                                                                                                                                                                                      project ([$$430, $$442])
                                                                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                        select (eq($$444.getField("to_u"), "aaaaa"))
                                                                                                                                                                                         -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                                                          project ([$$430, $$444, $$442])
                                                                                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                            assign [$$430, $$444, $$442] <- [$$391, $$386, $$384]
                                                                                                                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                              exchange
                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                replicate
                                                                                                                                                                                                 -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                  exchange
                                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                    assign [$$384] <- [$$386.getField("y_id")]
                                                                                                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                      project ([$$391, $$386])
                                                                                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                        assign [$$391, $$386] <- [$$405, $$411]
                                                                                                                                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                          exchange
                                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                            replicate
                                                                                                                                                                                                             -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                              exchange
                                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                                -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                                                                                data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                                                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                  exchange
                                                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                    empty-tuple-source
                                                                                                                                                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                            exchange
                                                                                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                                              unnest $$259 <- scan-collection(array: [ 66, 67, 26, 12, 13 ])
                                                                                                               -- UNNEST  |UNPARTITIONED|
+                                                                                                                empty-tuple-source
                                                                                                                 -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                                                                      exchange
                                                                                       -- HASH_PARTITION_EXCHANGE [$$208]  |PARTITIONED|
+                                                                                        project ([$$213, $$156, $$159, $$190, $$208])
                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                          assign [$$213, $$159, $$156, $$208] <- [$$H.getField("u"), $$H.getField("posi"), $$H.getField("a"), $$H.getField("y_id")]
                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                            project ([$$190, $$H])
                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                              assign [$$190, $$H] <- [$$405, $$411]
                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                exchange
                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                  replicate
                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                    exchange
                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                      -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                      data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                        exchange
                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                          empty-tuple-source
                                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                              exchange
                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                assign [$$381] <- [true]
                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                  project ([$$453, $$454])
                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                    select (eq($$318, $#11))
                                                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                                                      project ([$$453, $$454, $$318, $#11])
                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                        unnest $#11 <- scan-collection($$177)
                                                                                         -- UNNEST  |PARTITIONED|
+                                                                                          exchange
                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                            -- PRE_CLUSTERED_GROUP_BY[$$321, $$320]  |PARTITIONED|
-                                                                                                    {
+                                                                                            group by ([$$453 := $$321; $$454 := $$320]) decor ([$$318]) {
+                                                                                                      aggregate [$$177] <- [listify($$198)]
                                                                                                       -- AGGREGATE  |LOCAL|
+                                                                                                        aggregate [$$198] <- [agg-sql-max($$174)]
                                                                                                         -- AGGREGATE  |LOCAL|
+                                                                                                          select (not(is-missing($$452)))
                                                                                                           -- STREAM_SELECT  |LOCAL|
+                                                                                                            nested tuple source
                                                                                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                    }
+                                                                                                   }
+                                                                                            -- PRE_CLUSTERED_GROUP_BY[$$321, $$320]  |PARTITIONED|
+                                                                                              exchange
                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                order (ASC, $$321) (ASC, $$320)
                                                                                                 -- STABLE_SORT [$$321(ASC), $$320(ASC)]  |PARTITIONED|
+                                                                                                  exchange
                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                    project ([$$318, $$174, $$452, $$321, $$320])
                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                      exchange
                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                        left outer join (and(eq($$321, $$392), eq($$320, $$391)))
                                                                                                         -- HYBRID_HASH_JOIN [$$321, $$320][$$392, $$391]  |PARTITIONED|
+                                                                                                          exchange
                                                                                                           -- HASH_PARTITION_EXCHANGE [$$321, $$320]  |PARTITIONED|
+                                                                                                            project ([$$318, $$321, $$320])
                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                              exchange
                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                join (eq($$313, $$314))
                                                                                                                 -- HYBRID_HASH_JOIN [$$314][$$313]  |PARTITIONED|
+                                                                                                                  exchange
                                                                                                                   -- HASH_PARTITION_EXCHANGE [$$314]  |PARTITIONED|
-                                                                                                                    -- PRE_CLUSTERED_GROUP_BY[$$322]  |PARTITIONED|
-                                                                                                                            {
+                                                                                                                    group by ([$$321 := $$322]) decor ([$$314]) {
+                                                                                                                              aggregate [] <- []
                                                                                                                               -- AGGREGATE  |LOCAL|
+                                                                                                                                select (not(is-missing($$326)))
                                                                                                                                 -- STREAM_SELECT  |LOCAL|
+                                                                                                                                  nested tuple source
                                                                                                                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                                            }
+                                                                                                                           }
+                                                                                                                    -- PRE_CLUSTERED_GROUP_BY[$$322]  |PARTITIONED|
+                                                                                                                      exchange
                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                        project ([$$314, $$326, $$322])
                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                          exchange
                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                            left outer join (eq($$322, $$325))
                                                                                                                             -- HYBRID_HASH_JOIN [$$322][$$325]  |PARTITIONED|
+                                                                                                                              exchange
                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                project ([$$314, $$322])
                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                  assign [$$314, $$322] <- [$$385, $$393]
                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                    exchange
                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                      replicate
                                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                                        exchange
                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                          replicate
                                                                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                                                                            exchange
                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                              project ([$$385, $$393])
                                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                                                  exchange
                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                    -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                                                    data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                      exchange
                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                        empty-tuple-source
                                                                                                                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                              exchange
                                                                                                                               -- HASH_PARTITION_EXCHANGE [$$325]  |PARTITIONED|
+                                                                                                                                assign [$$326] <- [true]
                                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                                  project ([$$325])
                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                    exchange
                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                      join (eq($$329, $$330))
                                                                                                                                       -- HYBRID_HASH_JOIN [$$330][$$329]  |PARTITIONED|
+                                                                                                                                        exchange
                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                          project ([$$325, $$330])
                                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                            select ($$331)
                                                                                                                                             -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                              project ([$$331, $$325, $$330])
                                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                exchange
                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                  -- PRE_CLUSTERED_GROUP_BY[$$332, $$334]  |PARTITIONED|
-                                                                                                                                                          {
+                                                                                                                                                  group by ([$$325 := $$332; $$333 := $$334]) decor ([$$330]) {
+                                                                                                                                                            aggregate [$$331] <- [non-empty-stream()]
                                                                                                                                                             -- AGGREGATE  |LOCAL|
+                                                                                                                                                              select (not(is-missing($$344)))
                                                                                                                                                               -- STREAM_SELECT  |LOCAL|
+                                                                                                                                                                nested tuple source
                                                                                                                                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                                                                          }
+                                                                                                                                                         }
+                                                                                                                                                  -- PRE_CLUSTERED_GROUP_BY[$$332, $$334]  |PARTITIONED|
+                                                                                                                                                    exchange
                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                      order (ASC, $$332) (ASC, $$334)
                                                                                                                                                       -- STABLE_SORT [$$332(ASC), $$334(ASC)]  |PARTITIONED|
+                                                                                                                                                        exchange
                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                          project ([$$330, $$344, $$332, $$334])
                                                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                            exchange
                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                              left outer join (and(eq($$332, $$342), eq($$334, $$343)))
                                                                                                                                                               -- HYBRID_HASH_JOIN [$$332, $$334][$$342, $$343]  |PARTITIONED|
+                                                                                                                                                                exchange
                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                  project ([$$330, $$332, $$334])
                                                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                    assign [$$330, $$332, $$334] <- [$$401, $$403, $$405]
                                                                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                      exchange
                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                        replicate
                                                                                                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                          exchange
                                                                                                                                                                           -- HASH_PARTITION_EXCHANGE [$$403, $$405]  |PARTITIONED|
+                                                                                                                                                                            project ([$$401, $$403, $$405])
                                                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                              exchange
                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                join (eq($$409, $$408))
                                                                                                                                                                                 -- HYBRID_HASH_JOIN [$$408][$$409]  |PARTITIONED|
+                                                                                                                                                                                  exchange
                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                    project ([$$403, $$408])
                                                                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                      assign [$$403, $$408] <- [$$429, $$439]
                                                                                                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                        exchange
                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                          replicate
                                                                                                                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                            exchange
                                                                                                                                                                                             -- HASH_PARTITION_EXCHANGE [$$439]  |PARTITIONED|
+                                                                                                                                                                                              project ([$$439, $$429])
                                                                                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                assign [$$439, $$429] <- [$$385, $$393]
                                                                                                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                  exchange
                                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                    replicate
                                                                                                                                                                                                     -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                      exchange
                                                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                        project ([$$385, $$393])
                                                                                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                          assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                            exchange
                                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                              -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                                                                                                              data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                                                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                exchange
                                                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                  empty-tuple-source
                                                                                                                                                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                                  exchange
                                                                                                                                                                                   -- HASH_PARTITION_EXCHANGE [$$409]  |PARTITIONED|
+                                                                                                                                                                                    project ([$$401, $$405, $$409])
                                                                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                      select (eq($$411.getField("to_u"), "aaaaa"))
                                                                                                                                                                                       -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                                                        assign [$$409, $$401] <- [$$411.getField("y_id"), $$411.getField("a")]
                                                                                                                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                          exchange
                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                            replicate
                                                                                                                                                                                             -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                              exchange
                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                                                                data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                  exchange
                                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                    empty-tuple-source
                                                                                                                                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                exchange
                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                  assign [$$344] <- [true]
                                                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                    project ([$$342, $$343])
                                                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                      select (eq($$345, $$346))
                                                                                                                                                                       -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                                        project ([$$342, $$343, $$345, $$346])
                                                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                          unnest $$346 <- scan-collection($$347)
                                                                                                                                                                           -- UNNEST  |PARTITIONED|
+                                                                                                                                                                            exchange
                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                              -- PRE_CLUSTERED_GROUP_BY[$$348, $$349]  |PARTITIONED|
-                                                                                                                                                                                      {
+                                                                                                                                                                              group by ([$$342 := $$348; $$343 := $$349]) decor ([$$345]) {
+                                                                                                                                                                                        aggregate [$$347] <- [listify($$379)]
                                                                                                                                                                                         -- AGGREGATE  |LOCAL|
+                                                                                                                                                                                          aggregate [$$379] <- [agg-sql-max($$361)]
                                                                                                                                                                                           -- AGGREGATE  |LOCAL|
+                                                                                                                                                                                            select (not(is-missing($$360)))
                                                                                                                                                                                             -- STREAM_SELECT  |LOCAL|
+                                                                                                                                                                                              nested tuple source
                                                                                                                                                                                               -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                                                                                                      }
+                                                                                                                                                                                     }
+                                                                                                                                                                              -- PRE_CLUSTERED_GROUP_BY[$$348, $$349]  |PARTITIONED|
+                                                                                                                                                                                exchange
                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                  order (ASC, $$348) (ASC, $$349)
                                                                                                                                                                                   -- STABLE_SORT [$$348(ASC), $$349(ASC)]  |PARTITIONED|
+                                                                                                                                                                                    exchange
                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                      project ([$$345, $$361, $$360, $$348, $$349])
                                                                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                        exchange
                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                          left outer join (and(eq($$348, $$358), eq($$349, $$359)))
                                                                                                                                                                                           -- HYBRID_HASH_JOIN [$$348, $$349][$$358, $$359]  |PARTITIONED|
+                                                                                                                                                                                            exchange
                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                              project ([$$345, $$348, $$349])
                                                                                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                assign [$$345, $$348, $$349] <- [$$416, $$419, $$420]
                                                                                                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                  exchange
                                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                    replicate
                                                                                                                                                                                                     -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                      exchange
                                                                                                                                                                                                       -- HASH_PARTITION_EXCHANGE [$$419, $$420]  |PARTITIONED|
+                                                                                                                                                                                                        project ([$$416, $$419, $$420])
                                                                                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                          exchange
                                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                            join (eq($$427, $$428))
                                                                                                                                                                                                             -- HYBRID_HASH_JOIN [$$428][$$427]  |PARTITIONED|
+                                                                                                                                                                                                              exchange
                                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                project ([$$419, $$428])
                                                                                                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                  assign [$$419, $$428] <- [$$429, $$439]
                                                                                                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                      replicate
                                                                                                                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                        exchange
                                                                                                                                                                                                                         -- HASH_PARTITION_EXCHANGE [$$439]  |PARTITIONED|
+                                                                                                                                                                                                                          project ([$$439, $$429])
                                                                                                                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                            assign [$$439, $$429] <- [$$385, $$393]
                                                                                                                                                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                              exchange
                                                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                replicate
                                                                                                                                                                                                                                 -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                  exchange
                                                                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                    project ([$$385, $$393])
                                                                                                                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                      assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                                                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                        exchange
                                                                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                                                          -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                                                                                                                                          data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                                                                                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                                            exchange
                                                                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                              empty-tuple-source
                                                                                                                                                                                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                                                              exchange
                                                                                                                                                                                                               -- HASH_PARTITION_EXCHANGE [$$427]  |PARTITIONED|
+                                                                                                                                                                                                                project ([$$416, $$420, $$427])
                                                                                                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                  select (eq($$422.getField("to_u"), "aaaaa"))
                                                                                                                                                                                                                   -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                      replicate
                                                                                                                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                        exchange
                                                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                          assign [$$427, $$416] <- [$$422.getField("y_id"), $$422.getField("b")]
                                                                                                                                                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                            project ([$$420, $$422])
                                                                                                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                              assign [$$420, $$422] <- [$$405, $$411]
                                                                                                                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                exchange
                                                                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                  replicate
                                                                                                                                                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                                                      -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                                                                                                      data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                                                                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                                        exchange
                                                                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                          empty-tuple-source
                                                                                                                                                                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                                            exchange
                                                                                                                                                                                             -- HASH_PARTITION_EXCHANGE [$$358, $$359]  |PARTITIONED|
+                                                                                                                                                                                              assign [$$360] <- [true]
                                                                                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                project ([$$361, $$358, $$359])
                                                                                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                  exchange
                                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                    join (eq($$371, $$368))
                                                                                                                                                                                                     -- HYBRID_HASH_JOIN [$$368][$$371]  |PARTITIONED|
+                                                                                                                                                                                                      exchange
                                                                                                                                                                                                       -- HASH_PARTITION_EXCHANGE [$$368]  |PARTITIONED|
+                                                                                                                                                                                                        project ([$$361, $$358, $$368])
                                                                                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                          exchange
                                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                            join (eq($$367, $$368))
                                                                                                                                                                                                             -- HYBRID_HASH_JOIN [$$367][$$368]  |PARTITIONED|
+                                                                                                                                                                                                              exchange
                                                                                                                                                                                                               -- HASH_PARTITION_EXCHANGE [$$367]  |PARTITIONED|
+                                                                                                                                                                                                                project ([$$361, $$367])
                                                                                                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                  exchange
                                                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                    join (eq($$365, $$366))
                                                                                                                                                                                                                     -- HYBRID_HASH_JOIN [$$366][$$365]  |PARTITIONED|
+                                                                                                                                                                                                                      exchange
                                                                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                        project ([$$361, $$367, $$366])
                                                                                                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                          assign [$$361, $$367, $$366] <- [$$432, $$438, $$437]
                                                                                                                                                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                            exchange
                                                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                              replicate
                                                                                                                                                                                                                               -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                exchange
                                                                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                  project ([$$432, $$438, $$437])
                                                                                                                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                    select (eq($$435.getField("to_u"), "aaaaa"))
                                                                                                                                                                                                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                                                                                                      assign [$$438, $$437, $$432] <- [$$435.getField("y_id"), $$435.getField("a"), $$435.getField("b")]
                                                                                                                                                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                        exchange
                                                                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                          replicate
                                                                                                                                                                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                            exchange
                                                                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                              project ([$$435])
                                                                                                                                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                                exchange
                                                                                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                                                                  -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                                                                                                                  data-scan []<-[$$441, $$435] <- test.collection1
+                                                                                                                                                                                                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                      empty-tuple-source
                                                                                                                                                                                                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                                                                      exchange
                                                                                                                                                                                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                        unnest $$365 <- scan-collection(array: [ 66, 67, 26, 12, 13 ])
                                                                                                                                                                                                                         -- UNNEST  |UNPARTITIONED|
+                                                                                                                                                                                                                          empty-tuple-source
                                                                                                                                                                                                                           -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                                                                                                                                                                                              exchange
                                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                project ([$$358, $$368])
                                                                                                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                  assign [$$358, $$368] <- [$$429, $$439]
                                                                                                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                      replicate
                                                                                                                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                        exchange
                                                                                                                                                                                                                         -- HASH_PARTITION_EXCHANGE [$$439]  |PARTITIONED|
+                                                                                                                                                                                                                          project ([$$439, $$429])
                                                                                                                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                            assign [$$439, $$429] <- [$$385, $$393]
                                                                                                                                                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                              exchange
                                                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                replicate
                                                                                                                                                                                                                                 -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                  exchange
                                                                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                    project ([$$385, $$393])
                                                                                                                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                      assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                                                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                        exchange
                                                                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                                                          -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                                                                                                                                          data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                                                                                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                                            exchange
                                                                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                              empty-tuple-source
                                                                                                                                                                                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                                                      exchange
                                                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                        project ([$$359, $$371])
                                                                                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                          assign [$$359, $$371] <- [$$430, $$442]
                                                                                                                                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                            exchange
                                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                              replicate
                                                                                                                                                                                                               -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                exchange
                                                                                                                                                                                                                 -- HASH_PARTITION_EXCHANGE [$$442]  |PARTITIONED|
+                                                                                                                                                                                                                  project ([$$430, $$442])
                                                                                                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                    select (eq($$444.getField("to_u"), "aaaaa"))
                                                                                                                                                                                                                     -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                                                                                      project ([$$430, $$444, $$442])
                                                                                                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                        assign [$$430, $$444, $$442] <- [$$391, $$386, $$384]
                                                                                                                                                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                          exchange
                                                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                            replicate
                                                                                                                                                                                                                             -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                              exchange
                                                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                assign [$$384] <- [$$386.getField("y_id")]
                                                                                                                                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                  project ([$$391, $$386])
                                                                                                                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                    assign [$$391, $$386] <- [$$405, $$411]
                                                                                                                                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                      exchange
                                                                                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                        replicate
                                                                                                                                                                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                          exchange
                                                                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                                                            -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                                                                                                            data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                                                                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                                              exchange
                                                                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                empty-tuple-source
                                                                                                                                                                                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                        exchange
                                                                                                                                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                                                                          unnest $$329 <- scan-collection(array: [ 66, 67, 26, 12, 13 ])
                                                                                                                                           -- UNNEST  |UNPARTITIONED|
+                                                                                                                                            empty-tuple-source
                                                                                                                                             -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                                                                                                  exchange
                                                                                                                   -- HASH_PARTITION_EXCHANGE [$$313]  |PARTITIONED|
+                                                                                                                    project ([$$318, $$320, $$313])
                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                      assign [$$320, $$315, $$313, $$318] <- [$$420, $$422, $$427, $$416]
                                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                                        exchange
                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                          replicate
                                                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                                                            exchange
                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                              assign [$$427, $$416] <- [$$422.getField("y_id"), $$422.getField("b")]
                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                project ([$$420, $$422])
                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                  assign [$$420, $$422] <- [$$405, $$411]
                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                    exchange
                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                      replicate
                                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                                        exchange
                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                          -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                          data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                            exchange
                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                              empty-tuple-source
                                                                                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                          exchange
                                                                                                           -- HASH_PARTITION_EXCHANGE [$$392, $$391]  |PARTITIONED|
+                                                                                                            assign [$$452] <- [true]
                                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                                              project ([$$174, $$392, $$391])
                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                exchange
                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                  join (eq($$194, $$166))
                                                                                                                   -- HYBRID_HASH_JOIN [$$166][$$194]  |PARTITIONED|
+                                                                                                                    exchange
                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                      project ([$$174, $$392, $$391, $$166])
                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                        exchange
                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                          join (eq($$210, $$385))
                                                                                                                           -- HYBRID_HASH_JOIN [$$385][$$210]  |PARTITIONED|
+                                                                                                                            exchange
                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                              project ([$$392, $$391, $$385])
                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                exchange
                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                  join (eq($$384, $$385))
                                                                                                                                   -- HYBRID_HASH_JOIN [$$385][$$384]  |PARTITIONED|
+                                                                                                                                    exchange
                                                                                                                                     -- HASH_PARTITION_EXCHANGE [$$385]  |PARTITIONED|
-                                                                                                                                      -- PRE_CLUSTERED_GROUP_BY[$$393]  |PARTITIONED|
-                                                                                                                                              {
+                                                                                                                                      group by ([$$392 := $$393]) decor ([$$385]) {
+                                                                                                                                                aggregate [] <- []
                                                                                                                                                 -- AGGREGATE  |LOCAL|
+                                                                                                                                                  select (not(is-missing($$397)))
                                                                                                                                                   -- STREAM_SELECT  |LOCAL|
+                                                                                                                                                    nested tuple source
                                                                                                                                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                                                              }
+                                                                                                                                             }
+                                                                                                                                      -- PRE_CLUSTERED_GROUP_BY[$$393]  |PARTITIONED|
+                                                                                                                                        exchange
                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                          project ([$$385, $$397, $$393])
                                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                            exchange
                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                              left outer join (eq($$393, $$396))
                                                                                                                                               -- HYBRID_HASH_JOIN [$$393][$$396]  |PARTITIONED|
+                                                                                                                                                exchange
                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                  replicate
                                                                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                                                                    exchange
                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                      replicate
                                                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                                                        exchange
                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                          project ([$$385, $$393])
                                                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                            assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                                                                                              exchange
                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                                                                data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                  exchange
                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                    empty-tuple-source
                                                                                                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                exchange
                                                                                                                                                 -- HASH_PARTITION_EXCHANGE [$$396]  |PARTITIONED|
+                                                                                                                                                  assign [$$397] <- [true]
                                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                                    project ([$$396])
                                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                      exchange
                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                        join (eq($$400, $$401))
                                                                                                                                                         -- HYBRID_HASH_JOIN [$$401][$$400]  |PARTITIONED|
+                                                                                                                                                          exchange
                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                            project ([$$396, $$401])
                                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                              select ($$402)
                                                                                                                                                               -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                                project ([$$402, $$396, $$401])
                                                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                  exchange
                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                    -- PRE_CLUSTERED_GROUP_BY[$$403, $$405]  |PARTITIONED|
-                                                                                                                                                                            {
+                                                                                                                                                                    group by ([$$396 := $$403; $$404 := $$405]) decor ([$$401]) {
+                                                                                                                                                                              aggregate [$$402] <- [non-empty-stream()]
                                                                                                                                                                               -- AGGREGATE  |LOCAL|
+                                                                                                                                                                                select (not(is-missing($$415)))
                                                                                                                                                                                 -- STREAM_SELECT  |LOCAL|
+                                                                                                                                                                                  nested tuple source
                                                                                                                                                                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                                                                                            }
+                                                                                                                                                                           }
+                                                                                                                                                                    -- PRE_CLUSTERED_GROUP_BY[$$403, $$405]  |PARTITIONED|
+                                                                                                                                                                      exchange
                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                        order (ASC, $$403) (ASC, $$405)
                                                                                                                                                                         -- STABLE_SORT [$$403(ASC), $$405(ASC)]  |PARTITIONED|
+                                                                                                                                                                          exchange
                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                            project ([$$401, $$415, $$403, $$405])
                                                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                              exchange
                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                left outer join (and(eq($$403, $$413), eq($$405, $$414)))
                                                                                                                                                                                 -- HYBRID_HASH_JOIN [$$403, $$405][$$413, $$414]  |PARTITIONED|
+                                                                                                                                                                                  exchange
                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                    replicate
                                                                                                                                                                                     -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                      exchange
                                                                                                                                                                                       -- HASH_PARTITION_EXCHANGE [$$403, $$405]  |PARTITIONED|
+                                                                                                                                                                                        project ([$$401, $$403, $$405])
                                                                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                          exchange
                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                            join (eq($$409, $$408))
                                                                                                                                                                                             -- HYBRID_HASH_JOIN [$$408][$$409]  |PARTITIONED|
+                                                                                                                                                                                              exchange
                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                project ([$$403, $$408])
                                                                                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                  assign [$$403, $$408] <- [$$429, $$439]
                                                                                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                    exchange
                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                      replicate
                                                                                                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                        exchange
                                                                                                                                                                                                         -- HASH_PARTITION_EXCHANGE [$$439]  |PARTITIONED|
+                                                                                                                                                                                                          project ([$$439, $$429])
                                                                                                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                            assign [$$439, $$429] <- [$$385, $$393]
                                                                                                                                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                              exchange
                                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                replicate
                                                                                                                                                                                                                 -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                  exchange
                                                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                    project ([$$385, $$393])
                                                                                                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                      assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                        exchange
                                                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                                          -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                                                                                                                          data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                                                                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                            exchange
                                                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                              empty-tuple-source
                                                                                                                                                                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                                              exchange
                                                                                                                                                                                               -- HASH_PARTITION_EXCHANGE [$$409]  |PARTITIONED|
+                                                                                                                                                                                                project ([$$401, $$405, $$409])
                                                                                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                  select (eq($$411.getField("to_u"), "aaaaa"))
                                                                                                                                                                                                   -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                                                                    assign [$$409, $$401] <- [$$411.getField("y_id"), $$411.getField("a")]
                                                                                                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                      exchange
                                                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                        replicate
                                                                                                                                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                          exchange
                                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                            -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                                                                            data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                                                                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                              exchange
                                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                empty-tuple-source
                                                                                                                                                                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                                  exchange
                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                    assign [$$415] <- [true]
                                                                                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                      project ([$$413, $$414])
                                                                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                        select (eq($$416, $$417))
                                                                                                                                                                                         -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                                                          project ([$$413, $$414, $$416, $$417])
                                                                                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                            unnest $$417 <- scan-collection($$418)
                                                                                                                                                                                             -- UNNEST  |PARTITIONED|
+                                                                                                                                                                                              exchange
                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                -- PRE_CLUSTERED_GROUP_BY[$$419, $$420]  |PARTITIONED|
-                                                                                                                                                                                                        {
+                                                                                                                                                                                                group by ([$$413 := $$419; $$414 := $$420]) decor ([$$416]) {
+                                                                                                                                                                                                          aggregate [$$418] <- [listify($$450)]
                                                                                                                                                                                                           -- AGGREGATE  |LOCAL|
+                                                                                                                                                                                                            aggregate [$$450] <- [agg-sql-max($$432)]
                                                                                                                                                                                                             -- AGGREGATE  |LOCAL|
+                                                                                                                                                                                                              select (not(is-missing($$431)))
                                                                                                                                                                                                               -- STREAM_SELECT  |LOCAL|
+                                                                                                                                                                                                                nested tuple source
                                                                                                                                                                                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                                                                                                                                        }
+                                                                                                                                                                                                       }
+                                                                                                                                                                                                -- PRE_CLUSTERED_GROUP_BY[$$419, $$420]  |PARTITIONED|
+                                                                                                                                                                                                  exchange
                                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                    order (ASC, $$419) (ASC, $$420)
                                                                                                                                                                                                     -- STABLE_SORT [$$419(ASC), $$420(ASC)]  |PARTITIONED|
+                                                                                                                                                                                                      exchange
                                                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                        project ([$$416, $$432, $$431, $$419, $$420])
                                                                                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                          exchange
                                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                            left outer join (and(eq($$419, $$429), eq($$420, $$430)))
                                                                                                                                                                                                             -- HYBRID_HASH_JOIN [$$419, $$420][$$429, $$430]  |PARTITIONED|
+                                                                                                                                                                                                              exchange
                                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                replicate
                                                                                                                                                                                                                 -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                  exchange
                                                                                                                                                                                                                   -- HASH_PARTITION_EXCHANGE [$$419, $$420]  |PARTITIONED|
+                                                                                                                                                                                                                    project ([$$416, $$419, $$420])
                                                                                                                                                                                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                      exchange
                                                                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                        join (eq($$427, $$428))
                                                                                                                                                                                                                         -- HYBRID_HASH_JOIN [$$428][$$427]  |PARTITIONED|
+                                                                                                                                                                                                                          exchange
                                                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                            project ([$$419, $$428])
                                                                                                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                              assign [$$419, $$428] <- [$$429, $$439]
                                                                                                                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                exchange
                                                                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                  replicate
                                                                                                                                                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                                     -- HASH_PARTITION_EXCHANGE [$$439]  |PARTITIONED|
+                                                                                                                                                                                                                                      project ([$$439, $$429])
                                                                                                                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                        assign [$$439, $$429] <- [$$385, $$393]
                                                                                                                                                                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                          exchange
                                                                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                            replicate
                                                                                                                                                                                                                                             -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                              exchange
                                                                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                project ([$$385, $$393])
                                                                                                                                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                                  assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                                                                      -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                                                                                                                                                      data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                                                                                                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                                                        exchange
                                                                                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                          empty-tuple-source
                                                                                                                                                                                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                                                                          exchange
                                                                                                                                                                                                                           -- HASH_PARTITION_EXCHANGE [$$427]  |PARTITIONED|
+                                                                                                                                                                                                                            project ([$$416, $$420, $$427])
                                                                                                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                              select (eq($$422.getField("to_u"), "aaaaa"))
                                                                                                                                                                                                                               -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                                                                                                exchange
                                                                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                  replicate
                                                                                                                                                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                      assign [$$427, $$416] <- [$$422.getField("y_id"), $$422.getField("b")]
                                                                                                                                                                                                                                       -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                        project ([$$420, $$422])
                                                                                                                                                                                                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                          assign [$$420, $$422] <- [$$405, $$411]
                                                                                                                                                                                                                                           -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                            exchange
                                                                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                              replicate
                                                                                                                                                                                                                                               -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                                exchange
                                                                                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                                                                  -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                                                                                                                  data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                                                                                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                      empty-tuple-source
                                                                                                                                                                                                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                                                              exchange
                                                                                                                                                                                                               -- HASH_PARTITION_EXCHANGE [$$429, $$430]  |PARTITIONED|
+                                                                                                                                                                                                                assign [$$431] <- [true]
                                                                                                                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                  project ([$$432, $$429, $$430])
                                                                                                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                      join (eq($$442, $$439))
                                                                                                                                                                                                                       -- HYBRID_HASH_JOIN [$$439][$$442]  |PARTITIONED|
+                                                                                                                                                                                                                        exchange
                                                                                                                                                                                                                         -- HASH_PARTITION_EXCHANGE [$$439]  |PARTITIONED|
+                                                                                                                                                                                                                          project ([$$432, $$429, $$439])
                                                                                                                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                            exchange
                                                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                              join (eq($$438, $$439))
                                                                                                                                                                                                                               -- HYBRID_HASH_JOIN [$$438][$$439]  |PARTITIONED|
+                                                                                                                                                                                                                                exchange
                                                                                                                                                                                                                                 -- HASH_PARTITION_EXCHANGE [$$438]  |PARTITIONED|
+                                                                                                                                                                                                                                  project ([$$432, $$438])
                                                                                                                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                      join (eq($$436, $$437))
                                                                                                                                                                                                                                       -- HYBRID_HASH_JOIN [$$437][$$436]  |PARTITIONED|
+                                                                                                                                                                                                                                        exchange
                                                                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                          replicate
                                                                                                                                                                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                            exchange
                                                                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                              project ([$$432, $$438, $$437])
                                                                                                                                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                                select (eq($$435.getField("to_u"), "aaaaa"))
                                                                                                                                                                                                                                                 -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                                                                                                                  assign [$$438, $$437, $$432] <- [$$435.getField("y_id"), $$435.getField("a"), $$435.getField("b")]
                                                                                                                                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                      replicate
                                                                                                                                                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                                        exchange
                                                                                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                          project ([$$435])
                                                                                                                                                                                                                                                           -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                                            exchange
                                                                                                                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                                                                              -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                                                                                                                              data-scan []<-[$$441, $$435] <- test.collection1
+                                                                                                                                                                                                                                                              -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                                                                exchange
                                                                                                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                                  empty-tuple-source
                                                                                                                                                                                                                                                                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                                                                                        exchange
                                                                                                                                                                                                                                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                          unnest $$436 <- scan-collection(array: [ 66, 67, 26, 12, 13 ])
                                                                                                                                                                                                                                           -- UNNEST  |UNPARTITIONED|
+                                                                                                                                                                                                                                            empty-tuple-source
                                                                                                                                                                                                                                             -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                                                                                                                                                                                                                exchange
                                                                                                                                                                                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                  replicate
                                                                                                                                                                                                                                   -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                                     -- HASH_PARTITION_EXCHANGE [$$439]  |PARTITIONED|
+                                                                                                                                                                                                                                      project ([$$439, $$429])
                                                                                                                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                        assign [$$439, $$429] <- [$$385, $$393]
                                                                                                                                                                                                                                         -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                          exchange
                                                                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                            replicate
                                                                                                                                                                                                                                             -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                              exchange
                                                                                                                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                project ([$$385, $$393])
                                                                                                                                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                                  assign [$$385] <- [$$394.getField("x_id")]
                                                                                                                                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                                    exchange
                                                                                                                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                                                                      -- DATASOURCE_SCAN (test.collection0)  |PARTITIONED|
+                                                                                                                                                                                                                                                      data-scan []<-[$$393, $$394] <- test.collection0
+                                                                                                                                                                                                                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                                                        exchange
                                                                                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                          empty-tuple-source
                                                                                                                                                                                                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                                                                                        exchange
                                                                                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                          replicate
                                                                                                                                                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                            exchange
                                                                                                                                                                                                                             -- HASH_PARTITION_EXCHANGE [$$442]  |PARTITIONED|
+                                                                                                                                                                                                                              project ([$$430, $$442])
                                                                                                                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                select (eq($$444.getField("to_u"), "aaaaa"))
                                                                                                                                                                                                                                 -- STREAM_SELECT  |PARTITIONED|
+                                                                                                                                                                                                                                  project ([$$430, $$444, $$442])
                                                                                                                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                    assign [$$430, $$444, $$442] <- [$$391, $$386, $$384]
                                                                                                                                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                      exchange
                                                                                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                        replicate
                                                                                                                                                                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                          exchange
                                                                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                            assign [$$384] <- [$$386.getField("y_id")]
                                                                                                                                                                                                                                             -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                              project ([$$391, $$386])
                                                                                                                                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                                                                                                                assign [$$391, $$386] <- [$$405, $$411]
                                                                                                                                                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                                                                                                                                                  exchange
                                                                                                                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                    replicate
                                                                                                                                                                                                                                                     -- REPLICATE  |PARTITIONED|
+                                                                                                                                                                                                                                                      exchange
                                                                                                                                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                                                                                                                        -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                                                                                                                        data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                                                                                                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                                                                                                                          exchange
                                                                                                                                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                                                                                                                            empty-tuple-source
                                                                                                                                                                                                                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                                                          exchange
                                                                                                                                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                                                                                            unnest $$400 <- scan-collection(array: [ 66, 67, 26, 12, 13 ])
                                                                                                                                                             -- UNNEST  |UNPARTITIONED|
+                                                                                                                                                              empty-tuple-source
                                                                                                                                                               -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                                                                                                                    exchange
                                                                                                                                     -- HASH_PARTITION_EXCHANGE [$$384]  |PARTITIONED|
+                                                                                                                                      project ([$$391, $$384])
                                                                                                                                       -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                        exchange
                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                          replicate
                                                                                                                                           -- REPLICATE  |PARTITIONED|
+                                                                                                                                            exchange
                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                              assign [$$384] <- [$$386.getField("y_id")]
                                                                                                                                               -- ASSIGN  |PARTITIONED|
+                                                                                                                                                project ([$$391, $$386])
                                                                                                                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                                  assign [$$391, $$386] <- [$$405, $$411]
                                                                                                                                                   -- ASSIGN  |PARTITIONED|
+                                                                                                                                                    exchange
                                                                                                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                      replicate
                                                                                                                                                       -- REPLICATE  |PARTITIONED|
+                                                                                                                                                        exchange
                                                                                                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                          -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                          data-scan []<-[$$405, $$411] <- test.collection1
+                                                                                                                                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                            exchange
                                                                                                                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                              empty-tuple-source
                                                                                                                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                            exchange
                                                                                                                             -- HASH_PARTITION_EXCHANGE [$$210]  |PARTITIONED|
+                                                                                                                              project ([$$174, $$166, $$210])
                                                                                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                assign [$$166, $$210, $$174] <- [$$L.getField("posi"), $$L.getField("y_id"), $$L.getField("b")]
                                                                                                                                 -- ASSIGN  |PARTITIONED|
+                                                                                                                                  project ([$$L])
                                                                                                                                   -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                    assign [$$L] <- [$$435]
                                                                                                                                     -- ASSIGN  |PARTITIONED|
+                                                                                                                                      exchange
                                                                                                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                        replicate
                                                                                                                                         -- REPLICATE  |PARTITIONED|
+                                                                                                                                          exchange
                                                                                                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                            project ([$$435])
                                                                                                                                             -- STREAM_PROJECT  |PARTITIONED|
+                                                                                                                                              exchange
                                                                                                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                                                -- DATASOURCE_SCAN (test.collection1)  |PARTITIONED|
+                                                                                                                                                data-scan []<-[$$441, $$435] <- test.collection1
+                                                                                                                                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                                                                                                  exchange
                                                                                                                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                                                                                                    empty-tuple-source
                                                                                                                                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                                                                                    exchange
                                                                                                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                                                                                      unnest $$194 <- scan-collection(array: [ "a", "b" ])
                                                                                                                       -- UNNEST  |UNPARTITIONED|
+                                                                                                                        empty-tuple-source
                                                                                                                         -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                                      exchange
                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                        unnest $$195 <- scan-collection(array: [ "a", "b" ])
                                                         -- UNNEST  |UNPARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                                              exchange
                                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                unnest $$196 <- scan-collection(array: [ 66, 67, 12, 13 ])
                                                 -- UNNEST  |UNPARTITIONED|
+                                                  empty-tuple-source
                                                   -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/query_issue849.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/query_issue849.plan
index 0f1879f..4734106 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/query_issue849.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/query_issue849.plan
@@ -1,29 +1,26 @@
--- COMMIT  |PARTITIONED|
-  -- STREAM_PROJECT  |PARTITIONED|
-    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-      -- INSERT_DELETE  |PARTITIONED|
-        -- HASH_PARTITION_EXCHANGE [$$3]  |PARTITIONED|
-          -- ASSIGN  |UNPARTITIONED|
-            -- ASSIGN  |UNPARTITIONED|
-              -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
--- COMMIT  |PARTITIONED|
-  -- STREAM_PROJECT  |PARTITIONED|
-    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-      -- INSERT_DELETE  |PARTITIONED|
-        -- HASH_PARTITION_EXCHANGE [$$3]  |PARTITIONED|
-          -- ASSIGN  |UNPARTITIONED|
-            -- ASSIGN  |UNPARTITIONED|
-              -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+distribute result [$$42]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$42])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$42] <- [{"x": $$x, "y": $$44}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$x, $$44])
         -- STREAM_PROJECT  |PARTITIONED|
+          exchange
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- BTREE_SEARCH (test.s.s)  |PARTITIONED|
+            unnest-map [$$44, $$z] <- index-search("s", 0, "test", "s", true, true, 1, $$52, 1, $$52, true, true, true)
+            -- BTREE_SEARCH  |PARTITIONED|
+              exchange
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                order (ASC, $$52)
                 -- STABLE_SORT [$$52(ASC)]  |PARTITIONED|
+                  exchange
                   -- HASH_PARTITION_EXCHANGE [$$52]  |PARTITIONED|
+                    assign [$$52] <- [cast-lax($$x.getField(0))]
                     -- ASSIGN  |UNPARTITIONED|
+                      unnest $$x <- scan-collection(multiset: {{ { "a": 1 }, { "a": 2 } }})
                       -- UNNEST  |UNPARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index-geometry/rtree-sidx-idxonly-01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index-geometry/rtree-sidx-idxonly-01.plan
index 7cd72c2..09f1c85 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index-geometry/rtree-sidx-idxonly-01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index-geometry/rtree-sidx-idxonly-01.plan
@@ -1,8 +1,16 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (st-intersects($$geo.getField(1), OGCPolygon: POLYGON ((1 1, 5 1, 5 5, 1 5, 1 1))))
       -- STREAM_SELECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (IndexGeoJSON.Geometries)  |PARTITIONED|
+          data-scan []<-[$$17, $$geo] <- IndexGeoJSON.Geometries
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index-geometry/rtree-sidx-idxonly-02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index-geometry/rtree-sidx-idxonly-02.plan
index 7cd72c2..afa948d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index-geometry/rtree-sidx-idxonly-02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index-geometry/rtree-sidx-idxonly-02.plan
@@ -1,8 +1,16 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (st-contains($$geo.getField(1), OGCPolygon: POLYGON ((1 1, 5 1, 5 5, 1 5, 1 1))))
       -- STREAM_SELECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (IndexGeoJSON.Geometries)  |PARTITIONED|
+          data-scan []<-[$$17, $$geo] <- IndexGeoJSON.Geometries
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index-geometry/rtree-sidx-idxonly-03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index-geometry/rtree-sidx-idxonly-03.plan
index 7cd72c2..bdcc72d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index-geometry/rtree-sidx-idxonly-03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index-geometry/rtree-sidx-idxonly-03.plan
@@ -1,8 +1,16 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (st-crosses($$geo.getField(1), OGCPolygon: POLYGON ((1 1, 5 1, 5 5, 1 5, 1 1))))
       -- STREAM_SELECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (IndexGeoJSON.Geometries)  |PARTITIONED|
+          data-scan []<-[$$17, $$geo] <- IndexGeoJSON.Geometries
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index-geometry/rtree-sidx-idxonly-04.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index-geometry/rtree-sidx-idxonly-04.plan
index 7cd72c2..de5d14e 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index-geometry/rtree-sidx-idxonly-04.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index-geometry/rtree-sidx-idxonly-04.plan
@@ -1,8 +1,16 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (st-overlaps($$geo.getField(1), OGCPolygon: POLYGON ((1 1, 5 1, 5 5, 1 5, 1 1))))
       -- STREAM_SELECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (IndexGeoJSON.Geometries)  |PARTITIONED|
+          data-scan []<-[$$17, $$geo] <- IndexGeoJSON.Geometries
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index-geometry/rtree-sidx-idxonly-05.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index-geometry/rtree-sidx-idxonly-05.plan
index 7cd72c2..9375213 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index-geometry/rtree-sidx-idxonly-05.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index-geometry/rtree-sidx-idxonly-05.plan
@@ -1,8 +1,16 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (st-touches($$geo.getField(1), OGCPolygon: POLYGON ((1 1, 5 1, 5 5, 1 5, 1 1))))
       -- STREAM_SELECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (IndexGeoJSON.Geometries)  |PARTITIONED|
+          data-scan []<-[$$17, $$geo] <- IndexGeoJSON.Geometries
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index-geometry/rtree-sidx-idxonly-06.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index-geometry/rtree-sidx-idxonly-06.plan
index 7cd72c2..6eec130 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index-geometry/rtree-sidx-idxonly-06.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index-geometry/rtree-sidx-idxonly-06.plan
@@ -1,8 +1,16 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (st-within($$geo.getField(1), OGCPolygon: POLYGON ((1 1, 5 1, 5 5, 1 5, 1 1))))
       -- STREAM_SELECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (IndexGeoJSON.Geometries)  |PARTITIONED|
+          data-scan []<-[$$17, $$geo] <- IndexGeoJSON.Geometries
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index-geometry/rtree-sidx-idxonly-07.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index-geometry/rtree-sidx-idxonly-07.plan
index 7cd72c2..50a9f95 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index-geometry/rtree-sidx-idxonly-07.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index-geometry/rtree-sidx-idxonly-07.plan
@@ -1,8 +1,16 @@
+distribute result [$$17]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$17])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (st-disjoint($$geo.getField(1), OGCPolygon: POLYGON ((1 1, 5 1, 5 5, 1 5, 1 1))))
       -- STREAM_SELECT  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- DATASOURCE_SCAN (IndexGeoJSON.Geometries)  |PARTITIONED|
+          data-scan []<-[$$17, $$geo] <- IndexGeoJSON.Geometries
+          -- DATASOURCE_SCAN  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              empty-tuple-source
               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index/rtree-sidx-idxonly-01-disable-idxonly.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index/rtree-sidx-idxonly-01-disable-idxonly.plan
index 5b57d41..585bd4d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index/rtree-sidx-idxonly-01-disable-idxonly.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index/rtree-sidx-idxonly-01-disable-idxonly.plan
@@ -1,13 +1,26 @@
+distribute result [$$50]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$50])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$50] <- [{"$1": $$53}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$53] <- [agg-sql-sum($$54)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$54] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (spatial-intersect($$x.getField(8), polygon: [ point: { x: 0.0, y: 0.0 }, point: { x: 2.0, y: 2.0 }, point: { x: 0.0, y: 2.0 }, point: { x: 2.0, y: 0.0 } ]))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$x])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- DATASOURCE_SCAN (test.Fragile_raw)  |PARTITIONED|
+                    data-scan []<-[$$52, $$x] <- test.Fragile_raw
+                    -- DATASOURCE_SCAN  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index/rtree-sidx-idxonly-01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index/rtree-sidx-idxonly-01.plan
index 5b57d41..585bd4d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index/rtree-sidx-idxonly-01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/rtree-index/rtree-sidx-idxonly-01.plan
@@ -1,13 +1,26 @@
+distribute result [$$50]
 -- DISTRIBUTE_RESULT  |UNPARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
+    project ([$$50])
     -- STREAM_PROJECT  |UNPARTITIONED|
+      assign [$$50] <- [{"$1": $$53}]
       -- ASSIGN  |UNPARTITIONED|
+        aggregate [$$53] <- [agg-sql-sum($$54)]
         -- AGGREGATE  |UNPARTITIONED|
+          exchange
           -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+            aggregate [$$54] <- [agg-sql-count(1)]
             -- AGGREGATE  |PARTITIONED|
+              select (spatial-intersect($$x.getField(8), polygon: [ point: { x: 0.0, y: 0.0 }, point: { x: 2.0, y: 2.0 }, point: { x: 0.0, y: 2.0 }, point: { x: 2.0, y: 0.0 } ]))
               -- STREAM_SELECT  |PARTITIONED|
+                project ([$$x])
                 -- STREAM_PROJECT  |PARTITIONED|
+                  exchange
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- DATASOURCE_SCAN (test.Fragile_raw)  |PARTITIONED|
+                    data-scan []<-[$$52, $$x] <- test.Fragile_raw
+                    -- DATASOURCE_SCAN  |PARTITIONED|
+                      exchange
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        empty-tuple-source
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/skip-index/skip-secondary-btree-index-2.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/skip-index/skip-secondary-btree-index-2.plan
index 124330a..d95595d 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/skip-index/skip-secondary-btree-index-2.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/skip-index/skip-secondary-btree-index-2.plan
@@ -1,10 +1,20 @@
+distribute result [$$emp]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$emp])
     -- STREAM_PROJECT  |PARTITIONED|
+      select (and(ge($$17, "Max"), le($$17, "Roger")))
       -- STREAM_SELECT  |PARTITIONED|
+        assign [$$17] <- [$$emp.getField(1)]
         -- ASSIGN  |PARTITIONED|
+          project ([$$emp])
           -- STREAM_PROJECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- DATASOURCE_SCAN (test.testdst)  |PARTITIONED|
+              data-scan []<-[$$18, $$emp] <- test.testdst
+              -- DATASOURCE_SCAN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  empty-tuple-source
                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/split-materialization.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/split-materialization.plan
index 34f5238..9cb7882 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/split-materialization.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/split-materialization.plan
@@ -1,20 +1,40 @@
+distribute result [$$86]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$86])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$86] <- [{"user1": {"id": $$91, "name": $$97}, "user2": {"id": $$92, "name": $$98}}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$91(ASC), $$92(ASC) ]  |PARTITIONED|
+          order (ASC, $$91) (ASC, $$92)
           -- STABLE_SORT [$$91(ASC), $$92(ASC)]  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              project ([$$91, $$97, $$92, $$98])
               -- STREAM_PROJECT  |PARTITIONED|
+                select (lt(count($$d.getField(4)), 2))
                 -- STREAM_SELECT  |PARTITIONED|
+                  assign [$$98] <- [$$d.getField(2)]
                   -- ASSIGN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- BTREE_SEARCH (TinySocial.FacebookUsers.FacebookUsers)  |PARTITIONED|
+                      unnest-map [$$92, $$d] <- index-search("FacebookUsers", 0, "TinySocial", "FacebookUsers", true, true, 1, $$91, 0, false, true, false)
+                      -- BTREE_SEARCH  |PARTITIONED|
+                        exchange
                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                          project ([$$91, $$97])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            select (lt(count($$d.getField(4)), 2))
                             -- STREAM_SELECT  |PARTITIONED|
+                              assign [$$97] <- [$$d.getField(2)]
                               -- ASSIGN  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- DATASOURCE_SCAN (TinySocial.FacebookUsers)  |PARTITIONED|
+                                  data-scan []<-[$$91, $$d] <- TinySocial.FacebookUsers
+                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      empty-tuple-source
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/split-materialization_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/split-materialization_ps.plan
index 2881c66..aa01402 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/split-materialization_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/split-materialization_ps.plan
@@ -1,45 +1,90 @@
+distribute result [$$86]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$86])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$86] <- [{"user1": {"id": $$91, "name": $$97}, "user2": {"id": $$92, "name": $$98}}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$91) (ASC, $$92)
           -- STABLE_SORT [$$91(ASC), $$92(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$91(ASC), $$92(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$104
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      project ([$$91, $$97, $$92, $$98])
                       -- STREAM_PROJECT  |PARTITIONED|
+                        select (lt(count($$d.getField(4)), 2))
                         -- STREAM_SELECT  |PARTITIONED|
+                          assign [$$98] <- [$$d.getField(2)]
                           -- ASSIGN  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- BTREE_SEARCH (TinySocial.FacebookUsers.FacebookUsers)  |PARTITIONED|
+                              unnest-map [$$92, $$d] <- index-search("FacebookUsers", 0, "TinySocial", "FacebookUsers", true, true, 1, $$91, 0, false, true, false)
+                              -- BTREE_SEARCH  |PARTITIONED|
+                                exchange
                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                  project ([$$91, $$97])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    select (lt(count($$d.getField(4)), 2))
                                     -- STREAM_SELECT  |PARTITIONED|
+                                      assign [$$97] <- [$$d.getField(2)]
                                       -- ASSIGN  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- DATASOURCE_SCAN (TinySocial.FacebookUsers)  |PARTITIONED|
+                                          data-scan []<-[$$91, $$d] <- TinySocial.FacebookUsers
+                                          -- DATASOURCE_SCAN  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              empty-tuple-source
                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$104] <- [agg-range-map($$101, $$102, $$103)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$101, $$102, $$103] <- [agg-local-sampling($$91, $$92), agg-null-writer($$91), agg-null-writer($$92)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$91, $$92])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                project ([$$91, $$97, $$92, $$98])
                                 -- STREAM_PROJECT  |PARTITIONED|
+                                  select (lt(count($$d.getField(4)), 2))
                                   -- STREAM_SELECT  |PARTITIONED|
+                                    assign [$$98] <- [$$d.getField(2)]
                                     -- ASSIGN  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- BTREE_SEARCH (TinySocial.FacebookUsers.FacebookUsers)  |PARTITIONED|
+                                        unnest-map [$$92, $$d] <- index-search("FacebookUsers", 0, "TinySocial", "FacebookUsers", true, true, 1, $$91, 0, false, true, false)
+                                        -- BTREE_SEARCH  |PARTITIONED|
+                                          exchange
                                           -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                            project ([$$91, $$97])
                                             -- STREAM_PROJECT  |PARTITIONED|
+                                              select (lt(count($$d.getField(4)), 2))
                                               -- STREAM_SELECT  |PARTITIONED|
+                                                assign [$$97] <- [$$d.getField(2)]
                                                 -- ASSIGN  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN (TinySocial.FacebookUsers)  |PARTITIONED|
+                                                    data-scan []<-[$$91, $$d] <- TinySocial.FacebookUsers
+                                                    -- DATASOURCE_SCAN  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        empty-tuple-source
                                                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/statement-params/statement-params-01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/statement-params/statement-params-01.plan
index 904a882..2e71ce0 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/statement-params/statement-params-01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/statement-params/statement-params-01.plan
@@ -1,10 +1,20 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"c_id": $$17}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$17])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$t.getField("c_s"), "hello"))
           -- STREAM_SELECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+              data-scan []<-[$$17, $$t] <- test.TestOpen
+              -- DATASOURCE_SCAN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  empty-tuple-source
                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/statement-params/statement-params-02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/statement-params/statement-params-02.plan
index 904a882..2e71ce0 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/statement-params/statement-params-02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/statement-params/statement-params-02.plan
@@ -1,10 +1,20 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"c_id": $$17}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$17])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$t.getField("c_s"), "hello"))
           -- STREAM_SELECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+              data-scan []<-[$$17, $$t] <- test.TestOpen
+              -- DATASOURCE_SCAN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  empty-tuple-source
                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/statement-params/statement-params-03.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/statement-params/statement-params-03.plan
index 904a882..2e71ce0 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/statement-params/statement-params-03.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/statement-params/statement-params-03.plan
@@ -1,10 +1,20 @@
+distribute result [$$16]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$16])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$16] <- [{"c_id": $$17}]
       -- ASSIGN  |PARTITIONED|
+        project ([$$17])
         -- STREAM_PROJECT  |PARTITIONED|
+          select (eq($$t.getField("c_s"), "hello"))
           -- STREAM_SELECT  |PARTITIONED|
+            exchange
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-              -- DATASOURCE_SCAN (test.TestOpen)  |PARTITIONED|
+              data-scan []<-[$$17, $$t] <- test.TestOpen
+              -- DATASOURCE_SCAN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  empty-tuple-source
                   -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/statement-params/statement-params-index-01.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/statement-params/statement-params-index-01.plan
index cecfb1c..224b14b 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/statement-params/statement-params-index-01.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/statement-params/statement-params-index-01.plan
@@ -1,12 +1,24 @@
+distribute result [$$26]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$26])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$26] <- [{"id": $$29, "fname": $$28, "lname": $$32, "age": $$33}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$29(ASC) ]  |PARTITIONED|
+          select (eq($$28, "Julio"))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$29, $$33, $$32, $$28])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$33, $$32, $$28] <- [$$l.getField(3), $$l.getField(2), $$l.getField(1)]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.employee)  |PARTITIONED|
+                  data-scan []<-[$$29, $$l] <- test.employee
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/statement-params/statement-params-index-02.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/statement-params/statement-params-index-02.plan
index cce5aaa..9b42f0a 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/statement-params/statement-params-index-02.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/statement-params/statement-params-index-02.plan
@@ -1,12 +1,24 @@
+distribute result [$$26]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$26])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$26] <- [{"id": $$30, "fname": $$28, "lname": $$29, "age": $$33}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$30(ASC) ]  |PARTITIONED|
+          select (and(eq($$29, "Isa"), eq($$28, "Julio")))
           -- STREAM_SELECT  |PARTITIONED|
+            project ([$$30, $$33, $$28, $$29])
             -- STREAM_PROJECT  |PARTITIONED|
+              assign [$$33, $$28, $$29] <- [$$l.getField(3), $$l.getField(1), $$l.getField(2)]
               -- ASSIGN  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- DATASOURCE_SCAN (test.employee)  |PARTITIONED|
+                  data-scan []<-[$$30, $$l] <- test.employee
+                  -- DATASOURCE_SCAN  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      empty-tuple-source
                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/tpcds/query-ASTERIXDB-1580.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/tpcds/query-ASTERIXDB-1580.plan
deleted file mode 100644
index eb98d7c..0000000
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/tpcds/query-ASTERIXDB-1580.plan
+++ /dev/null
@@ -1,73 +0,0 @@
--- DISTRIBUTE_RESULT  |UNPARTITIONED|
-  -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
-    -- STREAM_LIMIT  |UNPARTITIONED|
-      -- STREAM_PROJECT  |PARTITIONED|
-        -- ASSIGN  |PARTITIONED|
-          -- SORT_MERGE_EXCHANGE [$$136(ASC) ]  |PARTITIONED|
-            -- STREAM_LIMIT  |PARTITIONED|
-              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- STABLE_SORT [topK: 100] [$$136(ASC)]  |PARTITIONED|
-                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                    -- STREAM_PROJECT  |PARTITIONED|
-                      -- STREAM_SELECT  |PARTITIONED|
-                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- SORT_GROUP_BY[$$145]  |PARTITIONED|
-                                  {
-                                    -- AGGREGATE  |LOCAL|
-                                      -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                  }
-                            -- HASH_PARTITION_EXCHANGE [$$145]  |PARTITIONED|
-                              -- SORT_GROUP_BY[$$126]  |PARTITIONED|
-                                      {
-                                        -- AGGREGATE  |LOCAL|
-                                          -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                      }
-                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- STREAM_PROJECT  |PARTITIONED|
-                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- HYBRID_HASH_JOIN [$$129][$$132]  |PARTITIONED|
-                                        -- HASH_PARTITION_EXCHANGE [$$129]  |PARTITIONED|
-                                          -- STREAM_PROJECT  |PARTITIONED|
-                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- HYBRID_HASH_JOIN [$$137][$$131]  |PARTITIONED|
-                                                -- HASH_PARTITION_EXCHANGE [$$137]  |PARTITIONED|
-                                                  -- STREAM_PROJECT  |PARTITIONED|
-                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- HYBRID_HASH_JOIN [$$128][$$142]  |PARTITIONED|
-                                                        -- HASH_PARTITION_EXCHANGE [$$128]  |PARTITIONED|
-                                                          -- STREAM_PROJECT  |PARTITIONED|
-                                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                              -- HYBRID_HASH_JOIN [$$127][$$140]  |PARTITIONED|
-                                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- ASSIGN  |PARTITIONED|
-                                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- DATASOURCE_SCAN (tpcds.customer_address)  |PARTITIONED|
-                                                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                          -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                                -- HASH_PARTITION_EXCHANGE [$$140]  |PARTITIONED|
-                                                                  -- STREAM_PROJECT  |PARTITIONED|
-                                                                    -- ASSIGN  |PARTITIONED|
-                                                                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                        -- DATASOURCE_SCAN (tpcds.customer)  |PARTITIONED|
-                                                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                        -- HASH_PARTITION_EXCHANGE [$$142]  |PARTITIONED|
-                                                          -- STREAM_PROJECT  |PARTITIONED|
-                                                            -- ASSIGN  |PARTITIONED|
-                                                              -- STREAM_PROJECT  |PARTITIONED|
-                                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- DATASOURCE_SCAN (tpcds.store_sales)  |PARTITIONED|
-                                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- STREAM_PROJECT  |PARTITIONED|
-                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (tpcds.date_dim)  |PARTITIONED|
-                                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- STREAM_PROJECT  |PARTITIONED|
-                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- DATASOURCE_SCAN (tpcds.item)  |PARTITIONED|
-                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/tpcds/query-ASTERIXDB-1591.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/tpcds/query-ASTERIXDB-1591.plan
deleted file mode 100644
index d3fce85..0000000
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/tpcds/query-ASTERIXDB-1591.plan
+++ /dev/null
@@ -1,151 +0,0 @@
--- DISTRIBUTE_RESULT  |UNPARTITIONED|
-  -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
-    -- STREAM_LIMIT  |UNPARTITIONED|
-      -- STREAM_PROJECT  |PARTITIONED|
-        -- ASSIGN  |PARTITIONED|
-          -- STREAM_PROJECT  |PARTITIONED|
-            -- SORT_MERGE_EXCHANGE [$$192(ASC) ]  |PARTITIONED|
-              -- STREAM_LIMIT  |PARTITIONED|
-                -- STREAM_PROJECT  |PARTITIONED|
-                  -- STREAM_SELECT  |PARTITIONED|
-                    -- STREAM_PROJECT  |PARTITIONED|
-                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- SORT_GROUP_BY[$$201, $$202]  |PARTITIONED|
-                                {
-                                  -- AGGREGATE  |LOCAL|
-                                    -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                }
-                          -- HASH_PARTITION_EXCHANGE [$$201, $$202]  |PARTITIONED|
-                            -- PRE_CLUSTERED_GROUP_BY[$$189, $$190]  |PARTITIONED|
-                                    {
-                                      -- AGGREGATE  |LOCAL|
-                                        -- STREAM_SELECT  |LOCAL|
-                                          -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                    }
-                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- STABLE_SORT [$$189(ASC), $$190(ASC)]  |PARTITIONED|
-                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- STREAM_PROJECT  |PARTITIONED|
-                                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- HYBRID_HASH_JOIN [$$189][$$171]  |PARTITIONED|
-                                          -- HASH_PARTITION_EXCHANGE [$$189]  |PARTITIONED|
-                                            -- SORT_GROUP_BY[$$198, $$199]  |PARTITIONED|
-                                                    {
-                                                      -- AGGREGATE  |LOCAL|
-                                                        -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                    }
-                                              -- HASH_PARTITION_EXCHANGE [$$198, $$199]  |PARTITIONED|
-                                                -- PRE_CLUSTERED_GROUP_BY[$$186, $$187]  |PARTITIONED|
-                                                        {
-                                                          -- AGGREGATE  |LOCAL|
-                                                            -- STREAM_SELECT  |LOCAL|
-                                                              -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                        }
-                                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- STABLE_SORT [$$186(ASC), $$187(ASC)]  |PARTITIONED|
-                                                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- STREAM_PROJECT  |PARTITIONED|
-                                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- HYBRID_HASH_JOIN [$$186][$$169]  |PARTITIONED|
-                                                              -- HASH_PARTITION_EXCHANGE [$$186]  |PARTITIONED|
-                                                                -- STREAM_PROJECT  |PARTITIONED|
-                                                                  -- STREAM_SELECT  |PARTITIONED|
-                                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- SORT_GROUP_BY[$$195, $$196]  |PARTITIONED|
-                                                                              {
-                                                                                -- AGGREGATE  |LOCAL|
-                                                                                  -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                              }
-                                                                        -- HASH_PARTITION_EXCHANGE [$$195, $$196]  |PARTITIONED|
-                                                                          -- PRE_CLUSTERED_GROUP_BY[$$150, $$151]  |PARTITIONED|
-                                                                                  {
-                                                                                    -- AGGREGATE  |LOCAL|
-                                                                                      -- STREAM_SELECT  |LOCAL|
-                                                                                        -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                                                                  }
-                                                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                              -- STABLE_SORT [$$150(ASC), $$151(ASC)]  |PARTITIONED|
-                                                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                  -- STREAM_PROJECT  |PARTITIONED|
-                                                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                      -- HYBRID_HASH_JOIN [$$150][$$167]  |PARTITIONED|
-                                                                                        -- HASH_PARTITION_EXCHANGE [$$150]  |PARTITIONED|
-                                                                                          -- STREAM_PROJECT  |PARTITIONED|
-                                                                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                              -- HYBRID_HASH_JOIN [$$161][$$151]  |PARTITIONED|
-                                                                                                -- HASH_PARTITION_EXCHANGE [$$161]  |PARTITIONED|
-                                                                                                  -- ASSIGN  |PARTITIONED|
-                                                                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                      -- DATASOURCE_SCAN (tpcds.customer)  |PARTITIONED|
-                                                                                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                          -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                  -- DATASOURCE_SCAN (tpcds.customer_address)  |PARTITIONED|
-                                                                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                      -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                                                        -- HASH_PARTITION_EXCHANGE [$$167]  |PARTITIONED|
-                                                                                          -- ASSIGN  |PARTITIONED|
-                                                                                            -- STREAM_PROJECT  |PARTITIONED|
-                                                                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                -- HYBRID_HASH_JOIN [$$172][$$154]  |PARTITIONED|
-                                                                                                  -- HASH_PARTITION_EXCHANGE [$$172]  |PARTITIONED|
-                                                                                                    -- ASSIGN  |PARTITIONED|
-                                                                                                      -- STREAM_PROJECT  |PARTITIONED|
-                                                                                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                          -- DATASOURCE_SCAN (tpcds.store_sales)  |PARTITIONED|
-                                                                                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                                                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                    -- REPLICATE  |PARTITIONED|
-                                                                                                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                        -- STREAM_SELECT  |PARTITIONED|
-                                                                                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                            -- DATASOURCE_SCAN (tpcds.date_dim)  |PARTITIONED|
-                                                                                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                              -- HASH_PARTITION_EXCHANGE [$$169]  |PARTITIONED|
-                                                                -- ASSIGN  |PARTITIONED|
-                                                                  -- STREAM_PROJECT  |PARTITIONED|
-                                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- HYBRID_HASH_JOIN [$$174][$$157]  |PARTITIONED|
-                                                                        -- HASH_PARTITION_EXCHANGE [$$174]  |PARTITIONED|
-                                                                          -- ASSIGN  |PARTITIONED|
-                                                                            -- STREAM_PROJECT  |PARTITIONED|
-                                                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                -- DATASOURCE_SCAN (tpcds.web_sales)  |PARTITIONED|
-                                                                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                          -- STREAM_PROJECT  |PARTITIONED|
-                                                                            -- ASSIGN  |PARTITIONED|
-                                                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                -- REPLICATE  |PARTITIONED|
-                                                                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                    -- STREAM_SELECT  |PARTITIONED|
-                                                                                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                        -- DATASOURCE_SCAN (tpcds.date_dim)  |PARTITIONED|
-                                                                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                          -- HASH_PARTITION_EXCHANGE [$$171]  |PARTITIONED|
-                                            -- ASSIGN  |PARTITIONED|
-                                              -- STREAM_PROJECT  |PARTITIONED|
-                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- HYBRID_HASH_JOIN [$$176][$$160]  |PARTITIONED|
-                                                    -- HASH_PARTITION_EXCHANGE [$$176]  |PARTITIONED|
-                                                      -- ASSIGN  |PARTITIONED|
-                                                        -- STREAM_PROJECT  |PARTITIONED|
-                                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- DATASOURCE_SCAN (tpcds.catalog_sales)  |PARTITIONED|
-                                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- STREAM_PROJECT  |PARTITIONED|
-                                                        -- ASSIGN  |PARTITIONED|
-                                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- REPLICATE  |PARTITIONED|
-                                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                -- STREAM_SELECT  |PARTITIONED|
-                                                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                    -- DATASOURCE_SCAN (tpcds.date_dim)  |PARTITIONED|
-                                                                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/tpch/q12_broadcast.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/tpch/q12_broadcast.plan
deleted file mode 100644
index 4ad65b5..0000000
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/tpch/q12_broadcast.plan
+++ /dev/null
@@ -1,43 +0,0 @@
--- DISTRIBUTE_RESULT  |PARTITIONED|
-  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- STREAM_PROJECT  |PARTITIONED|
-      -- ASSIGN  |PARTITIONED|
-        -- SORT_MERGE_EXCHANGE [$$l_shipmode(ASC) ]  |PARTITIONED|
-          -- SORT_GROUP_BY[$$131]  |PARTITIONED|
-                  {
-                    -- AGGREGATE  |LOCAL|
-                      -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
-            -- HASH_PARTITION_EXCHANGE [$$131]  |PARTITIONED|
-              -- SORT_GROUP_BY[$$114]  |PARTITIONED|
-                      {
-                        -- AGGREGATE  |LOCAL|
-                          -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
-                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- STREAM_PROJECT  |PARTITIONED|
-                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- HYBRID_HASH_JOIN [$$118][$$121]  |PARTITIONED|
-                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- STREAM_PROJECT  |PARTITIONED|
-                            -- ASSIGN  |PARTITIONED|
-                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
-                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                    -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                        -- BROADCAST_EXCHANGE  |PARTITIONED|
-                          -- STREAM_PROJECT  |PARTITIONED|
-                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- HYBRID_HASH_JOIN [$$114][$$120]  |PARTITIONED|
-                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- STREAM_PROJECT  |PARTITIONED|
-                                    -- STREAM_SELECT  |PARTITIONED|
-                                      -- ASSIGN  |PARTITIONED|
-                                        -- STREAM_PROJECT  |PARTITIONED|
-                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
-                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                -- BROADCAST_EXCHANGE  |PARTITIONED|
-                                  -- UNNEST  |UNPARTITIONED|
-                                    -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/tpch/q12_broadcast_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/tpch/q12_broadcast_ps.plan
deleted file mode 100644
index 7bf4afa..0000000
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/tpch/q12_broadcast_ps.plan
+++ /dev/null
@@ -1,95 +0,0 @@
--- DISTRIBUTE_RESULT  |PARTITIONED|
-  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-    -- STREAM_PROJECT  |PARTITIONED|
-      -- ASSIGN  |PARTITIONED|
-        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- STABLE_SORT [$$l_shipmode(ASC)]  |PARTITIONED|
-            -- RANGE_PARTITION_EXCHANGE [$$l_shipmode(ASC)]  |PARTITIONED|
-              -- FORWARD  |PARTITIONED|
-                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- REPLICATE  |PARTITIONED|
-                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- SORT_GROUP_BY[$$131]  |PARTITIONED|
-                              {
-                                -- AGGREGATE  |LOCAL|
-                                  -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
-                        -- HASH_PARTITION_EXCHANGE [$$131]  |PARTITIONED|
-                          -- SORT_GROUP_BY[$$114]  |PARTITIONED|
-                                  {
-                                    -- AGGREGATE  |LOCAL|
-                                      -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                  }
-                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- STREAM_PROJECT  |PARTITIONED|
-                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- HYBRID_HASH_JOIN [$$118][$$121]  |PARTITIONED|
-                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- STREAM_PROJECT  |PARTITIONED|
-                                        -- ASSIGN  |PARTITIONED|
-                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
-                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                    -- BROADCAST_EXCHANGE  |PARTITIONED|
-                                      -- STREAM_PROJECT  |PARTITIONED|
-                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- HYBRID_HASH_JOIN [$$114][$$120]  |PARTITIONED|
-                                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                              -- STREAM_PROJECT  |PARTITIONED|
-                                                -- STREAM_SELECT  |PARTITIONED|
-                                                  -- ASSIGN  |PARTITIONED|
-                                                    -- STREAM_PROJECT  |PARTITIONED|
-                                                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
-                                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                            -- BROADCAST_EXCHANGE  |PARTITIONED|
-                                              -- UNNEST  |UNPARTITIONED|
-                                                -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
-                -- BROADCAST_EXCHANGE  |PARTITIONED|
-                  -- AGGREGATE  |UNPARTITIONED|
-                    -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
-                      -- AGGREGATE  |PARTITIONED|
-                        -- STREAM_PROJECT  |PARTITIONED|
-                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                            -- REPLICATE  |PARTITIONED|
-                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- SORT_GROUP_BY[$$131]  |PARTITIONED|
-                                        {
-                                          -- AGGREGATE  |LOCAL|
-                                            -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
-                                  -- HASH_PARTITION_EXCHANGE [$$131]  |PARTITIONED|
-                                    -- SORT_GROUP_BY[$$114]  |PARTITIONED|
-                                            {
-                                              -- AGGREGATE  |LOCAL|
-                                                -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                            }
-                                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- STREAM_PROJECT  |PARTITIONED|
-                                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- HYBRID_HASH_JOIN [$$118][$$121]  |PARTITIONED|
-                                              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- STREAM_PROJECT  |PARTITIONED|
-                                                  -- ASSIGN  |PARTITIONED|
-                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
-                                                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                          -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                              -- BROADCAST_EXCHANGE  |PARTITIONED|
-                                                -- STREAM_PROJECT  |PARTITIONED|
-                                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- HYBRID_HASH_JOIN [$$114][$$120]  |PARTITIONED|
-                                                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- STREAM_PROJECT  |PARTITIONED|
-                                                          -- STREAM_SELECT  |PARTITIONED|
-                                                            -- ASSIGN  |PARTITIONED|
-                                                              -- STREAM_PROJECT  |PARTITIONED|
-                                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
-                                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                      -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                      -- BROADCAST_EXCHANGE  |PARTITIONED|
-                                                        -- UNNEST  |UNPARTITIONED|
-                                                          -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/tpch/q12_shipping.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/tpch/q12_shipping.plan
index 7609856..9626075 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/tpch/q12_shipping.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/tpch/q12_shipping.plan
@@ -1,43 +1,80 @@
+distribute result [$$112]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$112])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$112] <- [{"l_shipmode": $$l_shipmode, "high_line_count": $$123, "low_line_count": $$124}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$l_shipmode(ASC) ]  |PARTITIONED|
-          -- SORT_GROUP_BY[$$131]  |PARTITIONED|
-                  {
+          group by ([$$l_shipmode := $$131]) decor ([]) {
+                    aggregate [$$123, $$124] <- [agg-global-sql-sum($$129), agg-global-sql-sum($$130)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- SORT_GROUP_BY[$$131]  |PARTITIONED|
+            exchange
             -- HASH_PARTITION_EXCHANGE [$$131]  |PARTITIONED|
-              -- SORT_GROUP_BY[$$114]  |PARTITIONED|
-                      {
+              group by ([$$131 := $$114]) decor ([]) {
+                        aggregate [$$129, $$130] <- [agg-local-sql-sum(switch-case(true, or(eq($$119, "1-URGENT"), eq($$119, "2-HIGH")), numeric-add(1, numeric-multiply($$119, 0)), numeric-add(0, numeric-multiply($$119, 0)))), agg-local-sql-sum(switch-case(true, eq(true, or(eq($$119, "1-URGENT"), eq($$119, "2-HIGH"))), numeric-add(0, numeric-multiply($$119, 0)), numeric-add(1, numeric-multiply($$119, 0))))]
                         -- AGGREGATE  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SORT_GROUP_BY[$$114]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$119, $$114])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (eq($$118, $$122))
                       -- HYBRID_HASH_JOIN [$$118][$$122]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$119, $$118])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$119] <- [$$o.getField("o_orderpriority")]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                                data-scan []<-[$$118, $$o] <- tpch.Orders
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                          project ([$$114, $$122])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              join (eq($$120, $$114))
                               -- HYBRID_HASH_JOIN [$$114][$$120]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$114, $$122])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    select (and(lt($$116, $$115), ge($$115, "1994-01-01"), lt($$115, "1995-01-01"), lt($$l.getField("l_shipdate"), $$116)))
                                     -- STREAM_SELECT  |PARTITIONED|
+                                      assign [$$116, $$115, $$114, $$122] <- [$$l.getField("l_commitdate"), $$l.getField("l_receiptdate"), $$l.getField("l_shipmode"), $$l.getField("l_orderkey")]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$l])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
+                                            data-scan []<-[$$117, $$l] <- tpch.LineItem
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                exchange
                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                  unnest $$120 <- scan-collection(array: [ "MAIL", "SHIP" ])
                                   -- UNNEST  |UNPARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/tpch/q12_shipping_broadcast.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/tpch/q12_shipping_broadcast.plan
index 4ad65b5..0e52984 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/tpch/q12_shipping_broadcast.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/tpch/q12_shipping_broadcast.plan
@@ -1,43 +1,80 @@
+distribute result [$$112]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$112])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$112] <- [{"l_shipmode": $$l_shipmode, "high_line_count": $$123, "low_line_count": $$124}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- SORT_MERGE_EXCHANGE [$$l_shipmode(ASC) ]  |PARTITIONED|
-          -- SORT_GROUP_BY[$$131]  |PARTITIONED|
-                  {
+          group by ([$$l_shipmode := $$131]) decor ([]) {
+                    aggregate [$$123, $$124] <- [agg-global-sql-sum($$129), agg-global-sql-sum($$130)]
                     -- AGGREGATE  |LOCAL|
+                      nested tuple source
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                  }
+                 }
+          -- SORT_GROUP_BY[$$131]  |PARTITIONED|
+            exchange
             -- HASH_PARTITION_EXCHANGE [$$131]  |PARTITIONED|
-              -- SORT_GROUP_BY[$$114]  |PARTITIONED|
-                      {
+              group by ([$$131 := $$114]) decor ([]) {
+                        aggregate [$$129, $$130] <- [agg-local-sql-sum(switch-case(true, or(eq($$119, "1-URGENT"), eq($$119, "2-HIGH")), numeric-add(1, numeric-multiply($$119, 0)), numeric-add(0, numeric-multiply($$119, 0)))), agg-local-sql-sum(switch-case(true, eq(true, or(eq($$119, "1-URGENT"), eq($$119, "2-HIGH"))), numeric-add(0, numeric-multiply($$119, 0)), numeric-add(1, numeric-multiply($$119, 0))))]
                         -- AGGREGATE  |LOCAL|
+                          nested tuple source
                           -- NESTED_TUPLE_SOURCE  |LOCAL|
-                      }
+                     }
+              -- SORT_GROUP_BY[$$114]  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  project ([$$119, $$114])
                   -- STREAM_PROJECT  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      join (eq($$121, $$118))
                       -- HYBRID_HASH_JOIN [$$118][$$121]  |PARTITIONED|
+                        exchange
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                          project ([$$119, $$118])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            assign [$$119] <- [$$o.getField("o_orderpriority")]
                             -- ASSIGN  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                                data-scan []<-[$$118, $$o] <- tpch.Orders
+                                -- DATASOURCE_SCAN  |PARTITIONED|
+                                  exchange
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                        exchange
                         -- BROADCAST_EXCHANGE  |PARTITIONED|
+                          project ([$$114, $$121])
                           -- STREAM_PROJECT  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              join (eq($$120, $$114))
                               -- HYBRID_HASH_JOIN [$$114][$$120]  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  project ([$$114, $$121])
                                   -- STREAM_PROJECT  |PARTITIONED|
+                                    select (and(lt($$116, $$115), ge($$115, "1994-01-01"), lt($$115, "1995-01-01"), lt($$l.getField("l_shipdate"), $$116)))
                                     -- STREAM_SELECT  |PARTITIONED|
+                                      assign [$$116, $$115, $$114, $$121] <- [$$l.getField("l_commitdate"), $$l.getField("l_receiptdate"), $$l.getField("l_shipmode"), $$l.getField("l_orderkey")]
                                       -- ASSIGN  |PARTITIONED|
+                                        project ([$$l])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
+                                            data-scan []<-[$$117, $$l] <- tpch.LineItem
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                exchange
                                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                  unnest $$120 <- scan-collection(array: [ "MAIL", "SHIP" ])
                                   -- UNNEST  |UNPARTITIONED|
+                                    empty-tuple-source
                                     -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/tpch/q12_shipping_broadcast_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/tpch/q12_shipping_broadcast_ps.plan
index 7bf4afa..416d701 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/tpch/q12_shipping_broadcast_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/tpch/q12_shipping_broadcast_ps.plan
@@ -1,95 +1,178 @@
+distribute result [$$112]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$112])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$112] <- [{"l_shipmode": $$l_shipmode, "high_line_count": $$123, "low_line_count": $$124}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$l_shipmode)
           -- STABLE_SORT [$$l_shipmode(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$l_shipmode(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$134
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- SORT_GROUP_BY[$$131]  |PARTITIONED|
-                              {
+                      group by ([$$l_shipmode := $$131]) decor ([]) {
+                                aggregate [$$123, $$124] <- [agg-global-sql-sum($$129), agg-global-sql-sum($$130)]
                                 -- AGGREGATE  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- SORT_GROUP_BY[$$131]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$131]  |PARTITIONED|
-                          -- SORT_GROUP_BY[$$114]  |PARTITIONED|
-                                  {
+                          group by ([$$131 := $$114]) decor ([]) {
+                                    aggregate [$$129, $$130] <- [agg-local-sql-sum(switch-case(true, or(eq($$119, "1-URGENT"), eq($$119, "2-HIGH")), numeric-add(1, numeric-multiply($$119, 0)), numeric-add(0, numeric-multiply($$119, 0)))), agg-local-sql-sum(switch-case(true, eq(true, or(eq($$119, "1-URGENT"), eq($$119, "2-HIGH"))), numeric-add(0, numeric-multiply($$119, 0)), numeric-add(1, numeric-multiply($$119, 0))))]
                                     -- AGGREGATE  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                  }
+                                 }
+                          -- SORT_GROUP_BY[$$114]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$119, $$114])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  join (eq($$121, $$118))
                                   -- HYBRID_HASH_JOIN [$$118][$$121]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$119, $$118])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$119] <- [$$o.getField("o_orderpriority")]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                                            data-scan []<-[$$118, $$o] <- tpch.Orders
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                      project ([$$114, $$121])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          join (eq($$120, $$114))
                                           -- HYBRID_HASH_JOIN [$$114][$$120]  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$114, $$121])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                select (and(lt($$116, $$115), ge($$115, "1994-01-01"), lt($$115, "1995-01-01"), lt($$l.getField("l_shipdate"), $$116)))
                                                 -- STREAM_SELECT  |PARTITIONED|
+                                                  assign [$$116, $$115, $$114, $$121] <- [$$l.getField("l_commitdate"), $$l.getField("l_receiptdate"), $$l.getField("l_shipmode"), $$l.getField("l_orderkey")]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$l])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
+                                                        data-scan []<-[$$117, $$l] <- tpch.LineItem
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                            exchange
                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                              unnest $$120 <- scan-collection(array: [ "MAIL", "SHIP" ])
                                               -- UNNEST  |UNPARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$134] <- [agg-range-map($$132, $$133)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$132, $$133] <- [agg-local-sampling($$l_shipmode), agg-null-writer($$l_shipmode)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$l_shipmode])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- SORT_GROUP_BY[$$131]  |PARTITIONED|
-                                        {
+                                group by ([$$l_shipmode := $$131]) decor ([]) {
+                                          aggregate [$$123, $$124] <- [agg-global-sql-sum($$129), agg-global-sql-sum($$130)]
                                           -- AGGREGATE  |LOCAL|
+                                            nested tuple source
                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- SORT_GROUP_BY[$$131]  |PARTITIONED|
+                                  exchange
                                   -- HASH_PARTITION_EXCHANGE [$$131]  |PARTITIONED|
-                                    -- SORT_GROUP_BY[$$114]  |PARTITIONED|
-                                            {
+                                    group by ([$$131 := $$114]) decor ([]) {
+                                              aggregate [$$129, $$130] <- [agg-local-sql-sum(switch-case(true, or(eq($$119, "1-URGENT"), eq($$119, "2-HIGH")), numeric-add(1, numeric-multiply($$119, 0)), numeric-add(0, numeric-multiply($$119, 0)))), agg-local-sql-sum(switch-case(true, eq(true, or(eq($$119, "1-URGENT"), eq($$119, "2-HIGH"))), numeric-add(0, numeric-multiply($$119, 0)), numeric-add(1, numeric-multiply($$119, 0))))]
                                               -- AGGREGATE  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                            }
+                                           }
+                                    -- SORT_GROUP_BY[$$114]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$119, $$114])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            join (eq($$121, $$118))
                                             -- HYBRID_HASH_JOIN [$$118][$$121]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$119, $$118])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$119] <- [$$o.getField("o_orderpriority")]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                                                      data-scan []<-[$$118, $$o] <- tpch.Orders
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                              exchange
                                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                project ([$$114, $$121])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    join (eq($$120, $$114))
                                                     -- HYBRID_HASH_JOIN [$$114][$$120]  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        project ([$$114, $$121])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          select (and(lt($$116, $$115), ge($$115, "1994-01-01"), lt($$115, "1995-01-01"), lt($$l.getField("l_shipdate"), $$116)))
                                                           -- STREAM_SELECT  |PARTITIONED|
+                                                            assign [$$116, $$115, $$114, $$121] <- [$$l.getField("l_commitdate"), $$l.getField("l_receiptdate"), $$l.getField("l_shipmode"), $$l.getField("l_orderkey")]
                                                             -- ASSIGN  |PARTITIONED|
+                                                              project ([$$l])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
+                                                                  data-scan []<-[$$117, $$l] <- tpch.LineItem
+                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      empty-tuple-source
                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                      exchange
                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                        unnest $$120 <- scan-collection(array: [ "MAIL", "SHIP" ])
                                                         -- UNNEST  |UNPARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
diff --git a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/tpch/q12_shipping_ps.plan b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/tpch/q12_shipping_ps.plan
index f21d402..6dad1b8 100644
--- a/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/tpch/q12_shipping_ps.plan
+++ b/asterixdb/asterix-app/src/test/resources/optimizerts/results_cbo/tpch/q12_shipping_ps.plan
@@ -1,95 +1,178 @@
+distribute result [$$112]
 -- DISTRIBUTE_RESULT  |PARTITIONED|
+  exchange
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+    project ([$$112])
     -- STREAM_PROJECT  |PARTITIONED|
+      assign [$$112] <- [{"l_shipmode": $$l_shipmode, "high_line_count": $$123, "low_line_count": $$124}]
       -- ASSIGN  |PARTITIONED|
+        exchange
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          order (ASC, $$l_shipmode)
           -- STABLE_SORT [$$l_shipmode(ASC)]  |PARTITIONED|
+            exchange
             -- RANGE_PARTITION_EXCHANGE [$$l_shipmode(ASC)]  |PARTITIONED|
+              forward: shared-variable = $$134
               -- FORWARD  |PARTITIONED|
+                exchange
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                  replicate
                   -- REPLICATE  |PARTITIONED|
+                    exchange
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- SORT_GROUP_BY[$$131]  |PARTITIONED|
-                              {
+                      group by ([$$l_shipmode := $$131]) decor ([]) {
+                                aggregate [$$123, $$124] <- [agg-global-sql-sum($$129), agg-global-sql-sum($$130)]
                                 -- AGGREGATE  |LOCAL|
+                                  nested tuple source
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
-                              }
+                             }
+                      -- SORT_GROUP_BY[$$131]  |PARTITIONED|
+                        exchange
                         -- HASH_PARTITION_EXCHANGE [$$131]  |PARTITIONED|
-                          -- SORT_GROUP_BY[$$114]  |PARTITIONED|
-                                  {
+                          group by ([$$131 := $$114]) decor ([]) {
+                                    aggregate [$$129, $$130] <- [agg-local-sql-sum(switch-case(true, or(eq($$119, "1-URGENT"), eq($$119, "2-HIGH")), numeric-add(1, numeric-multiply($$119, 0)), numeric-add(0, numeric-multiply($$119, 0)))), agg-local-sql-sum(switch-case(true, eq(true, or(eq($$119, "1-URGENT"), eq($$119, "2-HIGH"))), numeric-add(0, numeric-multiply($$119, 0)), numeric-add(1, numeric-multiply($$119, 0))))]
                                     -- AGGREGATE  |LOCAL|
+                                      nested tuple source
                                       -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                  }
+                                 }
+                          -- SORT_GROUP_BY[$$114]  |PARTITIONED|
+                            exchange
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                              project ([$$119, $$114])
                               -- STREAM_PROJECT  |PARTITIONED|
+                                exchange
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                  join (eq($$118, $$122))
                                   -- HYBRID_HASH_JOIN [$$118][$$122]  |PARTITIONED|
+                                    exchange
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                      project ([$$119, $$118])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        assign [$$119] <- [$$o.getField("o_orderpriority")]
                                         -- ASSIGN  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                            -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                                            data-scan []<-[$$118, $$o] <- tpch.Orders
+                                            -- DATASOURCE_SCAN  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                    exchange
                                     -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                      project ([$$114, $$122])
                                       -- STREAM_PROJECT  |PARTITIONED|
+                                        exchange
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                          join (eq($$120, $$114))
                                           -- HYBRID_HASH_JOIN [$$114][$$120]  |PARTITIONED|
+                                            exchange
                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                              project ([$$114, $$122])
                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                select (and(lt($$116, $$115), ge($$115, "1994-01-01"), lt($$115, "1995-01-01"), lt($$l.getField("l_shipdate"), $$116)))
                                                 -- STREAM_SELECT  |PARTITIONED|
+                                                  assign [$$116, $$115, $$114, $$122] <- [$$l.getField("l_commitdate"), $$l.getField("l_receiptdate"), $$l.getField("l_shipmode"), $$l.getField("l_orderkey")]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    project ([$$l])
                                                     -- STREAM_PROJECT  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
+                                                        data-scan []<-[$$117, $$l] <- tpch.LineItem
+                                                        -- DATASOURCE_SCAN  |PARTITIONED|
+                                                          exchange
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                            empty-tuple-source
                                                             -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                            exchange
                                             -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                              unnest $$120 <- scan-collection(array: [ "MAIL", "SHIP" ])
                                               -- UNNEST  |UNPARTITIONED|
+                                                empty-tuple-source
                                                 -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|
+                exchange
                 -- BROADCAST_EXCHANGE  |PARTITIONED|
+                  aggregate [$$134] <- [agg-range-map($$132, $$133)]
                   -- AGGREGATE  |UNPARTITIONED|
+                    exchange
                     -- RANDOM_MERGE_EXCHANGE  |PARTITIONED|
+                      aggregate [$$132, $$133] <- [agg-local-sampling($$l_shipmode), agg-null-writer($$l_shipmode)]
                       -- AGGREGATE  |PARTITIONED|
+                        project ([$$l_shipmode])
                         -- STREAM_PROJECT  |PARTITIONED|
+                          exchange
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            replicate
                             -- REPLICATE  |PARTITIONED|
+                              exchange
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- SORT_GROUP_BY[$$131]  |PARTITIONED|
-                                        {
+                                group by ([$$l_shipmode := $$131]) decor ([]) {
+                                          aggregate [$$123, $$124] <- [agg-global-sql-sum($$129), agg-global-sql-sum($$130)]
                                           -- AGGREGATE  |LOCAL|
+                                            nested tuple source
                                             -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                        }
+                                       }
+                                -- SORT_GROUP_BY[$$131]  |PARTITIONED|
+                                  exchange
                                   -- HASH_PARTITION_EXCHANGE [$$131]  |PARTITIONED|
-                                    -- SORT_GROUP_BY[$$114]  |PARTITIONED|
-                                            {
+                                    group by ([$$131 := $$114]) decor ([]) {
+                                              aggregate [$$129, $$130] <- [agg-local-sql-sum(switch-case(true, or(eq($$119, "1-URGENT"), eq($$119, "2-HIGH")), numeric-add(1, numeric-multiply($$119, 0)), numeric-add(0, numeric-multiply($$119, 0)))), agg-local-sql-sum(switch-case(true, eq(true, or(eq($$119, "1-URGENT"), eq($$119, "2-HIGH"))), numeric-add(0, numeric-multiply($$119, 0)), numeric-add(1, numeric-multiply($$119, 0))))]
                                               -- AGGREGATE  |LOCAL|
+                                                nested tuple source
                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
-                                            }
+                                           }
+                                    -- SORT_GROUP_BY[$$114]  |PARTITIONED|
+                                      exchange
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                        project ([$$119, $$114])
                                         -- STREAM_PROJECT  |PARTITIONED|
+                                          exchange
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                            join (eq($$118, $$122))
                                             -- HYBRID_HASH_JOIN [$$118][$$122]  |PARTITIONED|
+                                              exchange
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                project ([$$119, $$118])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  assign [$$119] <- [$$o.getField("o_orderpriority")]
                                                   -- ASSIGN  |PARTITIONED|
+                                                    exchange
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                      -- DATASOURCE_SCAN (tpch.Orders)  |PARTITIONED|
+                                                      data-scan []<-[$$118, $$o] <- tpch.Orders
+                                                      -- DATASOURCE_SCAN  |PARTITIONED|
+                                                        exchange
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                              exchange
                                               -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                project ([$$114, $$122])
                                                 -- STREAM_PROJECT  |PARTITIONED|
+                                                  exchange
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                    join (eq($$120, $$114))
                                                     -- HYBRID_HASH_JOIN [$$114][$$120]  |PARTITIONED|
+                                                      exchange
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                        project ([$$114, $$122])
                                                         -- STREAM_PROJECT  |PARTITIONED|
+                                                          select (and(lt($$116, $$115), ge($$115, "1994-01-01"), lt($$115, "1995-01-01"), lt($$l.getField("l_shipdate"), $$116)))
                                                           -- STREAM_SELECT  |PARTITIONED|
+                                                            assign [$$116, $$115, $$114, $$122] <- [$$l.getField("l_commitdate"), $$l.getField("l_receiptdate"), $$l.getField("l_shipmode"), $$l.getField("l_orderkey")]
                                                             -- ASSIGN  |PARTITIONED|
+                                                              project ([$$l])
                                                               -- STREAM_PROJECT  |PARTITIONED|
+                                                                exchange
                                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                                  -- DATASOURCE_SCAN (tpch.LineItem)  |PARTITIONED|
+                                                                  data-scan []<-[$$117, $$l] <- tpch.LineItem
+                                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                                    exchange
                                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                                      empty-tuple-source
                                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                                      exchange
                                                       -- BROADCAST_EXCHANGE  |PARTITIONED|
+                                                        unnest $$120 <- scan-collection(array: [ "MAIL", "SHIP" ])
                                                         -- UNNEST  |UNPARTITIONED|
+                                                          empty-tuple-source
                                                           -- EMPTY_TUPLE_SOURCE  |UNPARTITIONED|