http://git-wip-us.apache.org/repos/asf/hive/blob/9244fdc7/ql/src/test/results/clientpositive/perf/tez/query39.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/perf/tez/query39.q.out 
b/ql/src/test/results/clientpositive/perf/tez/query39.q.out
new file mode 100644
index 0000000..8e91494
--- /dev/null
+++ b/ql/src/test/results/clientpositive/perf/tez/query39.q.out
@@ -0,0 +1,255 @@
+PREHOOK: query: explain
+with inv as
+(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy
+       ,stdev,mean, case mean when 0 then null else stdev/mean end cov
+ from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy
+            ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) 
mean
+      from inventory
+          ,item
+          ,warehouse
+          ,date_dim
+      where inv_item_sk = i_item_sk
+        and inv_warehouse_sk = w_warehouse_sk
+        and inv_date_sk = d_date_sk
+        and d_year =1999
+      group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo
+ where case mean when 0 then 0 else stdev/mean end > 1)
+select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov
+        ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov
+from inv inv1,inv inv2
+where inv1.i_item_sk = inv2.i_item_sk
+  and inv1.w_warehouse_sk =  inv2.w_warehouse_sk
+  and inv1.d_moy=4
+  and inv2.d_moy=4+1
+order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov
+        ,inv2.d_moy,inv2.mean, inv2.cov
+PREHOOK: type: QUERY
+POSTHOOK: query: explain
+with inv as
+(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy
+       ,stdev,mean, case mean when 0 then null else stdev/mean end cov
+ from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy
+            ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) 
mean
+      from inventory
+          ,item
+          ,warehouse
+          ,date_dim
+      where inv_item_sk = i_item_sk
+        and inv_warehouse_sk = w_warehouse_sk
+        and inv_date_sk = d_date_sk
+        and d_year =1999
+      group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo
+ where case mean when 0 then 0 else stdev/mean end > 1)
+select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov
+        ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov
+from inv inv1,inv inv2
+where inv1.i_item_sk = inv2.i_item_sk
+  and inv1.w_warehouse_sk =  inv2.w_warehouse_sk
+  and inv1.d_moy=4
+  and inv2.d_moy=4+1
+order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov
+        ,inv2.d_moy,inv2.mean, inv2.cov
+POSTHOOK: type: QUERY
+Plan optimized by CBO.
+
+Vertex dependency in root stage
+Reducer 10 <- Map 14 (SIMPLE_EDGE), Reducer 9 (SIMPLE_EDGE)
+Reducer 11 <- Reducer 10 (SIMPLE_EDGE)
+Reducer 2 <- Map 1 (SIMPLE_EDGE), Map 12 (SIMPLE_EDGE)
+Reducer 3 <- Map 13 (SIMPLE_EDGE), Reducer 2 (SIMPLE_EDGE)
+Reducer 4 <- Map 14 (SIMPLE_EDGE), Reducer 3 (SIMPLE_EDGE)
+Reducer 5 <- Reducer 4 (SIMPLE_EDGE)
+Reducer 6 <- Reducer 11 (SIMPLE_EDGE), Reducer 5 (SIMPLE_EDGE)
+Reducer 7 <- Reducer 6 (SIMPLE_EDGE)
+Reducer 8 <- Map 1 (SIMPLE_EDGE), Map 12 (SIMPLE_EDGE)
+Reducer 9 <- Map 13 (SIMPLE_EDGE), Reducer 8 (SIMPLE_EDGE)
+
+Stage-0
+  Fetch Operator
+    limit:-1
+    Stage-1
+      Reducer 7
+      File Output Operator [FS_63]
+        Select Operator [SEL_61] (rows=13756683 width=15)
+          
Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6","_col7","_col8","_col9"]
+        <-Reducer 6 [SIMPLE_EDGE]
+          SHUFFLE [RS_60]
+            Select Operator [SEL_59] (rows=13756683 width=15)
+              
Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6","_col7"]
+              Merge Join Operator [MERGEJOIN_104] (rows=13756683 width=15)
+                Conds:RS_56._col1, _col2=RS_57._col1, 
_col2(Inner),Output:["_col1","_col2","_col3","_col4","_col6","_col7","_col8","_col9"]
+              <-Reducer 11 [SIMPLE_EDGE]
+                SHUFFLE [RS_57]
+                  PartitionCols:_col1, _col2
+                  Select Operator [SEL_55] (rows=12506076 width=15)
+                    Output:["_col1","_col2","_col3","_col4"]
+                    Filter Operator [FIL_54] (rows=12506076 width=15)
+                      predicate:CASE WHEN ((_col4 = 0.0)) THEN (false) ELSE 
(((_col3 / _col4) > 1.0)) END
+                      Select Operator [SEL_53] (rows=25012152 width=15)
+                        Output:["_col1","_col2","_col3","_col4"]
+                        Group By Operator [GBY_52] (rows=25012152 width=15)
+                          
Output:["_col0","_col1","_col2","_col3","_col4"],aggregations:["stddev_samp(VALUE._col0)","avg(VALUE._col1)"],keys:KEY._col0,
 KEY._col1, KEY._col2
+                        <-Reducer 10 [SIMPLE_EDGE]
+                          SHUFFLE [RS_51]
+                            PartitionCols:_col0, _col1, _col2
+                            Group By Operator [GBY_50] (rows=50024305 width=15)
+                              
Output:["_col0","_col1","_col2","_col3","_col4"],aggregations:["stddev_samp(_col3)","avg(_col3)"],keys:_col8,
 _col7, _col9
+                              Merge Join Operator [MERGEJOIN_103] 
(rows=50024305 width=15)
+                                
Conds:RS_46._col2=RS_47._col0(Inner),Output:["_col3","_col7","_col8","_col9"]
+                              <-Map 14 [SIMPLE_EDGE]
+                                SHUFFLE [RS_47]
+                                  PartitionCols:_col0
+                                  Select Operator [SEL_11] (rows=27 width=1029)
+                                    Output:["_col0","_col1"]
+                                    Filter Operator [FIL_93] (rows=27 
width=1029)
+                                      predicate:w_warehouse_sk is not null
+                                      TableScan [TS_9] (rows=27 width=1029)
+                                        
default@warehouse,warehouse,Tbl:COMPLETE,Col:NONE,Output:["w_warehouse_sk","w_warehouse_name"]
+                              <-Reducer 9 [SIMPLE_EDGE]
+                                SHUFFLE [RS_46]
+                                  PartitionCols:_col2
+                                  Merge Join Operator [MERGEJOIN_102] 
(rows=45476640 width=15)
+                                    
Conds:RS_43._col1=RS_44._col0(Inner),Output:["_col2","_col3","_col7"]
+                                  <-Map 13 [SIMPLE_EDGE]
+                                    SHUFFLE [RS_44]
+                                      PartitionCols:_col0
+                                      Select Operator [SEL_8] (rows=462000 
width=1436)
+                                        Output:["_col0"]
+                                        Filter Operator [FIL_92] (rows=462000 
width=1436)
+                                          predicate:i_item_sk is not null
+                                          TableScan [TS_6] (rows=462000 
width=1436)
+                                            
default@item,item,Tbl:COMPLETE,Col:NONE,Output:["i_item_sk"]
+                                  <-Reducer 8 [SIMPLE_EDGE]
+                                    SHUFFLE [RS_43]
+                                      PartitionCols:_col1
+                                      Merge Join Operator [MERGEJOIN_101] 
(rows=41342400 width=15)
+                                        
Conds:RS_40._col0=RS_41._col0(Inner),Output:["_col1","_col2","_col3"]
+                                      <-Map 1 [SIMPLE_EDGE]
+                                        SHUFFLE [RS_40]
+                                          PartitionCols:_col0
+                                          Select Operator [SEL_2] 
(rows=37584000 width=15)
+                                            
Output:["_col0","_col1","_col2","_col3"]
+                                            Filter Operator [FIL_90] 
(rows=37584000 width=15)
+                                              predicate:(inv_date_sk is not 
null and inv_item_sk is not null and inv_warehouse_sk is not null)
+                                              TableScan [TS_0] (rows=37584000 
width=15)
+                                                
default@inventory,inventory,Tbl:COMPLETE,Col:NONE,Output:["inv_date_sk","inv_item_sk","inv_warehouse_sk","inv_quantity_on_hand"]
+                                      <-Map 12 [SIMPLE_EDGE]
+                                        SHUFFLE [RS_41]
+                                          PartitionCols:_col0
+                                          Select Operator [SEL_33] (rows=18262 
width=1119)
+                                            Output:["_col0"]
+                                            Filter Operator [FIL_95] 
(rows=18262 width=1119)
+                                              predicate:((d_moy = 5) and 
(d_year = 1999) and d_date_sk is not null)
+                                              TableScan [TS_3] (rows=73049 
width=1119)
+                                                
default@date_dim,date_dim,Tbl:COMPLETE,Col:NONE,Output:["d_date_sk","d_year","d_moy"]
+              <-Reducer 5 [SIMPLE_EDGE]
+                SHUFFLE [RS_56]
+                  PartitionCols:_col1, _col2
+                  Select Operator [SEL_27] (rows=12506076 width=15)
+                    Output:["_col1","_col2","_col3","_col4"]
+                    Filter Operator [FIL_26] (rows=12506076 width=15)
+                      predicate:CASE WHEN ((_col4 = 0.0)) THEN (false) ELSE 
(((_col3 / _col4) > 1.0)) END
+                      Select Operator [SEL_25] (rows=25012152 width=15)
+                        Output:["_col1","_col2","_col3","_col4"]
+                        Group By Operator [GBY_24] (rows=25012152 width=15)
+                          
Output:["_col0","_col1","_col2","_col3","_col4"],aggregations:["stddev_samp(VALUE._col0)","avg(VALUE._col1)"],keys:KEY._col0,
 KEY._col1, KEY._col2
+                        <-Reducer 4 [SIMPLE_EDGE]
+                          SHUFFLE [RS_23]
+                            PartitionCols:_col0, _col1, _col2
+                            Group By Operator [GBY_22] (rows=50024305 width=15)
+                              
Output:["_col0","_col1","_col2","_col3","_col4"],aggregations:["stddev_samp(_col3)","avg(_col3)"],keys:_col8,
 _col7, _col9
