ASTERIXDB-1005, ASTERIXDB-1263: Clean up subplan flattening:
1. Inline NestedTupleSource and remove SubplanOperator for special cases that
   join operators inside the SubplanOperator can be re-targeted for
   correlations;
2. Blindly inline NestedTupleSource and remove SubplanOperator for general cases
   where the condition of the special case is not met.

Change-Id: I4dd130a25f3c81272cc23f844ea20e376e990612
Reviewed-on: https://asterix-gerrit.ics.uci.edu/579
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <tillw@apache.org>
diff --git a/asterix-app/src/test/resources/optimizerts/results/fj-phase1.plan b/asterix-app/src/test/resources/optimizerts/results/fj-phase1.plan
index c5511fd..64c0b06 100644
--- a/asterix-app/src/test/resources/optimizerts/results/fj-phase1.plan
+++ b/asterix-app/src/test/resources/optimizerts/results/fj-phase1.plan
@@ -2,34 +2,34 @@
   -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
     -- STREAM_PROJECT  |PARTITIONED|
       -- ASSIGN  |PARTITIONED|
-        -- STREAM_PROJECT  |PARTITIONED|
-          -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-            -- PRE_CLUSTERED_GROUP_BY[$$23]  |PARTITIONED|
-                    {
-                      -- AGGREGATE  |LOCAL|
-                        -- STREAM_SELECT  |LOCAL|
-                          -- NESTED_TUPLE_SOURCE  |LOCAL|
-                    }
-              -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                -- STABLE_SORT [$$23(ASC), $$4(ASC)]  |PARTITIONED|
-                  -- HASH_PARTITION_EXCHANGE [$$23]  |PARTITIONED|
-                    -- STREAM_PROJECT  |PARTITIONED|
-                      -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
-                        -- HYBRID_HASH_JOIN [$$1][$$4]  |PARTITIONED|
-                          -- HASH_PARTITION_EXCHANGE [$$1]  |PARTITIONED|
-                            -- STREAM_PROJECT  |PARTITIONED|
-                              -- UNNEST  |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 [$$4]  |PARTITIONED|
+        -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+          -- PRE_CLUSTERED_GROUP_BY[$$21]  |PARTITIONED|
+                  {
+                    -- AGGREGATE  |LOCAL|
+                      -- STREAM_SELECT  |LOCAL|
+                        -- NESTED_TUPLE_SOURCE  |LOCAL|
+                  }
+            -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+              -- STABLE_SORT [$$21(ASC), $$4(ASC)]  |PARTITIONED|
+                -- HASH_PARTITION_EXCHANGE [$$21]  |PARTITIONED|
+                  -- STREAM_PROJECT  |PARTITIONED|
+                    -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
+                      -- HYBRID_HASH_JOIN [$$1][$$4]  |PARTITIONED|
+                        -- HASH_PARTITION_EXCHANGE [$$1]  |PARTITIONED|
+                          -- STREAM_PROJECT  |PARTITIONED|
+                            -- UNNEST  |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 [$$4]  |PARTITIONED|
+                          -- ASSIGN  |PARTITIONED|
                             -- RUNNING_AGGREGATE  |PARTITIONED|
                               -- STREAM_PROJECT  |PARTITIONED|
-                                -- SORT_MERGE_EXCHANGE [$$24(DESC) ]  |PARTITIONED|
-                                  -- STABLE_SORT [$$24(DESC)]  |PARTITIONED|
+                                -- SORT_MERGE_EXCHANGE [$$23(DESC) ]  |PARTITIONED|
+                                  -- STABLE_SORT [$$23(DESC)]  |PARTITIONED|
                                     -- ONE_TO_ONE_EXCHANGE  |PARTITIONED|
                                       -- PRE_CLUSTERED_GROUP_BY[$$30]  |PARTITIONED|
                                               {