Fixed a bug in the access method rewrite rule. Added common subexpression elimination rule to normalization rule collection. Changed expected plans of optimizer tests accordingly (some plans were improved, most had variable numbers changed).

git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_inline_vars@795 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-45.plan b/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-45.plan
index 107ed56..22b26c4 100644
--- a/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-45.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-45.plan
@@ -4,7 +4,7 @@
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
         -- BTREE_SEARCH  |PARTITIONED|
           -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-            -- STABLE_SORT [$$22(ASC)]  |LOCAL|
+            -- STABLE_SORT [$$20(ASC)]  |LOCAL|
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                 -- STREAM_PROJECT  |PARTITIONED|
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-46.plan b/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-46.plan
index 107ed56..22b26c4 100644
--- a/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-46.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-46.plan
@@ -4,7 +4,7 @@
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
         -- BTREE_SEARCH  |PARTITIONED|
           -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-            -- STABLE_SORT [$$22(ASC)]  |LOCAL|
+            -- STABLE_SORT [$$20(ASC)]  |LOCAL|
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                 -- STREAM_PROJECT  |PARTITIONED|
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-49.plan b/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-49.plan
index 107ed56..22b26c4 100644
--- a/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-49.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-49.plan
@@ -4,7 +4,7 @@
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
         -- BTREE_SEARCH  |PARTITIONED|
           -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-            -- STABLE_SORT [$$22(ASC)]  |LOCAL|
+            -- STABLE_SORT [$$20(ASC)]  |LOCAL|
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                 -- STREAM_PROJECT  |PARTITIONED|
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-50.plan b/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-50.plan
index 107ed56..22b26c4 100644
--- a/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-50.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-50.plan
@@ -4,7 +4,7 @@
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
         -- BTREE_SEARCH  |PARTITIONED|
           -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-            -- STABLE_SORT [$$22(ASC)]  |LOCAL|
+            -- STABLE_SORT [$$20(ASC)]  |LOCAL|
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                 -- STREAM_PROJECT  |PARTITIONED|
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-51.plan b/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-51.plan
index 107ed56..22b26c4 100644
--- a/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-51.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-51.plan
@@ -4,7 +4,7 @@
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
         -- BTREE_SEARCH  |PARTITIONED|
           -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-            -- STABLE_SORT [$$22(ASC)]  |LOCAL|
+            -- STABLE_SORT [$$20(ASC)]  |LOCAL|
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                 -- STREAM_PROJECT  |PARTITIONED|
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-56.plan b/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-56.plan
index cb0d369..4f9f4ba 100644
--- a/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-56.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-56.plan
@@ -4,7 +4,7 @@
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
         -- BTREE_SEARCH  |PARTITIONED|
           -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-            -- STABLE_SORT [$$13(ASC)]  |LOCAL|
+            -- STABLE_SORT [$$12(ASC)]  |LOCAL|
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                 -- STREAM_PROJECT  |PARTITIONED|
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-57.plan b/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-57.plan
index cb0d369..4f9f4ba 100644
--- a/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-57.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/btree-index/btree-secondary-57.plan
@@ -4,7 +4,7 @@
       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
         -- BTREE_SEARCH  |PARTITIONED|
           -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-            -- STABLE_SORT [$$13(ASC)]  |LOCAL|
+            -- STABLE_SORT [$$12(ASC)]  |LOCAL|
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                 -- STREAM_PROJECT  |PARTITIONED|
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/denorm-cust-order.plan b/asterix-app/src/test/resources/optimizerts/results/denorm-cust-order.plan
index 347a895..c48c00c 100644
--- a/asterix-app/src/test/resources/optimizerts/results/denorm-cust-order.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/denorm-cust-order.plan
@@ -3,17 +3,17 @@
     -- STREAM_PROJECT  |PARTITIONED|
       -- ASSIGN  |PARTITIONED|
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- PRE_CLUSTERED_GROUP_BY[$$15]  |PARTITIONED|
+          -- PRE_CLUSTERED_GROUP_BY[$$16]  |PARTITIONED|
                   {
                     -- AGGREGATE  |LOCAL|
                       -- NESTED_TUPLE_SOURCE  |LOCAL|
                   }
             -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-              -- STABLE_SORT [$$15(ASC)]  |LOCAL|