+                              Merge Join Operator [MERGEJOIN_100] 
(rows=50024305 width=15)
+                                
Conds:RS_18._col2=RS_19._col0(Inner),Output:["_col3","_col7","_col8","_col9"]
+                              <-Map 14 [SIMPLE_EDGE]
+                                SHUFFLE [RS_19]
+                                  PartitionCols:_col0
+                                   Please refer to the previous Select 
Operator [SEL_11]
+                              <-Reducer 3 [SIMPLE_EDGE]
+                                SHUFFLE [RS_18]
+                                  PartitionCols:_col2
+                                  Merge Join Operator [MERGEJOIN_99] 
(rows=45476640 width=15)
+                                    
Conds:RS_15._col1=RS_16._col0(Inner),Output:["_col2","_col3","_col7"]
+                                  <-Map 13 [SIMPLE_EDGE]
+                                    SHUFFLE [RS_16]
+                                      PartitionCols:_col0
+                                       Please refer to the previous Select 
Operator [SEL_8]
+                                  <-Reducer 2 [SIMPLE_EDGE]
+                                    SHUFFLE [RS_15]
+                                      PartitionCols:_col1
+                                      Merge Join Operator [MERGEJOIN_98] 
(rows=41342400 width=15)
+                                        
Conds:RS_12._col0=RS_13._col0(Inner),Output:["_col1","_col2","_col3"]
+                                      <-Map 1 [SIMPLE_EDGE]
+                                        SHUFFLE [RS_12]
+                                          PartitionCols:_col0
+                                           Please refer to the previous Select 
Operator [SEL_2]
+                                      <-Map 12 [SIMPLE_EDGE]
+                                        SHUFFLE [RS_13]
+                                          PartitionCols:_col0
+                                          Select Operator [SEL_5] (rows=18262 
width=1119)
+                                            Output:["_col0"]
+                                            Filter Operator [FIL_91] 
(rows=18262 width=1119)
+                                              predicate:((d_moy = 4) and 
(d_year = 1999) and d_date_sk is not null)
+                                               Please refer to the previous 
TableScan [TS_3]
+
+PREHOOK: query: with inv as
+(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy
+       ,stdev,mean, case mean when 0 then null else stdev/mean end cov
+ from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy
+            ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) 
mean
+      from inventory
+          ,item
+          ,warehouse
+          ,date_dim
+      where inv_item_sk = i_item_sk
+        and inv_warehouse_sk = w_warehouse_sk
+        and inv_date_sk = d_date_sk
+        and d_year =1999
+      group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo
+ where case mean when 0 then 0 else stdev/mean end > 1)
+select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov
+        ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov
+from inv inv1,inv inv2
+where inv1.i_item_sk = inv2.i_item_sk
+  and inv1.w_warehouse_sk =  inv2.w_warehouse_sk
+  and inv1.d_moy=4
+  and inv2.d_moy=4+1
+  and inv1.cov > 1.5
+order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov
+        ,inv2.d_moy,inv2.mean, inv2.cov
+PREHOOK: type: QUERY
+PREHOOK: Input: default@date_dim
+PREHOOK: Input: default@inventory
+PREHOOK: Input: default@item
+PREHOOK: Input: default@warehouse
+#### A masked pattern was here ####
+POSTHOOK: query: with inv as
+(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy
+       ,stdev,mean, case mean when 0 then null else stdev/mean end cov
+ from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy
+            ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) 
mean
+      from inventory
+          ,item
+          ,warehouse
+          ,date_dim
+      where inv_item_sk = i_item_sk
+        and inv_warehouse_sk = w_warehouse_sk
+        and inv_date_sk = d_date_sk
+        and d_year =1999
+      group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo
+ where case mean when 0 then 0 else stdev/mean end > 1)
+select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov
+        ,inv2.w_warehouse_sk,inv2.i_item_sk,inv2.d_moy,inv2.mean, inv2.cov
+from inv inv1,inv inv2
+where inv1.i_item_sk = inv2.i_item_sk
+  and inv1.w_warehouse_sk =  inv2.w_warehouse_sk
+  and inv1.d_moy=4
+  and inv2.d_moy=4+1
+  and inv1.cov > 1.5
+order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov
+        ,inv2.d_moy,inv2.mean, inv2.cov
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@date_dim
+POSTHOOK: Input: default@inventory
+POSTHOOK: Input: default@item
+POSTHOOK: Input: default@warehouse
+#### A masked pattern was here ####

http://git-wip-us.apache.org/repos/asf/hive/blob/9244fdc7/ql/src/test/results/clientpositive/perf/tez/query4.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/perf/tez/query4.q.out 
b/ql/src/test/results/clientpositive/perf/tez/query4.q.out
new file mode 100644
index 0000000..81867b9
--- /dev/null
+++ b/ql/src/test/results/clientpositive/perf/tez/query4.q.out
@@ -0,0 +1,500 @@
+PREHOOK: query: explain
+with year_total as (
+ select c_customer_id customer_id
+       ,c_first_name customer_first_name
+       ,c_last_name customer_last_name
+       ,c_preferred_cust_flag customer_preferred_cust_flag
+       ,c_birth_country customer_birth_country
+       ,c_login customer_login
+       ,c_email_address customer_email_address
+       ,d_year dyear
+       
,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2)
 year_total
+       ,'s' sale_type
+ from customer
+     ,store_sales
+     ,date_dim
+ where c_customer_sk = ss_customer_sk
+   and ss_sold_date_sk = d_date_sk
+ group by c_customer_id
+         ,c_first_name
+         ,c_last_name
+         ,c_preferred_cust_flag
+         ,c_birth_country
+         ,c_login
+         ,c_email_address
+         ,d_year
+ union all
+ select c_customer_id customer_id
+       ,c_first_name customer_first_name
+       ,c_last_name customer_last_name
+       ,c_preferred_cust_flag customer_preferred_cust_flag
+       ,c_birth_country customer_birth_country
+       ,c_login customer_login
+       ,c_email_address customer_email_address
+       ,d_year dyear
+       
,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2)
 ) year_total
+       ,'c' sale_type
+ from customer
+     ,catalog_sales
+     ,date_dim
+ where c_customer_sk = cs_bill_customer_sk
+   and cs_sold_date_sk = d_date_sk
+ group by c_customer_id
+         ,c_first_name
+         ,c_last_name
+         ,c_preferred_cust_flag
+         ,c_birth_country
+         ,c_login
+         ,c_email_address
+         ,d_year
+union all
+ select c_customer_id customer_id
+       ,c_first_name customer_first_name
+       ,c_last_name customer_last_name
+       ,c_preferred_cust_flag customer_preferred_cust_flag
+       ,c_birth_country customer_birth_country
+       ,c_login customer_login
+       ,c_email_address customer_email_address
+       ,d_year dyear
+       
,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2)
 ) year_total
+       ,'w' sale_type
+ from customer
+     ,web_sales
+     ,date_dim
+ where c_customer_sk = ws_bill_customer_sk
+   and ws_sold_date_sk = d_date_sk
+ group by c_customer_id
+         ,c_first_name
+         ,c_last_name
+         ,c_preferred_cust_flag
+         ,c_birth_country
+         ,c_login
+         ,c_email_address
+         ,d_year
+         )
+  select  t_s_secyear.customer_preferred_cust_flag
+ from year_total t_s_firstyear
+     ,year_total t_s_secyear
+     ,year_total t_c_firstyear
+     ,year_total t_c_secyear
+     ,year_total t_w_firstyear
+     ,year_total t_w_secyear
+ where t_s_secyear.customer_id = t_s_firstyear.customer_id
+   and t_s_firstyear.customer_id = t_c_secyear.customer_id
+   and t_s_firstyear.customer_id = t_c_firstyear.customer_id
+   and t_s_firstyear.customer_id = t_w_firstyear.customer_id
+   and t_s_firstyear.customer_id = t_w_secyear.customer_id
+   and t_s_firstyear.sale_type = 's'
+   and t_c_firstyear.sale_type = 'c'
+   and t_w_firstyear.sale_type = 'w'
+   and t_s_secyear.sale_type = 's'
+   and t_c_secyear.sale_type = 'c'
+   and t_w_secyear.sale_type = 'w'
+   and t_s_firstyear.dyear =  2001
+   and t_s_secyear.dyear = 2001+1
+   and t_c_firstyear.dyear =  2001
+   and t_c_secyear.dyear =  2001+1
+   and t_w_firstyear.dyear = 2001
+   and t_w_secyear.dyear = 2001+1
+   and t_s_firstyear.year_total > 0
+   and t_c_firstyear.year_total > 0
+   and t_w_firstyear.year_total > 0
+   and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / 
t_c_firstyear.year_total else null end
+           > case when t_s_firstyear.year_total > 0 then 
t_s_secyear.year_total / t_s_firstyear.year_total else null end
+   and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / 
t_c_firstyear.year_total else null end
+           > case when t_w_firstyear.year_total > 0 then 
t_w_secyear.year_total / t_w_firstyear.year_total else null end
+ order by t_s_secyear.customer_preferred_cust_flag
+limit 100
+PREHOOK: type: QUERY
+POSTHOOK: query: explain
+with year_total as (
+ select c_customer_id customer_id
+       ,c_first_name customer_first_name
+       ,c_last_name customer_last_name
+       ,c_preferred_cust_flag customer_preferred_cust_flag
+       ,c_birth_country customer_birth_country
+       ,c_login customer_login
+       ,c_email_address customer_email_address
+       ,d_year dyear
+       
,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2)
 year_total
+       ,'s' sale_type
+ from customer
+     ,store_sales
+     ,date_dim
+ where c_customer_sk = ss_customer_sk
+   and ss_sold_date_sk = d_date_sk
+ group by c_customer_id
+         ,c_first_name
+         ,c_last_name
+         ,c_preferred_cust_flag
+         ,c_birth_country
+         ,c_login
+         ,c_email_address
+         ,d_year
+ union all
+ select c_customer_id customer_id
+       ,c_first_name customer_first_name
+       ,c_last_name customer_last_name
+       ,c_preferred_cust_flag customer_preferred_cust_flag
+       ,c_birth_country customer_birth_country
+       ,c_login customer_login
+       ,c_email_address customer_email_address
+       ,d_year dyear
+       
,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2)
 ) year_total
+       ,'c' sale_type
+ from customer
+     ,catalog_sales
+     ,date_dim
+ where c_customer_sk = cs_bill_customer_sk
+   and cs_sold_date_sk = d_date_sk
+ group by c_customer_id
+         ,c_first_name
+         ,c_last_name
+         ,c_preferred_cust_flag
+         ,c_birth_country
+         ,c_login
+         ,c_email_address
+         ,d_year
+union all
+ select c_customer_id customer_id
+       ,c_first_name customer_first_name
+       ,c_last_name customer_last_name
+       ,c_preferred_cust_flag customer_preferred_cust_flag
+       ,c_birth_country customer_birth_country
+       ,c_login customer_login
+       ,c_email_address customer_email_address
+       ,d_year dyear
+       
,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2)
 ) year_total
+       ,'w' sale_type
+ from customer
+     ,web_sales
+     ,date_dim
+ where c_customer_sk = ws_bill_customer_sk
+   and ws_sold_date_sk = d_date_sk
+ group by c_customer_id
+         ,c_first_name
+         ,c_last_name
+         ,c_preferred_cust_flag
+         ,c_birth_country
+         ,c_login
+         ,c_email_address
+         ,d_year
+         )
+  select  t_s_secyear.customer_preferred_cust_flag
+ from year_total t_s_firstyear
+     ,year_total t_s_secyear
+     ,year_total t_c_firstyear
+     ,year_total t_c_secyear
+     ,year_total t_w_firstyear
+     ,year_total t_w_secyear
+ where t_s_secyear.customer_id = t_s_firstyear.customer_id
+   and t_s_firstyear.customer_id = t_c_secyear.customer_id
+   and t_s_firstyear.customer_id = t_c_firstyear.customer_id
+   and t_s_firstyear.customer_id = t_w_firstyear.customer_id
+   and t_s_firstyear.customer_id = t_w_secyear.customer_id
+   and t_s_firstyear.sale_type = 's'
+   and t_c_firstyear.sale_type = 'c'
+   and t_w_firstyear.sale_type = 'w'
+   and t_s_secyear.sale_type = 's'
+   and t_c_secyear.sale_type = 'c'
+   and t_w_secyear.sale_type = 'w'
+   and t_s_firstyear.dyear =  2001
+   and t_s_secyear.dyear = 2001+1
+   and t_c_firstyear.dyear =  2001
+   and t_c_secyear.dyear =  2001+1
+   and t_w_firstyear.dyear = 2001
+   and t_w_secyear.dyear = 2001+1
+   and t_s_firstyear.year_total > 0
+   and t_c_firstyear.year_total > 0
+   and t_w_firstyear.year_total > 0
+   and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / 
t_c_firstyear.year_total else null end
+           > case when t_s_firstyear.year_total > 0 then 
t_s_secyear.year_total / t_s_firstyear.year_total else null end
+   and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / 
t_c_firstyear.year_total else null end
+           > case when t_w_firstyear.year_total > 0 then 
t_w_secyear.year_total / t_w_firstyear.year_total else null end
+ order by t_s_secyear.customer_preferred_cust_flag
+limit 100
+POSTHOOK: type: QUERY
+Plan optimized by CBO.
+
+Vertex dependency in root stage
+Reducer 11 <- Map 10 (SIMPLE_EDGE), Map 24 (SIMPLE_EDGE)
+Reducer 12 <- Map 25 (SIMPLE_EDGE), Reducer 11 (SIMPLE_EDGE)
+Reducer 13 <- Reducer 12 (SIMPLE_EDGE)
+Reducer 14 <- Map 10 (SIMPLE_EDGE), Map 24 (SIMPLE_EDGE)
+Reducer 15 <- Map 25 (SIMPLE_EDGE), Reducer 14 (SIMPLE_EDGE)
+Reducer 16 <- Reducer 15 (SIMPLE_EDGE)
+Reducer 18 <- Map 17 (SIMPLE_EDGE), Map 24 (SIMPLE_EDGE)
+Reducer 19 <- Map 25 (SIMPLE_EDGE), Reducer 18 (SIMPLE_EDGE)
+Reducer 2 <- Map 1 (SIMPLE_EDGE), Map 24 (SIMPLE_EDGE)
+Reducer 20 <- Reducer 19 (SIMPLE_EDGE)
+Reducer 21 <- Map 17 (SIMPLE_EDGE), Map 24 (SIMPLE_EDGE)
+Reducer 22 <- Map 25 (SIMPLE_EDGE), Reducer 21 (SIMPLE_EDGE)
+Reducer 23 <- Reducer 22 (SIMPLE_EDGE)
+Reducer 3 <- Map 25 (SIMPLE_EDGE), Reducer 2 (SIMPLE_EDGE)
+Reducer 4 <- Reducer 3 (SIMPLE_EDGE)
+Reducer 5 <- Reducer 13 (SIMPLE_EDGE), Reducer 16 (SIMPLE_EDGE), Reducer 20 
(SIMPLE_EDGE), Reducer 23 (SIMPLE_EDGE), Reducer 4 (SIMPLE_EDGE), Reducer 9 
(SIMPLE_EDGE)
+Reducer 6 <- Reducer 5 (SIMPLE_EDGE)
+Reducer 7 <- Map 1 (SIMPLE_EDGE), Map 24 (SIMPLE_EDGE)
+Reducer 8 <- Map 25 (SIMPLE_EDGE), Reducer 7 (SIMPLE_EDGE)
+Reducer 9 <- Reducer 8 (SIMPLE_EDGE)
+
+Stage-0
+  Fetch Operator
+    limit:100
+    Stage-1
+      Reducer 6
+      File Output Operator [FS_142]
+        Limit [LIM_141] (rows=100 width=88)
+          Number of rows:100
+          Select Operator [SEL_140] (rows=479156399 width=88)
+            Output:["_col0"]
+          <-Reducer 5 [SIMPLE_EDGE]
+            SHUFFLE [RS_139]
+              Select Operator [SEL_138] (rows=479156399 width=88)
+                Output:["_col0"]
+                Filter Operator [FIL_136] (rows=479156399 width=88)
+                  predicate:(CASE WHEN ((_col15 > 0)) THEN (CASE WHEN ((_col23 
> 0)) THEN (((_col39 / _col23) > (_col47 / _col15))) ELSE ((null > (_col47 / 
_col15))) END) ELSE (CASE WHEN ((_col23 > 0)) THEN (((_col39 / _col23) > null)) 
ELSE (null) END) END and CASE WHEN ((_col31 > 0)) THEN (CASE WHEN ((_col23 > 
0)) THEN (((_col39 / _col23) > (_col7 / _col31))) ELSE ((null > (_col7 / 
_col31))) END) ELSE (CASE WHEN ((_col23 > 0)) THEN (((_col39 / _col23) > null)) 
ELSE (null) END) END)
+                  Merge Join Operator [MERGEJOIN_296] (rows=1916625598 
width=88)
+                    
Conds:RS_129._col0=RS_130._col0(Inner),RS_130._col0=RS_131._col0(Inner),RS_130._col0=RS_132._col0(Inner),RS_130._col0=RS_133._col0(Inner),RS_130._col0=RS_134._col0(Inner),Output:["_col7","_col15","_col23","_col31","_col39","_col43","_col47"]
+                  <-Reducer 13 [SIMPLE_EDGE]
+                    SHUFFLE [RS_133]
+                      PartitionCols:_col0
+                      Select Operator [SEL_107] (rows=174233858 width=135)
+                        Output:["_col0","_col7"]
+                        Group By Operator [GBY_106] (rows=174233858 width=135)
+                          
Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6","_col7"],aggregations:["sum(VALUE._col0)"],keys:KEY._col0,
 KEY._col1, KEY._col2, KEY._col3, KEY._col4, KEY._col5, KEY._col6
+                        <-Reducer 12 [SIMPLE_EDGE]
+                          SHUFFLE [RS_105]
+                            PartitionCols:_col0, _col1, _col2, _col3, _col4, 
_col5, _col6
+                            Group By Operator [GBY_104] (rows=348467716 
width=135)
+                              
Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6","_col7"],aggregations:["sum(_col7)"],keys:_col0,
 _col1, _col2, _col3, _col4, _col5, _col6
+                              Select Operator [SEL_102] (rows=348467716 
width=135)
+                                
Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6","_col7"]
+                                Merge Join Operator [MERGEJOIN_293] 
(rows=348467716 width=135)
+                                  
Conds:RS_99._col1=RS_100._col0(Inner),Output:["_col2","_col3","_col4","_col5","_col9","_col10","_col11","_col12","_col13","_col14","_col15"]
+                                <-Map 25 [SIMPLE_EDGE]
+                                  SHUFFLE [RS_100]
+                                    PartitionCols:_col0
+                                    Select Operator [SEL_116] (rows=80000000 
width=860)
+                                      
Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6","_col7"]
+                                      Filter Operator [FIL_280] (rows=80000000 
width=860)
+                                        predicate:(c_customer_id is not null 
and c_customer_sk is not null)
+                                        TableScan [TS_114] (rows=80000000 
width=860)
+                                          
default@customer,customer,Tbl:COMPLETE,Col:NONE,Output:["c_customer_sk","c_customer_id","c_first_name","c_last_name","c_preferred_cust_flag","c_birth_country","c_login","c_email_address"]
+                                <-Reducer 11 [SIMPLE_EDGE]
+                                  SHUFFLE [RS_99]
+                                    PartitionCols:_col1
+                                    Merge Join Operator [MERGEJOIN_292] 
(rows=316788826 width=135)
+                                      
Conds:RS_96._col0=RS_97._col0(Inner),Output:["_col1","_col2","_col3","_col4","_col5"]
+                                    <-Map 24 [SIMPLE_EDGE]
+                                      SHUFFLE [RS_97]
+                                        PartitionCols:_col0
+                                        Select Operator [SEL_113] (rows=36524 
width=1119)
+                                          Output:["_col0"]
+                                          Filter Operator [FIL_279] 
(rows=36524 width=1119)
+                                            predicate:((d_year = 2002) and 
d_date_sk is not null)
+                                            TableScan [TS_111] (rows=73049 
width=1119)
+                                              
default@date_dim,date_dim,Tbl:COMPLETE,Col:NONE,Output:["d_date_sk","d_year"]
+                                    <-Map 10 [SIMPLE_EDGE]
+                                      SHUFFLE [RS_96]
+                                        PartitionCols:_col0
+                                        Select Operator [SEL_89] 
(rows=287989836 width=135)
+                                          
Output:["_col0","_col1","_col2","_col3","_col4","_col5"]
+                                          Filter Operator [FIL_275] 
(rows=287989836 width=135)
+                                            predicate:(cs_bill_customer_sk is 
not null and cs_sold_date_sk is not null)
+                                            TableScan [TS_87] (rows=287989836 
width=135)
+                                              
default@catalog_sales,catalog_sales,Tbl:COMPLETE,Col:NONE,Output:["cs_sold_date_sk","cs_bill_customer_sk","cs_ext_discount_amt","cs_ext_sales_price","cs_ext_wholesale_cost","cs_ext_list_price"]
+                  <-Reducer 16 [SIMPLE_EDGE]
+                    SHUFFLE [RS_131]
+                      PartitionCols:_col0
+                      Filter Operator [FIL_63] (rows=58077952 width=135)
+                        predicate:(_col7 > 0)
+                        Select Operator [SEL_281] (rows=174233858 width=135)
+                          Output:["_col0","_col7"]
+                          Group By Operator [GBY_62] (rows=174233858 width=135)
+                            
Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6","_col7"],aggregations:["sum(VALUE._col0)"],keys:KEY._col0,
 KEY._col1, KEY._col2, KEY._col3, KEY._col4, KEY._col5, KEY._col6