+              -- STABLE_SORT [$$16(ASC)]  |LOCAL|
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                   -- STREAM_PROJECT  |PARTITIONED|
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                      -- HYBRID_HASH_JOIN [$$15][$$19]  |PARTITIONED|
+                      -- HYBRID_HASH_JOIN [$$16][$$19]  |PARTITIONED|
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                           -- DATASOURCE_SCAN  |PARTITIONED|
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/inlined_q18_large_volume_customer.plan b/asterix-app/src/test/resources/optimizerts/results/inlined_q18_large_volume_customer.plan
index 81b10a9..47986a9 100644
--- a/asterix-app/src/test/resources/optimizerts/results/inlined_q18_large_volume_customer.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/inlined_q18_large_volume_customer.plan
@@ -7,31 +7,31 @@
             -- ONE_TO_ONE_EXCHANGE  |LOCAL|
               -- STABLE_SORT [$$12(DESC), $$11(ASC)]  |LOCAL|
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                  -- PRE_CLUSTERED_GROUP_BY[$$73, $$74]  |PARTITIONED|
+                  -- PRE_CLUSTERED_GROUP_BY[$$72, $$73]  |PARTITIONED|
                           {
                             -- AGGREGATE  |LOCAL|
                               -- NESTED_TUPLE_SOURCE  |LOCAL|
                           }
-                    -- HASH_PARTITION_MERGE_EXCHANGE MERGE:[$$73(ASC), $$74(ASC)] HASH:[$$73, $$74]  |PARTITIONED|
-                      -- PRE_CLUSTERED_GROUP_BY[$$54, $$55]  |LOCAL|
+                    -- HASH_PARTITION_MERGE_EXCHANGE MERGE:[$$72(ASC), $$73(ASC)] HASH:[$$72, $$73]  |PARTITIONED|
+                      -- PRE_CLUSTERED_GROUP_BY[$$56, $$57]  |LOCAL|
                               {
                                 -- AGGREGATE  |LOCAL|
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
                               }
                         -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-                          -- STABLE_SORT [$$54(ASC), $$55(ASC)]  |LOCAL|
+                          -- STABLE_SORT [$$56(ASC), $$57(ASC)]  |LOCAL|
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                               -- STREAM_PROJECT  |PARTITIONED|
                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                  -- HYBRID_HASH_JOIN [$$55][$$58]  |PARTITIONED|
+                                  -- HYBRID_HASH_JOIN [$$57][$$60]  |PARTITIONED|
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                       -- STREAM_PROJECT  |PARTITIONED|
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                          -- HYBRID_HASH_JOIN [$$55][$$4]  |PARTITIONED|
-                                            -- HASH_PARTITION_EXCHANGE [$$55]  |PARTITIONED|
+                                          -- HYBRID_HASH_JOIN [$$57][$$4]  |PARTITIONED|
+                                            -- HASH_PARTITION_EXCHANGE [$$57]  |PARTITIONED|
                                               -- STREAM_PROJECT  |PARTITIONED|
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                  -- HYBRID_HASH_JOIN [$$54][$$63]  |PARTITIONED|
+                                                  -- HYBRID_HASH_JOIN [$$56][$$64]  |PARTITIONED|
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                       -- STREAM_PROJECT  |PARTITIONED|
                                                         -- ASSIGN  |PARTITIONED|
@@ -39,7 +39,7 @@
                                                             -- DATASOURCE_SCAN  |PARTITIONED|
                                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                    -- HASH_PARTITION_EXCHANGE [$$63]  |PARTITIONED|
+                                                    -- HASH_PARTITION_EXCHANGE [$$64]  |PARTITIONED|
                                                       -- STREAM_PROJECT  |PARTITIONED|
                                                         -- ASSIGN  |PARTITIONED|
                                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
@@ -50,13 +50,13 @@
                                               -- STREAM_PROJECT  |PARTITIONED|
                                                 -- STREAM_SELECT  |PARTITIONED|
                                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- PRE_CLUSTERED_GROUP_BY[$$70]  |PARTITIONED|
+                                                    -- PRE_CLUSTERED_GROUP_BY[$$69]  |PARTITIONED|
                                                             {
                                                               -- AGGREGATE  |LOCAL|
                                                                 -- NESTED_TUPLE_SOURCE  |LOCAL|
                                                             }