+                          <-Reducer 15 [SIMPLE_EDGE]
+                            SHUFFLE [RS_61]
+                              PartitionCols:_col0, _col1, _col2, _col3, _col4, 
_col5, _col6
+                              Group By Operator [GBY_60] (rows=348467716 
width=135)
+                                
Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6","_col7"],aggregations:["sum(_col7)"],keys:_col0,
 _col1, _col2, _col3, _col4, _col5, _col6
+                                Select Operator [SEL_58] (rows=348467716 
width=135)
+                                  
Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6","_col7"]
+                                  Merge Join Operator [MERGEJOIN_289] 
(rows=348467716 width=135)
+                                    
Conds:RS_55._col1=RS_56._col0(Inner),Output:["_col2","_col3","_col4","_col5","_col9","_col10","_col11","_col12","_col13","_col14","_col15"]
+                                  <-Map 25 [SIMPLE_EDGE]
+                                    SHUFFLE [RS_56]
+                                      PartitionCols:_col0
+                                       Please refer to the previous Select 
Operator [SEL_116]
+                                  <-Reducer 14 [SIMPLE_EDGE]
+                                    SHUFFLE [RS_55]
+                                      PartitionCols:_col1
+                                      Merge Join Operator [MERGEJOIN_288] 
(rows=316788826 width=135)
+                                        
Conds:RS_52._col0=RS_53._col0(Inner),Output:["_col1","_col2","_col3","_col4","_col5"]
+                                      <-Map 24 [SIMPLE_EDGE]
+                                        SHUFFLE [RS_53]
+                                          PartitionCols:_col0
+                                          Select Operator [SEL_48] (rows=36524 
width=1119)
+                                            Output:["_col0"]
+                                            Filter Operator [FIL_270] 
(rows=36524 width=1119)
+                                              predicate:((d_year = 2001) and 
d_date_sk is not null)
+                                               Please refer to the previous 
TableScan [TS_111]
+                                      <-Map 10 [SIMPLE_EDGE]
+                                        SHUFFLE [RS_52]
+                                          PartitionCols:_col0
+                                           Please refer to the previous Select 
Operator [SEL_89]
+                  <-Reducer 20 [SIMPLE_EDGE]
+                    SHUFFLE [RS_134]
+                      PartitionCols:_col0
+                      Select Operator [SEL_128] (rows=348477374 width=88)
+                        Output:["_col0","_col3","_col7"]
+                        Group By Operator [GBY_127] (rows=348477374 width=88)
+                          
Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6","_col7"],aggregations:["sum(VALUE._col0)"],keys:KEY._col0,
 KEY._col1, KEY._col2, KEY._col3, KEY._col4, KEY._col5, KEY._col6
+                        <-Reducer 19 [SIMPLE_EDGE]
+                          SHUFFLE [RS_126]
+                            PartitionCols:_col0, _col1, _col2, _col3, _col4, 
_col5, _col6
+                            Group By Operator [GBY_125] (rows=696954748 
width=88)
+                              
Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6","_col7"],aggregations:["sum(_col7)"],keys:_col0,
 _col1, _col2, _col3, _col4, _col5, _col6
+                              Select Operator [SEL_123] (rows=696954748 
width=88)
+                                
Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6","_col7"]
+                                Merge Join Operator [MERGEJOIN_295] 
(rows=696954748 width=88)
+                                  
Conds:RS_120._col1=RS_121._col0(Inner),Output:["_col2","_col3","_col4","_col5","_col9","_col10","_col11","_col12","_col13","_col14","_col15"]
+                                <-Map 25 [SIMPLE_EDGE]
+                                  SHUFFLE [RS_121]
+                                    PartitionCols:_col0
+                                     Please refer to the previous Select 
Operator [SEL_116]
+                                <-Reducer 18 [SIMPLE_EDGE]
+                                  SHUFFLE [RS_120]
+                                    PartitionCols:_col1
+                                    Merge Join Operator [MERGEJOIN_294] 
(rows=633595212 width=88)
+                                      
Conds:RS_117._col0=RS_118._col0(Inner),Output:["_col1","_col2","_col3","_col4","_col5"]
+                                    <-Map 24 [SIMPLE_EDGE]
+                                      SHUFFLE [RS_118]
+                                        PartitionCols:_col0
+                                         Please refer to the previous Select 
Operator [SEL_113]
+                                    <-Map 17 [SIMPLE_EDGE]
+                                      SHUFFLE [RS_117]
+                                        PartitionCols:_col0
+                                        Select Operator [SEL_110] 
(rows=575995635 width=88)
+                                          
Output:["_col0","_col1","_col2","_col3","_col4","_col5"]
+                                          Filter Operator [FIL_278] 
(rows=575995635 width=88)
+                                            predicate:(ss_customer_sk is not 
null and ss_sold_date_sk is not null)
+                                            TableScan [TS_108] (rows=575995635 
width=88)
+                                              
default@store_sales,store_sales,Tbl:COMPLETE,Col:NONE,Output:["ss_sold_date_sk","ss_customer_sk","ss_ext_discount_amt","ss_ext_sales_price","ss_ext_wholesale_cost","ss_ext_list_price"]
+                  <-Reducer 23 [SIMPLE_EDGE]
+                    SHUFFLE [RS_130]
+                      PartitionCols:_col0
+                      Filter Operator [FIL_41] (rows=116159124 width=88)
+                        predicate:(_col7 > 0)
+                        Select Operator [SEL_283] (rows=348477374 width=88)
+                          Output:["_col0","_col7"]
+                          Group By Operator [GBY_40] (rows=348477374 width=88)
+                            
Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6","_col7"],aggregations:["sum(VALUE._col0)"],keys:KEY._col0,
 KEY._col1, KEY._col2, KEY._col3, KEY._col4, KEY._col5, KEY._col6
+                          <-Reducer 22 [SIMPLE_EDGE]
+                            SHUFFLE [RS_39]
+                              PartitionCols:_col0, _col1, _col2, _col3, _col4, 
_col5, _col6
+                              Group By Operator [GBY_38] (rows=696954748 
width=88)
+                                
Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6","_col7"],aggregations:["sum(_col7)"],keys:_col0,
 _col1, _col2, _col3, _col4, _col5, _col6
+                                Select Operator [SEL_36] (rows=696954748 
width=88)
+                                  
Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6","_col7"]
+                                  Merge Join Operator [MERGEJOIN_287] 
(rows=696954748 width=88)
+                                    
Conds:RS_33._col1=RS_34._col0(Inner),Output:["_col2","_col3","_col4","_col5","_col9","_col10","_col11","_col12","_col13","_col14","_col15"]
+                                  <-Map 25 [SIMPLE_EDGE]
+                                    SHUFFLE [RS_34]
+                                      PartitionCols:_col0
+                                       Please refer to the previous Select 
Operator [SEL_116]
+                                  <-Reducer 21 [SIMPLE_EDGE]
+                                    SHUFFLE [RS_33]
+                                      PartitionCols:_col1
+                                      Merge Join Operator [MERGEJOIN_286] 
(rows=633595212 width=88)
+                                        
Conds:RS_30._col0=RS_31._col0(Inner),Output:["_col1","_col2","_col3","_col4","_col5"]
+                                      <-Map 24 [SIMPLE_EDGE]
+                                        SHUFFLE [RS_31]
+                                          PartitionCols:_col0
+                                          Select Operator [SEL_26] (rows=36524 
width=1119)
+                                            Output:["_col0"]
+                                            Filter Operator [FIL_267] 
(rows=36524 width=1119)
+                                              predicate:((d_year = 2001) and 
d_date_sk is not null)
+                                               Please refer to the previous 
TableScan [TS_111]
+                                      <-Map 17 [SIMPLE_EDGE]
+                                        SHUFFLE [RS_30]
+                                          PartitionCols:_col0
+                                           Please refer to the previous Select 
Operator [SEL_110]
+                  <-Reducer 4 [SIMPLE_EDGE]
+                    SHUFFLE [RS_129]
+                      PartitionCols:_col0
+                      Select Operator [SEL_20] (rows=87121617 width=135)
+                        Output:["_col0","_col7"]
+                        Group By Operator [GBY_19] (rows=87121617 width=135)
+                          
Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6","_col7"],aggregations:["sum(VALUE._col0)"],keys:KEY._col0,
 KEY._col1, KEY._col2, KEY._col3, KEY._col4, KEY._col5, KEY._col6
+                        <-Reducer 3 [SIMPLE_EDGE]
+                          SHUFFLE [RS_18]
+                            PartitionCols:_col0, _col1, _col2, _col3, _col4, 
_col5, _col6
+                            Group By Operator [GBY_17] (rows=174243235 
width=135)
+                              
Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6","_col7"],aggregations:["sum(_col7)"],keys:_col0,
 _col1, _col2, _col3, _col4, _col5, _col6
+                              Select Operator [SEL_15] (rows=174243235 
width=135)
+                                
Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6","_col7"]
+                                Merge Join Operator [MERGEJOIN_285] 
(rows=174243235 width=135)
+                                  
Conds:RS_12._col1=RS_13._col0(Inner),Output:["_col2","_col3","_col4","_col5","_col9","_col10","_col11","_col12","_col13","_col14","_col15"]
+                                <-Map 25 [SIMPLE_EDGE]
+                                  SHUFFLE [RS_13]
+                                    PartitionCols:_col0
+                                     Please refer to the previous Select 
Operator [SEL_116]
+                                <-Reducer 2 [SIMPLE_EDGE]
+                                  SHUFFLE [RS_12]
+                                    PartitionCols:_col1
+                                    Merge Join Operator [MERGEJOIN_284] 
(rows=158402938 width=135)
+                                      
Conds:RS_9._col0=RS_10._col0(Inner),Output:["_col1","_col2","_col3","_col4","_col5"]
+                                    <-Map 24 [SIMPLE_EDGE]
+                                      SHUFFLE [RS_10]
+                                        PartitionCols:_col0
+                                         Please refer to the previous Select 
Operator [SEL_113]
+                                    <-Map 1 [SIMPLE_EDGE]
+                                      SHUFFLE [RS_9]
+                                        PartitionCols:_col0
+                                        Select Operator [SEL_2] 
(rows=144002668 width=135)
+                                          
Output:["_col0","_col1","_col2","_col3","_col4","_col5"]
+                                          Filter Operator [FIL_263] 
(rows=144002668 width=135)
+                                            predicate:(ws_bill_customer_sk is 
not null and ws_sold_date_sk is not null)
+                                            TableScan [TS_0] (rows=144002668 
width=135)
+                                              
default@web_sales,web_sales,Tbl:COMPLETE,Col:NONE,Output:["ws_sold_date_sk","ws_bill_customer_sk","ws_ext_discount_amt","ws_ext_sales_price","ws_ext_wholesale_cost","ws_ext_list_price"]
+                  <-Reducer 9 [SIMPLE_EDGE]
+                    SHUFFLE [RS_132]
+                      PartitionCols:_col0
+                      Filter Operator [FIL_85] (rows=29040539 width=135)
+                        predicate:(_col7 > 0)
+                        Select Operator [SEL_282] (rows=87121617 width=135)
+                          Output:["_col0","_col7"]
+                          Group By Operator [GBY_84] (rows=87121617 width=135)
+                            
Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6","_col7"],aggregations:["sum(VALUE._col0)"],keys:KEY._col0,
 KEY._col1, KEY._col2, KEY._col3, KEY._col4, KEY._col5, KEY._col6
+                          <-Reducer 8 [SIMPLE_EDGE]
+                            SHUFFLE [RS_83]
+                              PartitionCols:_col0, _col1, _col2, _col3, _col4, 
_col5, _col6
+                              Group By Operator [GBY_82] (rows=174243235 
width=135)
+                                
Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6","_col7"],aggregations:["sum(_col7)"],keys:_col0,
 _col1, _col2, _col3, _col4, _col5, _col6
+                                Select Operator [SEL_80] (rows=174243235 
width=135)
+                                  
Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6","_col7"]
+                                  Merge Join Operator [MERGEJOIN_291] 
(rows=174243235 width=135)
+                                    
Conds:RS_77._col1=RS_78._col0(Inner),Output:["_col2","_col3","_col4","_col5","_col9","_col10","_col11","_col12","_col13","_col14","_col15"]
+                                  <-Map 25 [SIMPLE_EDGE]
+                                    SHUFFLE [RS_78]
+                                      PartitionCols:_col0
+                                       Please refer to the previous Select 
Operator [SEL_116]
+                                  <-Reducer 7 [SIMPLE_EDGE]
+                                    SHUFFLE [RS_77]
+                                      PartitionCols:_col1
+                                      Merge Join Operator [MERGEJOIN_290] 
(rows=158402938 width=135)
+                                        
Conds:RS_74._col0=RS_75._col0(Inner),Output:["_col1","_col2","_col3","_col4","_col5"]
+                                      <-Map 24 [SIMPLE_EDGE]
+                                        SHUFFLE [RS_75]
+                                          PartitionCols:_col0
+                                          Select Operator [SEL_70] (rows=36524 
width=1119)
+                                            Output:["_col0"]
+                                            Filter Operator [FIL_273] 
(rows=36524 width=1119)
+                                              predicate:((d_year = 2001) and 
d_date_sk is not null)
+                                               Please refer to the previous 
TableScan [TS_111]
+                                      <-Map 1 [SIMPLE_EDGE]
+                                        SHUFFLE [RS_74]
+                                          PartitionCols:_col0
+                                           Please refer to the previous Select 
Operator [SEL_2]
+

http://git-wip-us.apache.org/repos/asf/hive/blob/9244fdc7/ql/src/test/results/clientpositive/perf/tez/query40.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/perf/tez/query40.q.out 
b/ql/src/test/results/clientpositive/perf/tez/query40.q.out
new file mode 100644
index 0000000..604f741
--- /dev/null
+++ b/ql/src/test/results/clientpositive/perf/tez/query40.q.out
@@ -0,0 +1,148 @@
+PREHOOK: query: explain
+select  
+   w_state
+  ,i_item_id
+  ,sum(case when (cast(d_date as date) < cast ('1998-04-08' as date)) 
+               then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) 
as sales_before
+  ,sum(case when (cast(d_date as date) >= cast ('1998-04-08' as date)) 
+               then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) 
as sales_after
+ from
+   catalog_sales left outer join catalog_returns on
+       (cs_order_number = cr_order_number 
+        and cs_item_sk = cr_item_sk)
+  ,warehouse 
+  ,item
+  ,date_dim
+ where
+     i_current_price between 0.99 and 1.49
+ and i_item_sk          = cs_item_sk
+ and cs_warehouse_sk    = w_warehouse_sk 
+ and cs_sold_date_sk    = d_date_sk
+ and d_date between (cast ('1998-04-08' as date) - 30 days)
+                and (cast ('1998-04-08' as date) + 30 days) 
+ group by
+    w_state,i_item_id
+ order by w_state,i_item_id
+limit 100
+PREHOOK: type: QUERY
+POSTHOOK: query: explain
+select  
+   w_state
+  ,i_item_id
+  ,sum(case when (cast(d_date as date) < cast ('1998-04-08' as date)) 
+               then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) 
as sales_before
+  ,sum(case when (cast(d_date as date) >= cast ('1998-04-08' as date)) 
+               then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) 
as sales_after
+ from
+   catalog_sales left outer join catalog_returns on
+       (cs_order_number = cr_order_number 
+        and cs_item_sk = cr_item_sk)
+  ,warehouse 
+  ,item
+  ,date_dim
+ where
+     i_current_price between 0.99 and 1.49
+ and i_item_sk          = cs_item_sk
+ and cs_warehouse_sk    = w_warehouse_sk 
+ and cs_sold_date_sk    = d_date_sk
+ and d_date between (cast ('1998-04-08' as date) - 30 days)
+                and (cast ('1998-04-08' as date) + 30 days) 
+ group by
+    w_state,i_item_id
+ order by w_state,i_item_id
+limit 100
+POSTHOOK: type: QUERY
+Plan optimized by CBO.
+
+Vertex dependency in root stage
+Reducer 2 <- Map 1 (SIMPLE_EDGE), Map 8 (SIMPLE_EDGE)
+Reducer 3 <- Map 9 (SIMPLE_EDGE), Reducer 2 (SIMPLE_EDGE)
+Reducer 4 <- Map 10 (SIMPLE_EDGE), Reducer 3 (SIMPLE_EDGE)
+Reducer 5 <- Map 11 (SIMPLE_EDGE), Reducer 4 (SIMPLE_EDGE)
+Reducer 6 <- Reducer 5 (SIMPLE_EDGE)
+Reducer 7 <- Reducer 6 (SIMPLE_EDGE)
+
+Stage-0
+  Fetch Operator
+    limit:100
+    Stage-1
+      Reducer 7
+      File Output Operator [FS_36]
+        Limit [LIM_35] (rows=100 width=135)
+          Number of rows:100
+          Select Operator [SEL_34] (rows=210822976 width=135)
+            Output:["_col0","_col1","_col2","_col3"]
+          <-Reducer 6 [SIMPLE_EDGE]
+            SHUFFLE [RS_33]
+              Group By Operator [GBY_31] (rows=210822976 width=135)
+                
Output:["_col0","_col1","_col2","_col3"],aggregations:["sum(VALUE._col0)","sum(VALUE._col1)"],keys:KEY._col0,
 KEY._col1
+              <-Reducer 5 [SIMPLE_EDGE]
+                SHUFFLE [RS_30]
+                  PartitionCols:_col0, _col1
+                  Group By Operator [GBY_29] (rows=421645953 width=135)
+                    
Output:["_col0","_col1","_col2","_col3"],aggregations:["sum(_col2)","sum(_col3)"],keys:_col0,
 _col1
+                    Select Operator [SEL_27] (rows=421645953 width=135)
+                      Output:["_col0","_col1","_col2","_col3"]
+                      Merge Join Operator [MERGEJOIN_58] (rows=421645953 
width=135)
+                        
Conds:RS_24._col1=RS_25._col0(Inner),Output:["_col4","_col7","_col9","_col11","_col14"]
+                      <-Map 11 [SIMPLE_EDGE]
+                        SHUFFLE [RS_25]
+                          PartitionCols:_col0
+                          Select Operator [SEL_14] (rows=27 width=1029)
+                            Output:["_col0","_col1"]
+                            Filter Operator [FIL_54] (rows=27 width=1029)
+                              predicate:w_warehouse_sk is not null
+                              TableScan [TS_12] (rows=27 width=1029)
+                                
default@warehouse,warehouse,Tbl:COMPLETE,Col:NONE,Output:["w_warehouse_sk","w_state"]
+                      <-Reducer 4 [SIMPLE_EDGE]
+                        SHUFFLE [RS_24]
+                          PartitionCols:_col1
+                          Merge Join Operator [MERGEJOIN_57] (rows=383314495 
width=135)
+                            
Conds:RS_21._col2=RS_22._col0(Inner),Output:["_col1","_col4","_col7","_col9","_col11"]
+                          <-Map 10 [SIMPLE_EDGE]
+                            SHUFFLE [RS_22]
+                              PartitionCols:_col0
+                              Select Operator [SEL_11] (rows=51333 width=1436)
+                                Output:["_col0","_col1"]
+                                Filter Operator [FIL_53] (rows=51333 
width=1436)
+                                  predicate:(i_current_price BETWEEN 0.99 AND 
1.49 and i_item_sk is not null)
+                                  TableScan [TS_9] (rows=462000 width=1436)
+                                    
default@item,item,Tbl:COMPLETE,Col:NONE,Output:["i_item_sk","i_item_id","i_current_price"]
+                          <-Reducer 3 [SIMPLE_EDGE]
+                            SHUFFLE [RS_21]
+                              PartitionCols:_col2
+                              Merge Join Operator [MERGEJOIN_56] 
(rows=348467716 width=135)
+                                
Conds:RS_18._col0=RS_19._col0(Inner),Output:["_col1","_col2","_col4","_col7","_col9"]
+                              <-Map 9 [SIMPLE_EDGE]
+                                SHUFFLE [RS_19]
+                                  PartitionCols:_col0
+                                  Select Operator [SEL_8] (rows=8116 
width=1119)
+                                    Output:["_col0","_col1"]
+                                    Filter Operator [FIL_52] (rows=8116 
width=1119)
+                                      predicate:(CAST( d_date AS TIMESTAMP) 
BETWEEN 1998-03-08 23:00:00.0 AND 1998-05-08 00:00:00.0 and d_date_sk is not 
null)
+                                      TableScan [TS_6] (rows=73049 width=1119)
+                                        
default@date_dim,date_dim,Tbl:COMPLETE,Col:NONE,Output:["d_date_sk","d_date"]
+                              <-Reducer 2 [SIMPLE_EDGE]
+                                SHUFFLE [RS_18]
+                                  PartitionCols:_col0
+                                  Merge Join Operator [MERGEJOIN_55] 
(rows=316788826 width=135)
+                                    Conds:RS_15._col2, _col3=RS_16._col0, 
_col1(Left Outer),Output:["_col0","_col1","_col2","_col4","_col7"]
+                                  <-Map 1 [SIMPLE_EDGE]
+                                    SHUFFLE [RS_15]
+                                      PartitionCols:_col2, _col3
+                                      Select Operator [SEL_2] (rows=287989836 
width=135)
+                                        
Output:["_col0","_col1","_col2","_col3","_col4"]
+                                        Filter Operator [FIL_50] 
(rows=287989836 width=135)
+                                          predicate:(cs_item_sk is not null 
and cs_sold_date_sk is not null and cs_warehouse_sk is not null)
+                                          TableScan [TS_0] (rows=287989836 
width=135)
+                                            
default@catalog_sales,catalog_sales,Tbl:COMPLETE,Col:NONE,Output:["cs_sold_date_sk","cs_warehouse_sk","cs_item_sk","cs_order_number","cs_sales_price"]
+                                  <-Map 8 [SIMPLE_EDGE]
+                                    SHUFFLE [RS_16]
+                                      PartitionCols:_col0, _col1
+                                      Select Operator [SEL_5] (rows=28798881 
width=106)
+                                        Output:["_col0","_col1","_col2"]
+                                        Filter Operator [FIL_51] 
(rows=28798881 width=106)
+                                          predicate:cr_item_sk is not null
+                                          TableScan [TS_3] (rows=28798881 
width=106)
+                                            
default@catalog_returns,catalog_returns,Tbl:COMPLETE,Col:NONE,Output:["cr_item_sk","cr_order_number","cr_refunded_cash"]
+