-                                                      -- HASH_PARTITION_MERGE_EXCHANGE MERGE:[$$70(ASC)] HASH:[$$70]  |PARTITIONED|
-                                                        -- PRE_CLUSTERED_GROUP_BY[$$56]  |LOCAL|
+                                                      -- HASH_PARTITION_MERGE_EXCHANGE MERGE:[$$69(ASC)] HASH:[$$69]  |PARTITIONED|
+                                                        -- PRE_CLUSTERED_GROUP_BY[$$58]  |LOCAL|
                                                                 {
                                                                   -- AGGREGATE  |LOCAL|
                                                                     -- NESTED_TUPLE_SOURCE  |LOCAL|
@@ -70,7 +70,7 @@
                                                                       -- DATASOURCE_SCAN  |PARTITIONED|
                                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                                           -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                    -- HASH_PARTITION_EXCHANGE [$$58]  |PARTITIONED|
+                                    -- HASH_PARTITION_EXCHANGE [$$60]  |PARTITIONED|
                                       -- STREAM_PROJECT  |UNPARTITIONED|
                                         -- ASSIGN  |UNPARTITIONED|
                                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_01.plan b/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_01.plan
index 8983d73..148a0a8 100644
--- a/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_01.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_01.plan
@@ -6,7 +6,7 @@
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
             -- BTREE_SEARCH  |PARTITIONED|
               -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-                -- STABLE_SORT [$$15(ASC)]  |LOCAL|
+                -- STABLE_SORT [$$14(ASC)]  |LOCAL|
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                     -- STREAM_PROJECT  |PARTITIONED|
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_02.plan b/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_02.plan
index 8983d73..148a0a8 100644
--- a/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_02.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-edit-distance-check-let-panic-nopanic_02.plan
@@ -6,7 +6,7 @@
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
             -- BTREE_SEARCH  |PARTITIONED|
               -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-                -- STABLE_SORT [$$15(ASC)]  |LOCAL|
+                -- STABLE_SORT [$$14(ASC)]  |LOCAL|
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                     -- STREAM_PROJECT  |PARTITIONED|
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-jaccard-check-multi-let.plan b/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-jaccard-check-multi-let.plan
index 2f996ad..20cfea3 100644
--- a/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-jaccard-check-multi-let.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/ngram-jaccard-check-multi-let.plan
@@ -7,7 +7,7 @@
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
               -- BTREE_SEARCH  |PARTITIONED|
                 -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-                  -- STABLE_SORT [$$15(ASC)]  |LOCAL|
+                  -- STABLE_SORT [$$16(ASC)]  |LOCAL|
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                       -- STREAM_PROJECT  |PARTITIONED|
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/word-jaccard-check-multi-let.plan b/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/word-jaccard-check-multi-let.plan
index 2f996ad..20cfea3 100644
--- a/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/word-jaccard-check-multi-let.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/inverted-index-complex/word-jaccard-check-multi-let.plan
@@ -7,7 +7,7 @@
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
               -- BTREE_SEARCH  |PARTITIONED|
                 -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-                  -- STABLE_SORT [$$15(ASC)]  |LOCAL|
+                  -- STABLE_SORT [$$16(ASC)]  |LOCAL|
                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                       -- STREAM_PROJECT  |PARTITIONED|
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/join-super-key_01.plan b/asterix-app/src/test/resources/optimizerts/results/join-super-key_01.plan
index 7f3d6d7..f5f0063 100644
--- a/asterix-app/src/test/resources/optimizerts/results/join-super-key_01.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/join-super-key_01.plan
@@ -3,15 +3,15 @@
     -- STREAM_PROJECT  |PARTITIONED|
       -- ASSIGN  |PARTITIONED|
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- HYBRID_HASH_JOIN [$$20, $$22, $$16][$$19, $$23, $$18]  |PARTITIONED|
-            -- HASH_PARTITION_EXCHANGE [$$20, $$22, $$16]  |PARTITIONED|
+          -- HYBRID_HASH_JOIN [$$17, $$22, $$24][$$19, $$23, $$20]  |PARTITIONED|
+            -- HASH_PARTITION_EXCHANGE [$$17, $$22, $$24]  |PARTITIONED|
               -- STREAM_PROJECT  |PARTITIONED|
                 -- ASSIGN  |PARTITIONED|
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                     -- DATASOURCE_SCAN  |PARTITIONED|
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-            -- HASH_PARTITION_EXCHANGE [$$19, $$23, $$18]  |PARTITIONED|
+            -- HASH_PARTITION_EXCHANGE [$$19, $$23, $$20]  |PARTITIONED|
               -- STREAM_PROJECT  |PARTITIONED|
                 -- ASSIGN  |PARTITIONED|
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/join-super-key_02.plan b/asterix-app/src/test/resources/optimizerts/results/join-super-key_02.plan
index eb5e8c8..6476e6c 100644
--- a/asterix-app/src/test/resources/optimizerts/results/join-super-key_02.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/join-super-key_02.plan
@@ -3,7 +3,7 @@
     -- STREAM_PROJECT  |PARTITIONED|
       -- ASSIGN  |PARTITIONED|
         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-          -- HYBRID_HASH_JOIN [$$17, $$23, $$16][$$20, $$22, $$18]  |PARTITIONED|
+          -- HYBRID_HASH_JOIN [$$17, $$23, $$18][$$19, $$22, $$24]  |PARTITIONED|
             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
               -- STREAM_PROJECT  |PARTITIONED|
                 -- ASSIGN  |PARTITIONED|
@@ -11,7 +11,7 @@
                     -- DATASOURCE_SCAN  |PARTITIONED|
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                         -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-            -- HASH_PARTITION_EXCHANGE [$$18, $$20]  |PARTITIONED|
+            -- HASH_PARTITION_EXCHANGE [$$19, $$24]  |PARTITIONED|
               -- STREAM_PROJECT  |PARTITIONED|
                 -- ASSIGN  |PARTITIONED|
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/orders-composite-index-search.plan b/asterix-app/src/test/resources/optimizerts/results/orders-composite-index-search.plan
index 2b19a64..fda7f5b 100644
--- a/asterix-app/src/test/resources/optimizerts/results/orders-composite-index-search.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/orders-composite-index-search.plan
@@ -6,7 +6,7 @@
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
             -- BTREE_SEARCH  |PARTITIONED|
               -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-                -- STABLE_SORT [$$23(ASC)]  |LOCAL|
+                -- STABLE_SORT [$$21(ASC)]  |LOCAL|
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                     -- STREAM_PROJECT  |PARTITIONED|
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive-open_01.plan b/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive-open_01.plan
index 6e22ff1..559f0d1 100644
--- a/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive-open_01.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive-open_01.plan
@@ -1,14 +1,14 @@
 -- SINK_WRITE  |PARTITIONED|
   -- STREAM_PROJECT  |PARTITIONED|
     -- ASSIGN  |PARTITIONED|
-      -- SORT_MERGE_EXCHANGE [$$11(ASC) ]  |PARTITIONED|
+      -- SORT_MERGE_EXCHANGE [$$12(ASC) ]  |PARTITIONED|
         -- STREAM_PROJECT  |PARTITIONED|
           -- STREAM_SELECT  |PARTITIONED|
             -- ASSIGN  |PARTITIONED|
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                 -- BTREE_SEARCH  |PARTITIONED|
                   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-                    -- STABLE_SORT [$$20(ASC)]  |LOCAL|
+                    -- STABLE_SORT [$$19(ASC)]  |LOCAL|
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                         -- STREAM_PROJECT  |PARTITIONED|
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive-open_02.plan b/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive-open_02.plan
index 2a501cf..685d093 100644
--- a/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive-open_02.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive-open_02.plan
@@ -1,14 +1,14 @@
 -- SINK_WRITE  |PARTITIONED|
   -- STREAM_PROJECT  |PARTITIONED|
     -- ASSIGN  |PARTITIONED|
-      -- SORT_MERGE_EXCHANGE [$$12(ASC) ]  |PARTITIONED|
+      -- SORT_MERGE_EXCHANGE [$$14(ASC) ]  |PARTITIONED|
         -- STREAM_PROJECT  |PARTITIONED|
           -- STREAM_SELECT  |PARTITIONED|
             -- ASSIGN  |PARTITIONED|
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                 -- BTREE_SEARCH  |PARTITIONED|
                   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-                    -- STABLE_SORT [$$22(ASC)]  |LOCAL|
+                    -- STABLE_SORT [$$20(ASC)]  |LOCAL|
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                         -- STREAM_PROJECT  |PARTITIONED|
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive_01.plan b/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive_01.plan
index c9d9f78..559f0d1 100644
--- a/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive_01.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive_01.plan
@@ -1,18 +1,18 @@
 -- SINK_WRITE  |PARTITIONED|
   -- STREAM_PROJECT  |PARTITIONED|
     -- ASSIGN  |PARTITIONED|
-      -- SORT_MERGE_EXCHANGE [$$11(ASC) ]  |PARTITIONED|
+      -- SORT_MERGE_EXCHANGE [$$12(ASC) ]  |PARTITIONED|
         -- STREAM_PROJECT  |PARTITIONED|
           -- STREAM_SELECT  |PARTITIONED|
             -- ASSIGN  |PARTITIONED|
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                 -- BTREE_SEARCH  |PARTITIONED|
                   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-                    -- STABLE_SORT [$$20(ASC)]  |LOCAL|
+                    -- STABLE_SORT [$$19(ASC)]  |LOCAL|
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                         -- STREAM_PROJECT  |PARTITIONED|
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                             -- BTREE_SEARCH  |PARTITIONED|
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                 -- ASSIGN  |PARTITIONED|
-                                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive_02.plan b/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive_02.plan
index 85badf2..685d093 100644
--- a/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive_02.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/orders-index-search-conjunctive_02.plan
@@ -1,18 +1,18 @@
 -- SINK_WRITE  |PARTITIONED|
   -- STREAM_PROJECT  |PARTITIONED|
     -- ASSIGN  |PARTITIONED|
-      -- SORT_MERGE_EXCHANGE [$$12(ASC) ]  |PARTITIONED|
+      -- SORT_MERGE_EXCHANGE [$$14(ASC) ]  |PARTITIONED|
         -- STREAM_PROJECT  |PARTITIONED|
           -- STREAM_SELECT  |PARTITIONED|
             -- ASSIGN  |PARTITIONED|
               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                 -- BTREE_SEARCH  |PARTITIONED|
                   -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-                    -- STABLE_SORT [$$22(ASC)]  |LOCAL|
+                    -- STABLE_SORT [$$20(ASC)]  |LOCAL|
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                         -- STREAM_PROJECT  |PARTITIONED|
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                             -- BTREE_SEARCH  |PARTITIONED|
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                 -- ASSIGN  |PARTITIONED|
-                                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
\ No newline at end of file
+                                  -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/orders-index-search-open.plan b/asterix-app/src/test/resources/optimizerts/results/orders-index-search-open.plan
index 754f055..ce5cbbf 100644
--- a/asterix-app/src/test/resources/optimizerts/results/orders-index-search-open.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/orders-index-search-open.plan
@@ -6,7 +6,7 @@
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
             -- BTREE_SEARCH  |PARTITIONED|
               -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-                -- STABLE_SORT [$$14(ASC)]  |LOCAL|
+                -- STABLE_SORT [$$13(ASC)]  |LOCAL|
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                     -- STREAM_PROJECT  |PARTITIONED|
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/orders-index-search.plan b/asterix-app/src/test/resources/optimizerts/results/orders-index-search.plan
index 754f055..ce5cbbf 100644
--- a/asterix-app/src/test/resources/optimizerts/results/orders-index-search.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/orders-index-search.plan
@@ -6,7 +6,7 @@
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
             -- BTREE_SEARCH  |PARTITIONED|
               -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-                -- STABLE_SORT [$$14(ASC)]  |LOCAL|
+                -- STABLE_SORT [$$13(ASC)]  |LOCAL|
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                     -- STREAM_PROJECT  |PARTITIONED|
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/push_limit.plan b/asterix-app/src/test/resources/optimizerts/results/push_limit.plan
index 3400b25..21d56c6 100644
--- a/asterix-app/src/test/resources/optimizerts/results/push_limit.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/push_limit.plan
@@ -2,7 +2,7 @@
   -- STREAM_PROJECT  |UNPARTITIONED|
     -- ASSIGN  |UNPARTITIONED|
       -- STREAM_LIMIT  |UNPARTITIONED|
-        -- SORT_MERGE_EXCHANGE [$$8(ASC) ]  |PARTITIONED|
+        -- SORT_MERGE_EXCHANGE [$$9(ASC) ]  |PARTITIONED|
           -- STREAM_PROJECT  |PARTITIONED|
             -- STREAM_SELECT  |PARTITIONED|
               -- ASSIGN  |PARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/q3_shipping_priority.plan b/asterix-app/src/test/resources/optimizerts/results/q3_shipping_priority.plan
index 4fb9342..141f042 100644
--- a/asterix-app/src/test/resources/optimizerts/results/q3_shipping_priority.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/q3_shipping_priority.plan
@@ -2,10 +2,10 @@
   -- STREAM_PROJECT  |UNPARTITIONED|
     -- ASSIGN  |UNPARTITIONED|
       -- STREAM_LIMIT  |UNPARTITIONED|
-        -- SORT_MERGE_EXCHANGE [$$44(DESC), $$4(ASC) ]  |PARTITIONED|
+        -- SORT_MERGE_EXCHANGE [$$46(DESC), $$4(ASC) ]  |PARTITIONED|
           -- STREAM_LIMIT  |LOCAL|
             -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-              -- STABLE_SORT [$$44(DESC), $$4(ASC)]  |LOCAL|
+              -- STABLE_SORT [$$46(DESC), $$4(ASC)]  |LOCAL|
                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                   -- EXTERNAL_GROUP_BY[$$56, $$57, $$58]  |PARTITIONED|
                           {
@@ -13,7 +13,7 @@
                               -- NESTED_TUPLE_SOURCE  |LOCAL|
                           }
                     -- HASH_PARTITION_EXCHANGE [$$56, $$57, $$58]  |PARTITIONED|
-                      -- EXTERNAL_GROUP_BY[$$42, $$47, $$39]  |LOCAL|
+                      -- EXTERNAL_GROUP_BY[$$44, $$41, $$39]  |LOCAL|
                               {
                                 -- AGGREGATE  |LOCAL|
                                   -- NESTED_TUPLE_SOURCE  |LOCAL|
@@ -21,11 +21,11 @@
                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                           -- STREAM_PROJECT  |PARTITIONED|
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- HYBRID_HASH_JOIN [$$41][$$42]  |PARTITIONED|
-                                -- HASH_PARTITION_EXCHANGE [$$41]  |PARTITIONED|
+                              -- HYBRID_HASH_JOIN [$$43][$$44]  |PARTITIONED|
+                                -- HASH_PARTITION_EXCHANGE [$$43]  |PARTITIONED|
                                   -- STREAM_PROJECT  |PARTITIONED|
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                      -- HYBRID_HASH_JOIN [$$40][$$49]  |PARTITIONED|
+                                      -- HYBRID_HASH_JOIN [$$42][$$50]  |PARTITIONED|
                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                           -- STREAM_PROJECT  |PARTITIONED|
                                             -- STREAM_SELECT  |PARTITIONED|
@@ -34,16 +34,15 @@
                                                   -- DATASOURCE_SCAN  |PARTITIONED|
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                        -- HASH_PARTITION_EXCHANGE [$$49]  |PARTITIONED|
+                                        -- HASH_PARTITION_EXCHANGE [$$50]  |PARTITIONED|
                                           -- STREAM_PROJECT  |PARTITIONED|
-                                            -- ASSIGN  |PARTITIONED|
-                                              -- STREAM_SELECT  |PARTITIONED|
-                                                -- ASSIGN  |PARTITIONED|
-                                                  -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                    -- DATASOURCE_SCAN  |PARTITIONED|
-                                                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                -- HASH_PARTITION_EXCHANGE [$$42]  |PARTITIONED|
+                                            -- STREAM_SELECT  |PARTITIONED|
+                                              -- ASSIGN  |PARTITIONED|
+                                                -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                  -- DATASOURCE_SCAN  |PARTITIONED|
+                                                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                                                      -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                                -- HASH_PARTITION_EXCHANGE [$$44]  |PARTITIONED|
                                   -- STREAM_PROJECT  |PARTITIONED|
                                     -- STREAM_SELECT  |PARTITIONED|
                                       -- ASSIGN  |PARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/q5_local_supplier_volume.plan b/asterix-app/src/test/resources/optimizerts/results/q5_local_supplier_volume.plan
index bd95437..4f123f6 100644
--- a/asterix-app/src/test/resources/optimizerts/results/q5_local_supplier_volume.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/q5_local_supplier_volume.plan
@@ -1,15 +1,15 @@
 -- SINK_WRITE  |PARTITIONED|
   -- STREAM_PROJECT  |PARTITIONED|
     -- ASSIGN  |PARTITIONED|
-      -- SORT_MERGE_EXCHANGE [$$87(DESC) ]  |PARTITIONED|
-        -- STABLE_SORT [$$87(DESC)]  |LOCAL|
+      -- SORT_MERGE_EXCHANGE [$$89(DESC) ]  |PARTITIONED|
+        -- STABLE_SORT [$$89(DESC)]  |LOCAL|
           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- EXTERNAL_GROUP_BY[$$122]  |PARTITIONED|
+            -- EXTERNAL_GROUP_BY[$$120]  |PARTITIONED|
                     {
                       -- AGGREGATE  |LOCAL|
                         -- NESTED_TUPLE_SOURCE  |LOCAL|
                     }
-              -- HASH_PARTITION_EXCHANGE [$$122]  |PARTITIONED|
+              -- HASH_PARTITION_EXCHANGE [$$120]  |PARTITIONED|
                 -- EXTERNAL_GROUP_BY[$$94]  |LOCAL|
                         {
                           -- AGGREGATE  |LOCAL|
@@ -18,7 +18,7 @@
                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                     -- STREAM_PROJECT  |PARTITIONED|
                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- HYBRID_HASH_JOIN [$$80, $$117][$$114, $$96]  |PARTITIONED|
+                        -- HYBRID_HASH_JOIN [$$81, $$115][$$112, $$88]  |PARTITIONED|
                           -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                             -- STREAM_PROJECT  |PARTITIONED|
                               -- ASSIGN  |PARTITIONED|
@@ -26,10 +26,10 @@
                                   -- DATASOURCE_SCAN  |PARTITIONED|
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                          -- HASH_PARTITION_EXCHANGE [$$114]  |PARTITIONED|
+                          -- HASH_PARTITION_EXCHANGE [$$112]  |PARTITIONED|
                             -- STREAM_PROJECT  |PARTITIONED|
                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                -- HYBRID_HASH_JOIN [$$81][$$82]  |PARTITIONED|
+                                -- HYBRID_HASH_JOIN [$$82][$$83]  |PARTITIONED|
                                   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                     -- STREAM_PROJECT  |PARTITIONED|
                                       -- STREAM_SELECT  |PARTITIONED|
@@ -38,32 +38,32 @@
                                             -- DATASOURCE_SCAN  |PARTITIONED|
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                 -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                  -- HASH_PARTITION_EXCHANGE [$$82]  |PARTITIONED|
+                                  -- HASH_PARTITION_EXCHANGE [$$83]  |PARTITIONED|
                                     -- STREAM_PROJECT  |PARTITIONED|
                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                        -- HYBRID_HASH_JOIN [$$101][$$84]  |PARTITIONED|
-                                          -- HASH_PARTITION_EXCHANGE [$$101]  |PARTITIONED|
+                                        -- HYBRID_HASH_JOIN [$$99][$$85]  |PARTITIONED|
+                                          -- HASH_PARTITION_EXCHANGE [$$99]  |PARTITIONED|
                                             -- STREAM_PROJECT  |PARTITIONED|
                                               -- ASSIGN  |PARTITIONED|
                                                 -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                   -- DATASOURCE_SCAN  |PARTITIONED|
                                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                       -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                          -- HASH_PARTITION_EXCHANGE [$$84]  |PARTITIONED|
+                                          -- HASH_PARTITION_EXCHANGE [$$85]  |PARTITIONED|
                                             -- STREAM_PROJECT  |PARTITIONED|
                                               -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                -- HYBRID_HASH_JOIN [$$96][$$85]  |PARTITIONED|
-                                                  -- HASH_PARTITION_EXCHANGE [$$96]  |PARTITIONED|
+                                                -- HYBRID_HASH_JOIN [$$88][$$86]  |PARTITIONED|
+                                                  -- HASH_PARTITION_EXCHANGE [$$88]  |PARTITIONED|
                                                     -- STREAM_PROJECT  |PARTITIONED|
                                                       -- ASSIGN  |PARTITIONED|
                                                         -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                           -- DATASOURCE_SCAN  |PARTITIONED|
                                                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                                               -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
-                                                  -- HASH_PARTITION_EXCHANGE [$$85]  |PARTITIONED|
+                                                  -- HASH_PARTITION_EXCHANGE [$$86]  |PARTITIONED|
                                                     -- STREAM_PROJECT  |PARTITIONED|
                                                       -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                                                        -- HYBRID_HASH_JOIN [$$92][$$86]  |PARTITIONED|
+                                                        -- HYBRID_HASH_JOIN [$$92][$$87]  |PARTITIONED|
                                                           -- HASH_PARTITION_EXCHANGE [$$92]  |PARTITIONED|
                                                             -- STREAM_PROJECT  |PARTITIONED|
                                                               -- ASSIGN  |PARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/scan-delete-rtree-secondary-index.plan b/asterix-app/src/test/resources/optimizerts/results/scan-delete-rtree-secondary-index.plan
index 03fd04e..7f3570c 100644
--- a/asterix-app/src/test/resources/optimizerts/results/scan-delete-rtree-secondary-index.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/scan-delete-rtree-secondary-index.plan
@@ -2,7 +2,7 @@
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
     -- INDEX_INSERT_DELETE  |UNPARTITIONED|
       -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-        -- STABLE_SORT [$$25(ASC), $$26(ASC), $$27(ASC), $$28(ASC)]  |LOCAL|
+        -- STABLE_SORT [$$24(ASC), $$25(ASC), $$26(ASC), $$27(ASC)]  |LOCAL|
           -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
             -- ASSIGN  |UNPARTITIONED|
               -- ASSIGN  |UNPARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/scan-delete.plan b/asterix-app/src/test/resources/optimizerts/results/scan-delete.plan
index f1a7172..57aafc3 100644
--- a/asterix-app/src/test/resources/optimizerts/results/scan-delete.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/scan-delete.plan
@@ -7,10 +7,9 @@
             -- ASSIGN  |PARTITIONED|
               -- STREAM_PROJECT  |PARTITIONED|
                 -- ASSIGN  |PARTITIONED|
-                  -- ASSIGN  |PARTITIONED|
-                    -- STREAM_SELECT  |PARTITIONED|
-                      -- ASSIGN  |PARTITIONED|
-                        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                          -- DATASOURCE_SCAN  |PARTITIONED|
-                            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                              -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
+                  -- STREAM_SELECT  |PARTITIONED|
+                    -- ASSIGN  |PARTITIONED|
+                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                        -- DATASOURCE_SCAN  |PARTITIONED|
+                          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                            -- EMPTY_TUPLE_SOURCE  |PARTITIONED|
diff --git a/asterix-app/src/test/resources/optimizerts/results/scan-insert-secondary-index.plan b/asterix-app/src/test/resources/optimizerts/results/scan-insert-secondary-index.plan
index c1bed36..765770e 100644
--- a/asterix-app/src/test/resources/optimizerts/results/scan-insert-secondary-index.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/scan-insert-secondary-index.plan
@@ -2,14 +2,14 @@
   -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
     -- INDEX_INSERT_DELETE  |UNPARTITIONED|
       -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-        -- STABLE_SORT [$$12(ASC)]  |LOCAL|
+        -- STABLE_SORT [$$11(ASC)]  |LOCAL|
           -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
             -- ASSIGN  |UNPARTITIONED|
               -- STREAM_PROJECT  |UNPARTITIONED|
                 -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
                   -- INDEX_INSERT_DELETE  |UNPARTITIONED|
                     -- ONE_TO_ONE_EXCHANGE  |LOCAL|
-                      -- STABLE_SORT [$$11(ASC)]  |LOCAL|
+                      -- STABLE_SORT [$$10(ASC)]  |LOCAL|
                         -- ONE_TO_ONE_EXCHANGE  |UNPARTITIONED|
                           -- ASSIGN  |UNPARTITIONED|
                             -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|