http://git-wip-us.apache.org/repos/asf/hive/blob/9244fdc7/ql/src/test/results/clientpositive/perf/tez/query42.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/perf/tez/query42.q.out 
b/ql/src/test/results/clientpositive/perf/tez/query42.q.out
new file mode 100644
index 0000000..f31a62d
--- /dev/null
+++ b/ql/src/test/results/clientpositive/perf/tez/query42.q.out
@@ -0,0 +1,108 @@
+PREHOOK: query: explain
+select  dt.d_year
+       ,item.i_category_id
+       ,item.i_category
+       ,sum(ss_ext_sales_price)
+ from  date_dim dt
+       ,store_sales
+       ,item
+ where dt.d_date_sk = store_sales.ss_sold_date_sk
+       and store_sales.ss_item_sk = item.i_item_sk
+       and item.i_manager_id = 1       
+       and dt.d_moy=12
+       and dt.d_year=1998
+ group by      dt.d_year
+               ,item.i_category_id
+               ,item.i_category
+ order by       sum(ss_ext_sales_price) desc,dt.d_year
+               ,item.i_category_id
+               ,item.i_category
+limit 100
+PREHOOK: type: QUERY
+POSTHOOK: query: explain
+select  dt.d_year
+       ,item.i_category_id
+       ,item.i_category
+       ,sum(ss_ext_sales_price)
+ from  date_dim dt
+       ,store_sales
+       ,item
+ where dt.d_date_sk = store_sales.ss_sold_date_sk
+       and store_sales.ss_item_sk = item.i_item_sk
+       and item.i_manager_id = 1       
+       and dt.d_moy=12
+       and dt.d_year=1998
+ group by      dt.d_year
+               ,item.i_category_id
+               ,item.i_category
+ order by       sum(ss_ext_sales_price) desc,dt.d_year
+               ,item.i_category_id
+               ,item.i_category
+limit 100
+POSTHOOK: type: QUERY
+Plan optimized by CBO.
+
+Vertex dependency in root stage
+Reducer 2 <- Map 1 (SIMPLE_EDGE), Map 6 (SIMPLE_EDGE)
+Reducer 3 <- Map 7 (SIMPLE_EDGE), Reducer 2 (SIMPLE_EDGE)
+Reducer 4 <- Reducer 3 (SIMPLE_EDGE)
+Reducer 5 <- Reducer 4 (SIMPLE_EDGE)
+
+Stage-0
+  Fetch Operator
+    limit:-1
+    Stage-1
+      Reducer 5
+      File Output Operator [FS_24]
+        Select Operator [SEL_23] (rows=100 width=88)
+          Output:["_col0","_col1","_col2","_col3"]
+          Limit [LIM_22] (rows=100 width=88)
+            Number of rows:100
+            Select Operator [SEL_21] (rows=348477374 width=88)
+              Output:["_col0","_col1","_col2"]
+            <-Reducer 4 [SIMPLE_EDGE]
+              SHUFFLE [RS_20]
+                Select Operator [SEL_19] (rows=348477374 width=88)
+                  Output:["_col0","_col1","_col3"]
+                  Group By Operator [GBY_18] (rows=348477374 width=88)
+                    
Output:["_col0","_col1","_col2"],aggregations:["sum(VALUE._col0)"],keys:KEY._col0,
 KEY._col1
+                  <-Reducer 3 [SIMPLE_EDGE]
+                    SHUFFLE [RS_17]
+                      PartitionCols:_col0, _col1
+                      Group By Operator [GBY_16] (rows=696954748 width=88)
+                        
Output:["_col0","_col1","_col2"],aggregations:["sum(_col2)"],keys:_col7, _col8
+                        Merge Join Operator [MERGEJOIN_34] (rows=696954748 
width=88)
+                          
Conds:RS_12._col1=RS_13._col0(Inner),Output:["_col2","_col7","_col8"]
+                        <-Map 7 [SIMPLE_EDGE]
+                          SHUFFLE [RS_13]
+                            PartitionCols:_col0
+                            Select Operator [SEL_8] (rows=231000 width=1436)
+                              Output:["_col0","_col1","_col2"]
+                              Filter Operator [FIL_32] (rows=231000 width=1436)
+                                predicate:((i_manager_id = 1) and i_item_sk is 
not null)
+                                TableScan [TS_6] (rows=462000 width=1436)
+                                  
default@item,item,Tbl:COMPLETE,Col:NONE,Output:["i_item_sk","i_category_id","i_category","i_manager_id"]
+                        <-Reducer 2 [SIMPLE_EDGE]
+                          SHUFFLE [RS_12]
+                            PartitionCols:_col1
+                            Merge Join Operator [MERGEJOIN_33] (rows=633595212 
width=88)
+                              
Conds:RS_9._col0=RS_10._col0(Inner),Output:["_col1","_col2"]
+                            <-Map 1 [SIMPLE_EDGE]
+                              SHUFFLE [RS_9]
+                                PartitionCols:_col0
+                                Select Operator [SEL_2] (rows=575995635 
width=88)
+                                  Output:["_col0","_col1","_col2"]
+                                  Filter Operator [FIL_30] (rows=575995635 
width=88)
+                                    predicate:(ss_item_sk is not null and 
ss_sold_date_sk is not null)
+                                    TableScan [TS_0] (rows=575995635 width=88)
+                                      
default@store_sales,store_sales,Tbl:COMPLETE,Col:NONE,Output:["ss_sold_date_sk","ss_item_sk","ss_ext_sales_price"]
+                            <-Map 6 [SIMPLE_EDGE]
+                              SHUFFLE [RS_10]
+                                PartitionCols:_col0
+                                Select Operator [SEL_5] (rows=18262 width=1119)
+                                  Output:["_col0"]
+                                  Filter Operator [FIL_31] (rows=18262 
width=1119)
+                                    predicate:((d_moy = 12) and (d_year = 
1998) and d_date_sk is not null)
+                                    TableScan [TS_3] (rows=73049 width=1119)
+                                      
default@date_dim,dt,Tbl:COMPLETE,Col:NONE,Output:["d_date_sk","d_year","d_moy"]
+

http://git-wip-us.apache.org/repos/asf/hive/blob/9244fdc7/ql/src/test/results/clientpositive/perf/tez/query43.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/perf/tez/query43.q.out 
b/ql/src/test/results/clientpositive/perf/tez/query43.q.out
new file mode 100644
index 0000000..6db0919
--- /dev/null
+++ b/ql/src/test/results/clientpositive/perf/tez/query43.q.out
@@ -0,0 +1,100 @@
+PREHOOK: query: explain
+select  s_store_name, s_store_id,
+        sum(case when (d_day_name='Sunday') then ss_sales_price else null end) 
sun_sales,
+        sum(case when (d_day_name='Monday') then ss_sales_price else null end) 
mon_sales,
+        sum(case when (d_day_name='Tuesday') then ss_sales_price else  null 
end) tue_sales,
+        sum(case when (d_day_name='Wednesday') then ss_sales_price else null 
end) wed_sales,
+        sum(case when (d_day_name='Thursday') then ss_sales_price else null 
end) thu_sales,
+        sum(case when (d_day_name='Friday') then ss_sales_price else null end) 
fri_sales,
+        sum(case when (d_day_name='Saturday') then ss_sales_price else null 
end) sat_sales
+ from date_dim, store_sales, store
+ where d_date_sk = ss_sold_date_sk and
+       s_store_sk = ss_store_sk and
+       s_gmt_offset = -6 and
+       d_year = 1998 
+ group by s_store_name, s_store_id
+ order by s_store_name, 
s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales
+ limit 100
+PREHOOK: type: QUERY
+POSTHOOK: query: explain
+select  s_store_name, s_store_id,
+        sum(case when (d_day_name='Sunday') then ss_sales_price else null end) 
sun_sales,
+        sum(case when (d_day_name='Monday') then ss_sales_price else null end) 
mon_sales,
+        sum(case when (d_day_name='Tuesday') then ss_sales_price else  null 
end) tue_sales,
+        sum(case when (d_day_name='Wednesday') then ss_sales_price else null 
end) wed_sales,
+        sum(case when (d_day_name='Thursday') then ss_sales_price else null 
end) thu_sales,
+        sum(case when (d_day_name='Friday') then ss_sales_price else null end) 
fri_sales,
+        sum(case when (d_day_name='Saturday') then ss_sales_price else null 
end) sat_sales
+ from date_dim, store_sales, store
+ where d_date_sk = ss_sold_date_sk and
+       s_store_sk = ss_store_sk and
+       s_gmt_offset = -6 and
+       d_year = 1998 
+ group by s_store_name, s_store_id
+ order by s_store_name, 
s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales
+ limit 100
+POSTHOOK: type: QUERY
+Plan optimized by CBO.
+
+Vertex dependency in root stage
+Reducer 2 <- Map 1 (SIMPLE_EDGE), Map 6 (SIMPLE_EDGE)
+Reducer 3 <- Map 7 (SIMPLE_EDGE), Reducer 2 (SIMPLE_EDGE)
+Reducer 4 <- Reducer 3 (SIMPLE_EDGE)
+Reducer 5 <- Reducer 4 (SIMPLE_EDGE)
+
+Stage-0
+  Fetch Operator
+    limit:100
+    Stage-1
+      Reducer 5
+      File Output Operator [FS_24]
+        Limit [LIM_23] (rows=100 width=88)
+          Number of rows:100
+          Select Operator [SEL_22] (rows=348477374 width=88)
+            
Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6","_col7","_col8"]
+          <-Reducer 4 [SIMPLE_EDGE]
+            SHUFFLE [RS_21]
+              Group By Operator [GBY_19] (rows=348477374 width=88)
+                
Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6","_col7","_col8"],aggregations:["sum(VALUE._col0)","sum(VALUE._col1)","sum(VALUE._col2)","sum(VALUE._col3)","sum(VALUE._col4)","sum(VALUE._col5)","sum(VALUE._col6)"],keys:KEY._col0,
 KEY._col1
+              <-Reducer 3 [SIMPLE_EDGE]
+                SHUFFLE [RS_18]
+                  PartitionCols:_col0, _col1
+                  Group By Operator [GBY_17] (rows=696954748 width=88)
+                    
Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6","_col7","_col8"],aggregations:["sum(_col2)","sum(_col3)","sum(_col4)","sum(_col5)","sum(_col6)","sum(_col7)","sum(_col8)"],keys:_col0,
 _col1
+                    Select Operator [SEL_15] (rows=696954748 width=88)
+                      
Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6","_col7","_col8"]
+                      Merge Join Operator [MERGEJOIN_34] (rows=696954748 
width=88)
+                        
Conds:RS_12._col1=RS_13._col0(Inner),Output:["_col2","_col5","_col7","_col8"]
+                      <-Map 7 [SIMPLE_EDGE]
+                        SHUFFLE [RS_13]
+                          PartitionCols:_col0
+                          Select Operator [SEL_8] (rows=852 width=1910)
+                            Output:["_col0","_col1","_col2"]
+                            Filter Operator [FIL_32] (rows=852 width=1910)
+                              predicate:((s_gmt_offset = -6) and s_store_sk is 
not null)
+                              TableScan [TS_6] (rows=1704 width=1910)
+                                
default@store,store,Tbl:COMPLETE,Col:NONE,Output:["s_store_sk","s_store_id","s_store_name","s_gmt_offset"]
+                      <-Reducer 2 [SIMPLE_EDGE]
+                        SHUFFLE [RS_12]
+                          PartitionCols:_col1
+                          Merge Join Operator [MERGEJOIN_33] (rows=633595212 
width=88)
+                            
Conds:RS_9._col0=RS_10._col0(Inner),Output:["_col1","_col2","_col5"]
+                          <-Map 1 [SIMPLE_EDGE]
+                            SHUFFLE [RS_9]
+                              PartitionCols:_col0
+                              Select Operator [SEL_2] (rows=575995635 width=88)
+                                Output:["_col0","_col1","_col2"]
+                                Filter Operator [FIL_30] (rows=575995635 
width=88)
+                                  predicate:(ss_sold_date_sk is not null and 
ss_store_sk is not null)
+                                  TableScan [TS_0] (rows=575995635 width=88)
+                                    
default@store_sales,store_sales,Tbl:COMPLETE,Col:NONE,Output:["ss_sold_date_sk","ss_store_sk","ss_sales_price"]
+                          <-Map 6 [SIMPLE_EDGE]
+                            SHUFFLE [RS_10]
+                              PartitionCols:_col0
+                              Select Operator [SEL_5] (rows=36524 width=1119)
+                                Output:["_col0","_col2"]
+                                Filter Operator [FIL_31] (rows=36524 
width=1119)
+                                  predicate:((d_year = 1998) and d_date_sk is 
not null)
+                                  TableScan [TS_3] (rows=73049 width=1119)
+                                    
default@date_dim,date_dim,Tbl:COMPLETE,Col:NONE,Output:["d_date_sk","d_year","d_day_name"]
+

http://git-wip-us.apache.org/repos/asf/hive/blob/9244fdc7/ql/src/test/results/clientpositive/perf/tez/query44.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/perf/tez/query44.q.out 
b/ql/src/test/results/clientpositive/perf/tez/query44.q.out
new file mode 100644
index 0000000..07187b1
--- /dev/null
+++ b/ql/src/test/results/clientpositive/perf/tez/query44.q.out
@@ -0,0 +1,258 @@
+Warning: Shuffle Join MERGEJOIN[131][tables = [$hdt$_2, $hdt$_3, $hdt$_1]] in 
Stage 'Reducer 9' is a cross product
+Warning: Shuffle Join MERGEJOIN[133][tables = [$hdt$_4, $hdt$_5, $hdt$_3]] in 
Stage 'Reducer 13' is a cross product
+PREHOOK: query: explain
+select  asceding.rnk, i1.i_product_name best_performing, i2.i_product_name 
worst_performing
+from(select *
+     from (select item_sk,rank() over (order by rank_col asc) rnk
+           from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col 
+                 from store_sales ss1
+                 where ss_store_sk = 410
+                 group by ss_item_sk
+                 having avg(ss_net_profit) > 0.9*(select avg(ss_net_profit) 
rank_col
+                                                  from store_sales
+                                                  where ss_store_sk = 410
+                                                    and ss_hdemo_sk is null
+                                                  group by ss_store_sk))V1)V11
+     where rnk  < 11) asceding,
+    (select *
+     from (select item_sk,rank() over (order by rank_col desc) rnk
+           from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col
+                 from store_sales ss1
+                 where ss_store_sk = 410
+                 group by ss_item_sk
+                 having avg(ss_net_profit) > 0.9*(select avg(ss_net_profit) 
rank_col
+                                                  from store_sales
+                                                  where ss_store_sk = 410
+                                                    and ss_hdemo_sk is null
+                                                  group by ss_store_sk))V2)V21
+     where rnk  < 11) descending,
+item i1,
+item i2
+where asceding.rnk = descending.rnk 
+  and i1.i_item_sk=asceding.item_sk
+  and i2.i_item_sk=descending.item_sk
+order by asceding.rnk
+limit 100
+PREHOOK: type: QUERY
+POSTHOOK: query: explain
+select  asceding.rnk, i1.i_product_name best_performing, i2.i_product_name 
worst_performing
+from(select *
+     from (select item_sk,rank() over (order by rank_col asc) rnk
+           from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col 
+                 from store_sales ss1
+                 where ss_store_sk = 410
+                 group by ss_item_sk
+                 having avg(ss_net_profit) > 0.9*(select avg(ss_net_profit) 
rank_col
+                                                  from store_sales
+                                                  where ss_store_sk = 410
+                                                    and ss_hdemo_sk is null
+                                                  group by ss_store_sk))V1)V11
+     where rnk  < 11) asceding,
+    (select *
+     from (select item_sk,rank() over (order by rank_col desc) rnk
+           from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col
+                 from store_sales ss1
+                 where ss_store_sk = 410
+                 group by ss_item_sk
+                 having avg(ss_net_profit) > 0.9*(select avg(ss_net_profit) 
rank_col
+                                                  from store_sales
+                                                  where ss_store_sk = 410
+                                                    and ss_hdemo_sk is null
+                                                  group by ss_store_sk))V2)V21
+     where rnk  < 11) descending,
+item i1,
+item i2
+where asceding.rnk = descending.rnk 
+  and i1.i_item_sk=asceding.item_sk
+  and i2.i_item_sk=descending.item_sk
+order by asceding.rnk
+limit 100
+POSTHOOK: type: QUERY
+Plan optimized by CBO.
+
+Vertex dependency in root stage
+Reducer 10 <- Reducer 9 (SIMPLE_EDGE)
+Reducer 11 <- Map 6 (SIMPLE_EDGE)
+Reducer 12 <- Reducer 11 (CUSTOM_SIMPLE_EDGE)
+Reducer 13 <- Reducer 12 (CUSTOM_SIMPLE_EDGE), Reducer 17 
(CUSTOM_SIMPLE_EDGE), Reducer 20 (CUSTOM_SIMPLE_EDGE)
+Reducer 14 <- Reducer 13 (SIMPLE_EDGE)
+Reducer 16 <- Map 15 (SIMPLE_EDGE)
+Reducer 17 <- Map 15 (SIMPLE_EDGE)
+Reducer 19 <- Map 18 (SIMPLE_EDGE)
+Reducer 2 <- Map 1 (SIMPLE_EDGE), Reducer 10 (SIMPLE_EDGE)
+Reducer 20 <- Map 18 (SIMPLE_EDGE)
+Reducer 3 <- Reducer 2 (SIMPLE_EDGE), Reducer 5 (SIMPLE_EDGE)
+Reducer 4 <- Reducer 3 (SIMPLE_EDGE)
+Reducer 5 <- Map 1 (SIMPLE_EDGE), Reducer 14 (SIMPLE_EDGE)
+Reducer 7 <- Map 6 (SIMPLE_EDGE)
+Reducer 8 <- Reducer 7 (CUSTOM_SIMPLE_EDGE)
+Reducer 9 <- Reducer 16 (CUSTOM_SIMPLE_EDGE), Reducer 19 (CUSTOM_SIMPLE_EDGE), 
Reducer 8 (CUSTOM_SIMPLE_EDGE)
+
+Stage-0
+  Fetch Operator
+    limit:100
+    Stage-1
+      Reducer 4
+      File Output Operator [FS_104]
+        Limit [LIM_103] (rows=100 width=185)
+          Number of rows:100
+          Select Operator [SEL_102] (rows=1393898919384048 width=185)
+            Output:["_col0","_col1","_col2"]
+          <-Reducer 3 [SIMPLE_EDGE]
+            SHUFFLE [RS_101]
+              Select Operator [SEL_100] (rows=1393898919384048 width=185)
+                Output:["_col0","_col1","_col2"]
+                Merge Join Operator [MERGEJOIN_135] (rows=1393898919384048 
width=185)
+                  
Conds:RS_97._col3=RS_98._col3(Inner),Output:["_col1","_col3","_col5"]
+                <-Reducer 2 [SIMPLE_EDGE]
+                  SHUFFLE [RS_97]
+                    PartitionCols:_col3
+                    Merge Join Operator [MERGEJOIN_132] (rows=1267180808338276 
width=185)
+                      
Conds:RS_94._col0=RS_95._col0(Inner),Output:["_col1","_col3"]
+                    <-Map 1 [SIMPLE_EDGE]
+                      SHUFFLE [RS_94]
+                        PartitionCols:_col0
+                        Select Operator [SEL_2] (rows=462000 width=1436)
+                          Output:["_col0","_col1"]
+                          Filter Operator [FIL_121] (rows=462000 width=1436)
+                            predicate:i_item_sk is not null
+                            TableScan [TS_0] (rows=462000 width=1436)
+                              
default@item,i1,Tbl:COMPLETE,Col:NONE,Output:["i_item_sk","i_product_name"]
+                    <-Reducer 10 [SIMPLE_EDGE]
+                      SHUFFLE [RS_95]
+                        PartitionCols:_col0
+                        Select Operator [SEL_41] (rows=1151982528066248 
width=185)
+                          Output:["_col0","_col1"]
+                          Filter Operator [FIL_122] (rows=1151982528066248 
width=185)
+                            predicate:((rank_window_0 < 11) and _col2 is not 
null)
+                            PTF Operator [PTF_40] (rows=3455947584198744 
width=185)
+                              Function 
definitions:[{},{"name:":"windowingtablefunction","order by:":"_col3 ASC NULLS 
FIRST","partition by:":"0"}]
+                              Select Operator [SEL_39] (rows=3455947584198744 
width=185)
+                                Output:["_col2","_col3"]
+                              <-Reducer 9 [SIMPLE_EDGE]
+                                SHUFFLE [RS_38]
+                                  PartitionCols:0
+                                  Filter Operator [FIL_37] 
(rows=3455947584198744 width=185)
+                                    predicate:(_col3 > (0.9 * _col1))
+                                    Merge Join Operator [MERGEJOIN_131] 
(rows=10367842752596232 width=185)
+                                      
Conds:(Inner),(Inner),Output:["_col1","_col2","_col3"]
+                                    <-Reducer 16 [CUSTOM_SIMPLE_EDGE]
+                                      PARTITION_ONLY_SHUFFLE [RS_34]
+                                        Select Operator [SEL_25] 
(rows=71999454 width=88)
+                                          Output:["_col0"]
+                                          Group By Operator [GBY_24] 
(rows=71999454 width=88)
+                                            
Output:["_col0","_col1"],aggregations:["avg(VALUE._col0)"],keys:KEY._col0
+                                          <-Map 15 [SIMPLE_EDGE]
+                                            SHUFFLE [RS_23]
+                                              PartitionCols:_col0
+                                              Group By Operator [GBY_22] 
(rows=143998908 width=88)
+                                                
Output:["_col0","_col1"],aggregations:["avg(_col1)"],keys:410
+                                                Select Operator [SEL_20] 
(rows=143998908 width=88)
+                                                  Output:["_col1"]
+                                                  Filter Operator [FIL_124] 
(rows=143998908 width=88)
+                                                    predicate:((ss_store_sk = 
410) and ss_hdemo_sk is null)
+                                                    TableScan [TS_18] 
(rows=575995635 width=88)
+                                                      
default@store_sales,store_sales,Tbl:COMPLETE,Col:NONE,Output:["ss_hdemo_sk","ss_store_sk","ss_net_profit"]
+                                    <-Reducer 19 [CUSTOM_SIMPLE_EDGE]
+                                      PARTITION_ONLY_SHUFFLE [RS_35]
+                                        Group By Operator [GBY_31] 
(rows=143998908 width=88)
+                                          
Output:["_col0","_col1"],aggregations:["avg(VALUE._col0)"],keys:KEY._col0
+                                        <-Map 18 [SIMPLE_EDGE]
+                                          SHUFFLE [RS_30]
+                                            PartitionCols:_col0
+                                            Group By Operator [GBY_29] 
(rows=287997817 width=88)
+                                              
Output:["_col0","_col1"],aggregations:["avg(ss_net_profit)"],keys:ss_item_sk
+                                              Select Operator [SEL_28] 
(rows=287997817 width=88)
+                                                
Output:["ss_item_sk","ss_net_profit"]
+                                                Filter Operator [FIL_125] 
(rows=287997817 width=88)
+                                                  predicate:(ss_store_sk = 410)
+                                                  TableScan [TS_26] 
(rows=575995635 width=88)
+                                                    
default@store_sales,ss1,Tbl:COMPLETE,Col:NONE,Output:["ss_item_sk","ss_store_sk","ss_net_profit"]
+                                    <-Reducer 8 [CUSTOM_SIMPLE_EDGE]
+                                      PARTITION_ONLY_SHUFFLE [RS_33]
+                                        Select Operator [SEL_17] (rows=1 
width=8)
+                                          Filter Operator [FIL_16] (rows=1 
width=8)
+                                            predicate:(sq_count_check(_col0) 
<= 1)
+                                            Group By Operator [GBY_14] (rows=1 
width=8)
+                                              
Output:["_col0"],aggregations:["count(VALUE._col0)"]
+                                            <-Reducer 7 [CUSTOM_SIMPLE_EDGE]
+                                              PARTITION_ONLY_SHUFFLE [RS_13]
+                                                Group By Operator [GBY_12] 
(rows=1 width=8)
+                                                  
Output:["_col0"],aggregations:["count()"]
+                                                  Select Operator [SEL_10] 
(rows=71999454 width=88)
+                                                    Group By Operator [GBY_9] 
(rows=71999454 width=88)
+                                                      
Output:["_col0"],keys:KEY._col0
+                                                    <-Map 6 [SIMPLE_EDGE]
+                                                      SHUFFLE [RS_8]
+                                                        PartitionCols:_col0
+                                                        Group By Operator 
[GBY_7] (rows=143998908 width=88)
+                                                          
Output:["_col0"],keys:410
+                                                          Select Operator 
[SEL_5] (rows=143998908 width=88)
+                                                            Filter Operator 
[FIL_123] (rows=143998908 width=88)
+                                                              
predicate:((ss_store_sk = 410) and ss_hdemo_sk is null)
+                                                              TableScan [TS_3] 
(rows=575995635 width=88)
+                                                                
default@store_sales,store_sales,Tbl:COMPLETE,Col:NONE,Output:["ss_hdemo_sk","ss_store_sk"]
+                <-Reducer 5 [SIMPLE_EDGE]
+                  SHUFFLE [RS_98]
+                    PartitionCols:_col3
+                    Merge Join Operator [MERGEJOIN_134] (rows=1267180808338276 
width=185)
+                      
Conds:RS_90._col0=RS_91._col0(Inner),Output:["_col1","_col3"]
+                    <-Map 1 [SIMPLE_EDGE]
+                      SHUFFLE [RS_90]
+                        PartitionCols:_col0
+                         Please refer to the previous Select Operator [SEL_2]
+                    <-Reducer 14 [SIMPLE_EDGE]
+                      SHUFFLE [RS_91]
+                        PartitionCols:_col0
+                        Select Operator [SEL_86] (rows=1151982528066248 
width=185)
+                          Output:["_col0","_col1"]
+                          Filter Operator [FIL_127] (rows=1151982528066248 
width=185)
+                            predicate:((rank_window_0 < 11) and _col2 is not 
null)
+                            PTF Operator [PTF_85] (rows=3455947584198744 
width=185)
+                              Function 
definitions:[{},{"name:":"windowingtablefunction","order by:":"_col3 DESC NULLS 
LAST","partition by:":"0"}]
+                              Select Operator [SEL_84] (rows=3455947584198744 
width=185)
+                                Output:["_col2","_col3"]
+                              <-Reducer 13 [SIMPLE_EDGE]
+                                SHUFFLE [RS_83]
+                                  PartitionCols:0
+                                  Filter Operator [FIL_82] 
(rows=3455947584198744 width=185)
+                                    predicate:(_col3 > (0.9 * _col1))
+                                    Merge Join Operator [MERGEJOIN_133] 
(rows=10367842752596232 width=185)
+                                      
Conds:(Inner),(Inner),Output:["_col1","_col2","_col3"]
+                                    <-Reducer 12 [CUSTOM_SIMPLE_EDGE]
+                                      PARTITION_ONLY_SHUFFLE [RS_78]
+                                        Select Operator [SEL_62] (rows=1 
width=8)
+                                          Filter Operator [FIL_61] (rows=1 
width=8)
+                                            predicate:(sq_count_check(_col0) 
<= 1)
+                                            Group By Operator [GBY_59] (rows=1 
width=8)
+                                              
Output:["_col0"],aggregations:["count(VALUE._col0)"]
+                                            <-Reducer 11 [CUSTOM_SIMPLE_EDGE]
+                                              PARTITION_ONLY_SHUFFLE [RS_58]
+                                                Group By Operator [GBY_57] 
(rows=1 width=8)
+                                                  
Output:["_col0"],aggregations:["count()"]
+                                                  Select Operator [SEL_55] 
(rows=71999454 width=88)
+                                                    Group By Operator [GBY_54] 
(rows=71999454 width=88)
+                                                      
Output:["_col0"],keys:KEY._col0
+                                                    <-Map 6 [SIMPLE_EDGE]
+                                                      SHUFFLE [RS_53]
+                                                        PartitionCols:_col0
+                                                         Please refer to the 
previous Group By Operator [GBY_7]
+                                    <-Reducer 17 [CUSTOM_SIMPLE_EDGE]
+                                      PARTITION_ONLY_SHUFFLE [RS_79]
+                                        Select Operator [SEL_70] 
(rows=71999454 width=88)
+                                          Output:["_col0"]
+                                          Group By Operator [GBY_69] 
(rows=71999454 width=88)
+                                            
Output:["_col0","_col1"],aggregations:["avg(VALUE._col0)"],keys:KEY._col0
+                                          <-Map 15 [SIMPLE_EDGE]
+                                            SHUFFLE [RS_68]
+                                              PartitionCols:_col0
+                                               Please refer to the previous 
Group By Operator [GBY_22]
+                                    <-Reducer 20 [CUSTOM_SIMPLE_EDGE]
+                                      PARTITION_ONLY_SHUFFLE [RS_80]
+                                        Group By Operator [GBY_76] 
(rows=143998908 width=88)
+                                          
Output:["_col0","_col1"],aggregations:["avg(VALUE._col0)"],keys:KEY._col0
+                                        <-Map 18 [SIMPLE_EDGE]
+                                          SHUFFLE [RS_75]
+                                            PartitionCols:_col0
+                                             Please refer to the previous 
Group By Operator [GBY_29]
+

Reply via email to