You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by we...@apache.org on 2017/05/31 00:11:42 UTC

[04/17] hive git commit: HIVE-16764: Support numeric as same as decimal (Pengcheng Xiong, reviewed by Ashutosh Chauhan)

http://git-wip-us.apache.org/repos/asf/hive/blob/86b18772/ql/src/test/results/clientpositive/perf/query77.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/perf/query77.q.out b/ql/src/test/results/clientpositive/perf/query77.q.out
new file mode 100644
index 0000000..d46ba6b
--- /dev/null
+++ b/ql/src/test/results/clientpositive/perf/query77.q.out
@@ -0,0 +1,509 @@
+Warning: Shuffle Join MERGEJOIN[189][tables = [$hdt$_0, $hdt$_1]] in Stage 'Reducer 15' is a cross product
+PREHOOK: query: explain
+with ss as
+ (select s_store_sk,
+         sum(ss_ext_sales_price) as sales,
+         sum(ss_net_profit) as profit
+ from store_sales,
+      date_dim,
+      store
+ where ss_sold_date_sk = d_date_sk
+       and d_date between cast('1998-08-04' as date) 
+                  and (cast('1998-08-04' as date) +  30 days) 
+       and ss_store_sk = s_store_sk
+ group by s_store_sk)
+ ,
+ sr as
+ (select s_store_sk,
+         sum(sr_return_amt) as returns,
+         sum(sr_net_loss) as profit_loss
+ from store_returns,
+      date_dim,
+      store
+ where sr_returned_date_sk = d_date_sk
+       and d_date between cast('1998-08-04' as date)
+                  and (cast('1998-08-04' as date) +  30 days)
+       and sr_store_sk = s_store_sk
+ group by s_store_sk), 
+ cs as
+ (select cs_call_center_sk,
+        sum(cs_ext_sales_price) as sales,
+        sum(cs_net_profit) as profit
+ from catalog_sales,
+      date_dim
+ where cs_sold_date_sk = d_date_sk
+       and d_date between cast('1998-08-04' as date)
+                  and (cast('1998-08-04' as date) +  30 days)
+ group by cs_call_center_sk 
+ ), 
+ cr as
+ (select
+        sum(cr_return_amount) as returns,
+        sum(cr_net_loss) as profit_loss
+ from catalog_returns,
+      date_dim
+ where cr_returned_date_sk = d_date_sk
+       and d_date between cast('1998-08-04' as date)
+                  and (cast('1998-08-04' as date) +  30 days)
+ ), 
+ ws as
+ ( select wp_web_page_sk,
+        sum(ws_ext_sales_price) as sales,
+        sum(ws_net_profit) as profit
+ from web_sales,
+      date_dim,
+      web_page
+ where ws_sold_date_sk = d_date_sk
+       and d_date between cast('1998-08-04' as date)
+                  and (cast('1998-08-04' as date) +  30 days)
+       and ws_web_page_sk = wp_web_page_sk
+ group by wp_web_page_sk), 
+ wr as
+ (select wp_web_page_sk,
+        sum(wr_return_amt) as returns,
+        sum(wr_net_loss) as profit_loss
+ from web_returns,
+      date_dim,
+      web_page
+ where wr_returned_date_sk = d_date_sk
+       and d_date between cast('1998-08-04' as date)
+                  and (cast('1998-08-04' as date) +  30 days)
+       and wr_web_page_sk = wp_web_page_sk
+ group by wp_web_page_sk)
+  select  channel
+        , id
+        , sum(sales) as sales
+        , sum(returns) as returns
+        , sum(profit) as profit
+ from 
+ (select 'store channel' as channel
+        , ss.s_store_sk as id
+        , sales
+        , coalesce(returns, 0) as returns
+        , (profit - coalesce(profit_loss,0)) as profit
+ from   ss left join sr
+        on  ss.s_store_sk = sr.s_store_sk
+ union all
+ select 'catalog channel' as channel
+        , cs_call_center_sk as id
+        , sales
+        , returns
+        , (profit - profit_loss) as profit
+ from  cs
+       , cr
+ union all
+ select 'web channel' as channel
+        , ws.wp_web_page_sk as id
+        , sales
+        , coalesce(returns, 0) returns
+        , (profit - coalesce(profit_loss,0)) as profit
+ from   ws left join wr
+        on  ws.wp_web_page_sk = wr.wp_web_page_sk
+ ) x
+ group by rollup (channel, id)
+ order by channel
+         ,id
+ limit 100
+PREHOOK: type: QUERY
+POSTHOOK: query: explain
+with ss as
+ (select s_store_sk,
+         sum(ss_ext_sales_price) as sales,
+         sum(ss_net_profit) as profit
+ from store_sales,
+      date_dim,
+      store
+ where ss_sold_date_sk = d_date_sk
+       and d_date between cast('1998-08-04' as date) 
+                  and (cast('1998-08-04' as date) +  30 days) 
+       and ss_store_sk = s_store_sk
+ group by s_store_sk)
+ ,
+ sr as
+ (select s_store_sk,
+         sum(sr_return_amt) as returns,
+         sum(sr_net_loss) as profit_loss
+ from store_returns,
+      date_dim,
+      store
+ where sr_returned_date_sk = d_date_sk
+       and d_date between cast('1998-08-04' as date)
+                  and (cast('1998-08-04' as date) +  30 days)
+       and sr_store_sk = s_store_sk
+ group by s_store_sk), 
+ cs as
+ (select cs_call_center_sk,
+        sum(cs_ext_sales_price) as sales,
+        sum(cs_net_profit) as profit
+ from catalog_sales,
+      date_dim
+ where cs_sold_date_sk = d_date_sk
+       and d_date between cast('1998-08-04' as date)
+                  and (cast('1998-08-04' as date) +  30 days)
+ group by cs_call_center_sk 
+ ), 
+ cr as
+ (select
+        sum(cr_return_amount) as returns,
+        sum(cr_net_loss) as profit_loss
+ from catalog_returns,
+      date_dim
+ where cr_returned_date_sk = d_date_sk
+       and d_date between cast('1998-08-04' as date)
+                  and (cast('1998-08-04' as date) +  30 days)
+ ), 
+ ws as
+ ( select wp_web_page_sk,
+        sum(ws_ext_sales_price) as sales,
+        sum(ws_net_profit) as profit
+ from web_sales,
+      date_dim,
+      web_page
+ where ws_sold_date_sk = d_date_sk
+       and d_date between cast('1998-08-04' as date)
+                  and (cast('1998-08-04' as date) +  30 days)
+       and ws_web_page_sk = wp_web_page_sk
+ group by wp_web_page_sk), 
+ wr as
+ (select wp_web_page_sk,
+        sum(wr_return_amt) as returns,
+        sum(wr_net_loss) as profit_loss
+ from web_returns,
+      date_dim,
+      web_page
+ where wr_returned_date_sk = d_date_sk
+       and d_date between cast('1998-08-04' as date)
+                  and (cast('1998-08-04' as date) +  30 days)
+       and wr_web_page_sk = wp_web_page_sk
+ group by wp_web_page_sk)
+  select  channel
+        , id
+        , sum(sales) as sales
+        , sum(returns) as returns
+        , sum(profit) as profit
+ from 
+ (select 'store channel' as channel
+        , ss.s_store_sk as id
+        , sales
+        , coalesce(returns, 0) as returns
+        , (profit - coalesce(profit_loss,0)) as profit
+ from   ss left join sr
+        on  ss.s_store_sk = sr.s_store_sk
+ union all
+ select 'catalog channel' as channel
+        , cs_call_center_sk as id
+        , sales
+        , returns
+        , (profit - profit_loss) as profit
+ from  cs
+       , cr
+ union all
+ select 'web channel' as channel
+        , ws.wp_web_page_sk as id
+        , sales
+        , coalesce(returns, 0) returns
+        , (profit - coalesce(profit_loss,0)) as profit
+ from   ws left join wr
+        on  ws.wp_web_page_sk = wr.wp_web_page_sk
+ ) x
+ group by rollup (channel, id)
+ order by channel
+         ,id
+ limit 100
+POSTHOOK: type: QUERY
+Plan optimized by CBO.
+
+Vertex dependency in root stage
+Reducer 10 <- Map 26 (SIMPLE_EDGE), Map 9 (SIMPLE_EDGE)
+Reducer 11 <- Map 25 (SIMPLE_EDGE), Reducer 10 (SIMPLE_EDGE)
+Reducer 12 <- Reducer 11 (SIMPLE_EDGE)
+Reducer 13 <- Map 27 (SIMPLE_EDGE), Map 9 (SIMPLE_EDGE)
+Reducer 14 <- Reducer 13 (SIMPLE_EDGE)
+Reducer 15 <- Reducer 14 (CUSTOM_SIMPLE_EDGE), Reducer 17 (CUSTOM_SIMPLE_EDGE), Union 6 (CONTAINS)
+Reducer 16 <- Map 28 (SIMPLE_EDGE), Map 9 (SIMPLE_EDGE)
+Reducer 17 <- Reducer 16 (CUSTOM_SIMPLE_EDGE)
+Reducer 18 <- Map 29 (SIMPLE_EDGE), Map 9 (SIMPLE_EDGE)
+Reducer 19 <- Map 30 (SIMPLE_EDGE), Reducer 18 (SIMPLE_EDGE)
+Reducer 2 <- Map 1 (SIMPLE_EDGE), Map 9 (SIMPLE_EDGE)
+Reducer 20 <- Reducer 19 (SIMPLE_EDGE)
+Reducer 21 <- Reducer 20 (SIMPLE_EDGE), Reducer 24 (SIMPLE_EDGE), Union 6 (CONTAINS)
+Reducer 22 <- Map 31 (SIMPLE_EDGE), Map 9 (SIMPLE_EDGE)
+Reducer 23 <- Map 30 (SIMPLE_EDGE), Reducer 22 (SIMPLE_EDGE)
+Reducer 24 <- Reducer 23 (SIMPLE_EDGE)
+Reducer 3 <- Map 25 (SIMPLE_EDGE), Reducer 2 (SIMPLE_EDGE)
+Reducer 4 <- Reducer 3 (SIMPLE_EDGE)
+Reducer 5 <- Reducer 12 (SIMPLE_EDGE), Reducer 4 (SIMPLE_EDGE), Union 6 (CONTAINS)
+Reducer 7 <- Union 6 (SIMPLE_EDGE)
+Reducer 8 <- Reducer 7 (SIMPLE_EDGE)
+
+Stage-0
+  Fetch Operator
+    limit:100
+    Stage-1
+      Reducer 8
+      File Output Operator [FS_131]
+        Limit [LIM_130] (rows=100 width=163)
+          Number of rows:100
+          Select Operator [SEL_129] (rows=956329968 width=163)
+            Output:["_col0","_col1","_col2","_col3","_col4"]
+          <-Reducer 7 [SIMPLE_EDGE]
+            SHUFFLE [RS_128]
+              Select Operator [SEL_127] (rows=956329968 width=163)
+                Output:["_col0","_col1","_col2","_col3","_col4"]
+                Group By Operator [GBY_126] (rows=956329968 width=163)
+                  Output:["_col0","_col1","_col3","_col4","_col5"],aggregations:["sum(VALUE._col0)","sum(VALUE._col1)","sum(VALUE._col2)"],keys:KEY._col0, KEY._col1, KEY._col2
+                <-Union 6 [SIMPLE_EDGE]
+                  <-Reducer 15 [CONTAINS]
+                    Reduce Output Operator [RS_125]
+                      PartitionCols:_col0, _col1, _col2
+                      Group By Operator [GBY_124] (rows=1912659936 width=163)
+                        Output:["_col0","_col1","_col2","_col3","_col4","_col5"],aggregations:["sum(_col2)","sum(_col3)","sum(_col4)"],keys:_col0, _col1, 0
+                        Select Operator [SEL_75] (rows=158394413 width=360)
+                          Output:["_col0","_col1","_col2","_col3","_col4"]
+                          Merge Join Operator [MERGEJOIN_189] (rows=158394413 width=360)
+                            Conds:(Inner),Output:["_col0","_col1","_col2","_col3","_col4"]
+                          <-Reducer 14 [CUSTOM_SIMPLE_EDGE]
+                            PARTITION_ONLY_SHUFFLE [RS_72]
+                              Group By Operator [GBY_56] (rows=158394413 width=135)
+                                Output:["_col0","_col1","_col2"],aggregations:["sum(VALUE._col0)","sum(VALUE._col1)"],keys:KEY._col0
+                              <-Reducer 13 [SIMPLE_EDGE]
+                                SHUFFLE [RS_55]
+                                  PartitionCols:_col0
+                                  Group By Operator [GBY_54] (rows=316788826 width=135)
+                                    Output:["_col0","_col1","_col2"],aggregations:["sum(_col2)","sum(_col3)"],keys:_col1
+                                    Merge Join Operator [MERGEJOIN_182] (rows=316788826 width=135)
+                                      Conds:RS_50._col0=RS_51._col0(Inner),Output:["_col1","_col2","_col3"]
+                                    <-Map 9 [SIMPLE_EDGE]
+                                      SHUFFLE [RS_51]
+                                        PartitionCols:_col0
+                                        Select Operator [SEL_49] (rows=8116 width=1119)
+                                          Output:["_col0"]
+                                          Filter Operator [FIL_169] (rows=8116 width=1119)
+                                            predicate:(CAST( d_date AS TIMESTAMP) BETWEEN 1998-08-04 00:00:00.0 AND 1998-09-03 00:00:00.0 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_date"]
+                                    <-Map 27 [SIMPLE_EDGE]
+                                      SHUFFLE [RS_50]
+                                        PartitionCols:_col0
+                                        Select Operator [SEL_46] (rows=287989836 width=135)
+                                          Output:["_col0","_col1","_col2","_col3"]
+                                          Filter Operator [FIL_168] (rows=287989836 width=135)
+                                            predicate:cs_sold_date_sk is not null
+                                            TableScan [TS_44] (rows=287989836 width=135)
+                                              default@catalog_sales,catalog_sales,Tbl:COMPLETE,Col:NONE,Output:["cs_sold_date_sk","cs_call_center_sk","cs_ext_sales_price","cs_net_profit"]
+                          <-Reducer 17 [CUSTOM_SIMPLE_EDGE]
+                            PARTITION_ONLY_SHUFFLE [RS_73]
+                              Group By Operator [GBY_70] (rows=1 width=224)
+                                Output:["_col0","_col1"],aggregations:["sum(VALUE._col0)","sum(VALUE._col1)"]
+                              <-Reducer 16 [CUSTOM_SIMPLE_EDGE]
+                                PARTITION_ONLY_SHUFFLE [RS_69]
+                                  Group By Operator [GBY_68] (rows=1 width=224)
+                                    Output:["_col0","_col1"],aggregations:["sum(_col1)","sum(_col2)"]
+                                    Merge Join Operator [MERGEJOIN_183] (rows=31678769 width=106)
+                                      Conds:RS_64._col0=RS_65._col0(Inner),Output:["_col1","_col2"]
+                                    <-Map 9 [SIMPLE_EDGE]
+                                      SHUFFLE [RS_65]
+                                        PartitionCols:_col0
+                                        Select Operator [SEL_63] (rows=8116 width=1119)
+                                          Output:["_col0"]
+                                          Filter Operator [FIL_171] (rows=8116 width=1119)
+                                            predicate:(CAST( d_date AS TIMESTAMP) BETWEEN 1998-08-04 00:00:00.0 AND 1998-09-03 00:00:00.0 and d_date_sk is not null)
+                                             Please refer to the previous TableScan [TS_3]
+                                    <-Map 28 [SIMPLE_EDGE]
+                                      SHUFFLE [RS_64]
+                                        PartitionCols:_col0
+                                        Select Operator [SEL_60] (rows=28798881 width=106)
+                                          Output:["_col0","_col1","_col2"]
+                                          Filter Operator [FIL_170] (rows=28798881 width=106)
+                                            predicate:cr_returned_date_sk is not null
+                                            TableScan [TS_58] (rows=28798881 width=106)
+                                              default@catalog_returns,catalog_returns,Tbl:COMPLETE,Col:NONE,Output:["cr_returned_date_sk","cr_return_amount","cr_net_loss"]
+                  <-Reducer 21 [CONTAINS]
+                    Reduce Output Operator [RS_125]
+                      PartitionCols:_col0, _col1, _col2
+                      Group By Operator [GBY_124] (rows=1912659936 width=163)
+                        Output:["_col0","_col1","_col2","_col3","_col4","_col5"],aggregations:["sum(_col2)","sum(_col3)","sum(_col4)"],keys:_col0, _col1, 0
+                        Select Operator [SEL_121] (rows=95833780 width=135)
+                          Output:["_col0","_col1","_col2","_col3","_col4"]
+                          Merge Join Operator [MERGEJOIN_190] (rows=95833780 width=135)
+                            Conds:RS_118._col0=RS_119._col0(Left Outer),Output:["_col0","_col1","_col2","_col4","_col5"]
+                          <-Reducer 20 [SIMPLE_EDGE]
+                            SHUFFLE [RS_118]
+                              PartitionCols:_col0
+                              Group By Operator [GBY_96] (rows=87121617 width=135)
+                                Output:["_col0","_col1","_col2"],aggregations:["sum(VALUE._col0)","sum(VALUE._col1)"],keys:KEY._col0
+                              <-Reducer 19 [SIMPLE_EDGE]
+                                SHUFFLE [RS_95]
+                                  PartitionCols:_col0
+                                  Group By Operator [GBY_94] (rows=174243235 width=135)
+                                    Output:["_col0","_col1","_col2"],aggregations:["sum(_col2)","sum(_col3)"],keys:_col6
+                                    Merge Join Operator [MERGEJOIN_185] (rows=174243235 width=135)
+                                      Conds:RS_90._col1=RS_91._col0(Inner),Output:["_col2","_col3","_col6"]
+                                    <-Map 30 [SIMPLE_EDGE]
+                                      SHUFFLE [RS_91]
+                                        PartitionCols:_col0
+                                        Select Operator [SEL_86] (rows=4602 width=585)
+                                          Output:["_col0"]
+                                          Filter Operator [FIL_174] (rows=4602 width=585)
+                                            predicate:wp_web_page_sk is not null
+                                            TableScan [TS_84] (rows=4602 width=585)
+                                              default@web_page,web_page,Tbl:COMPLETE,Col:NONE,Output:["wp_web_page_sk"]
+                                    <-Reducer 18 [SIMPLE_EDGE]
+                                      SHUFFLE [RS_90]
+                                        PartitionCols:_col1
+                                        Merge Join Operator [MERGEJOIN_184] (rows=158402938 width=135)
+                                          Conds:RS_87._col0=RS_88._col0(Inner),Output:["_col1","_col2","_col3"]
+                                        <-Map 9 [SIMPLE_EDGE]
+                                          SHUFFLE [RS_88]
+                                            PartitionCols:_col0
+                                            Select Operator [SEL_83] (rows=8116 width=1119)
+                                              Output:["_col0"]
+                                              Filter Operator [FIL_173] (rows=8116 width=1119)
+                                                predicate:(CAST( d_date AS TIMESTAMP) BETWEEN 1998-08-04 00:00:00.0 AND 1998-09-03 00:00:00.0 and d_date_sk is not null)
+                                                 Please refer to the previous TableScan [TS_3]
+                                        <-Map 29 [SIMPLE_EDGE]
+                                          SHUFFLE [RS_87]
+                                            PartitionCols:_col0
+                                            Select Operator [SEL_80] (rows=144002668 width=135)
+                                              Output:["_col0","_col1","_col2","_col3"]
+                                              Filter Operator [FIL_172] (rows=144002668 width=135)
+                                                predicate:(ws_sold_date_sk is not null and ws_web_page_sk is not null)
+                                                TableScan [TS_78] (rows=144002668 width=135)
+                                                  default@web_sales,web_sales,Tbl:COMPLETE,Col:NONE,Output:["ws_sold_date_sk","ws_web_page_sk","ws_ext_sales_price","ws_net_profit"]
+                          <-Reducer 24 [SIMPLE_EDGE]
+                            SHUFFLE [RS_119]
+                              PartitionCols:_col0
+                              Group By Operator [GBY_116] (rows=8711072 width=92)
+                                Output:["_col0","_col1","_col2"],aggregations:["sum(VALUE._col0)","sum(VALUE._col1)"],keys:KEY._col0
+                              <-Reducer 23 [SIMPLE_EDGE]
+                                SHUFFLE [RS_115]
+                                  PartitionCols:_col0
+                                  Group By Operator [GBY_114] (rows=17422145 width=92)
+                                    Output:["_col0","_col1","_col2"],aggregations:["sum(_col2)","sum(_col3)"],keys:_col6
+                                    Merge Join Operator [MERGEJOIN_187] (rows=17422145 width=92)
+                                      Conds:RS_110._col1=RS_111._col0(Inner),Output:["_col2","_col3","_col6"]
+                                    <-Map 30 [SIMPLE_EDGE]
+                                      SHUFFLE [RS_111]
+                                        PartitionCols:_col0
+                                        Select Operator [SEL_106] (rows=4602 width=585)
+                                          Output:["_col0"]
+                                          Filter Operator [FIL_177] (rows=4602 width=585)
+                                            predicate:wp_web_page_sk is not null
+                                             Please refer to the previous TableScan [TS_84]
+                                    <-Reducer 22 [SIMPLE_EDGE]
+                                      SHUFFLE [RS_110]
+                                        PartitionCols:_col1
+                                        Merge Join Operator [MERGEJOIN_186] (rows=15838314 width=92)
+                                          Conds:RS_107._col0=RS_108._col0(Inner),Output:["_col1","_col2","_col3"]
+                                        <-Map 9 [SIMPLE_EDGE]
+                                          SHUFFLE [RS_108]
+                                            PartitionCols:_col0
+                                            Select Operator [SEL_103] (rows=8116 width=1119)
+                                              Output:["_col0"]
+                                              Filter Operator [FIL_176] (rows=8116 width=1119)
+                                                predicate:(CAST( d_date AS TIMESTAMP) BETWEEN 1998-08-04 00:00:00.0 AND 1998-09-03 00:00:00.0 and d_date_sk is not null)
+                                                 Please refer to the previous TableScan [TS_3]
+                                        <-Map 31 [SIMPLE_EDGE]
+                                          SHUFFLE [RS_107]
+                                            PartitionCols:_col0
+                                            Select Operator [SEL_100] (rows=14398467 width=92)
+                                              Output:["_col0","_col1","_col2","_col3"]
+                                              Filter Operator [FIL_175] (rows=14398467 width=92)
+                                                predicate:(wr_returned_date_sk is not null and wr_web_page_sk is not null)
+                                                TableScan [TS_98] (rows=14398467 width=92)
+                                                  default@web_returns,web_returns,Tbl:COMPLETE,Col:NONE,Output:["wr_returned_date_sk","wr_web_page_sk","wr_return_amt","wr_net_loss"]
+                  <-Reducer 5 [CONTAINS]
+                    Reduce Output Operator [RS_125]
+                      PartitionCols:_col0, _col1, _col2
+                      Group By Operator [GBY_124] (rows=1912659936 width=163)
+                        Output:["_col0","_col1","_col2","_col3","_col4","_col5"],aggregations:["sum(_col2)","sum(_col3)","sum(_col4)"],keys:_col0, _col1, 0
+                        Select Operator [SEL_43] (rows=383325119 width=88)
+                          Output:["_col0","_col1","_col2","_col3","_col4"]
+                          Merge Join Operator [MERGEJOIN_188] (rows=383325119 width=88)
+                            Conds:RS_40._col0=RS_41._col0(Left Outer),Output:["_col0","_col1","_col2","_col4","_col5"]
+                          <-Reducer 12 [SIMPLE_EDGE]
+                            SHUFFLE [RS_41]
+                              PartitionCols:_col0
+                              Group By Operator [GBY_38] (rows=34842647 width=77)
+                                Output:["_col0","_col1","_col2"],aggregations:["sum(VALUE._col0)","sum(VALUE._col1)"],keys:KEY._col0
+                              <-Reducer 11 [SIMPLE_EDGE]
+                                SHUFFLE [RS_37]
+                                  PartitionCols:_col0
+                                  Group By Operator [GBY_36] (rows=69685294 width=77)
+                                    Output:["_col0","_col1","_col2"],aggregations:["sum(_col2)","sum(_col3)"],keys:_col6
+                                    Merge Join Operator [MERGEJOIN_181] (rows=69685294 width=77)
+                                      Conds:RS_32._col1=RS_33._col0(Inner),Output:["_col2","_col3","_col6"]
+                                    <-Map 25 [SIMPLE_EDGE]
+                                      SHUFFLE [RS_33]
+                                        PartitionCols:_col0
+                                        Select Operator [SEL_28] (rows=1704 width=1910)
+                                          Output:["_col0"]
+                                          Filter Operator [FIL_167] (rows=1704 width=1910)
+                                            predicate:s_store_sk is not null
+                                            TableScan [TS_6] (rows=1704 width=1910)
+                                              default@store,store,Tbl:COMPLETE,Col:NONE,Output:["s_store_sk"]
+                                    <-Reducer 10 [SIMPLE_EDGE]
+                                      SHUFFLE [RS_32]
+                                        PartitionCols:_col1
+                                        Merge Join Operator [MERGEJOIN_180] (rows=63350266 width=77)
+                                          Conds:RS_29._col0=RS_30._col0(Inner),Output:["_col1","_col2","_col3"]
+                                        <-Map 9 [SIMPLE_EDGE]
+                                          SHUFFLE [RS_30]
+                                            PartitionCols:_col0
+                                            Select Operator [SEL_25] (rows=8116 width=1119)
+                                              Output:["_col0"]
+                                              Filter Operator [FIL_166] (rows=8116 width=1119)
+                                                predicate:(CAST( d_date AS TIMESTAMP) BETWEEN 1998-08-04 00:00:00.0 AND 1998-09-03 00:00:00.0 and d_date_sk is not null)
+                                                 Please refer to the previous TableScan [TS_3]
+                                        <-Map 26 [SIMPLE_EDGE]
+                                          SHUFFLE [RS_29]
+                                            PartitionCols:_col0
+                                            Select Operator [SEL_22] (rows=57591150 width=77)
+                                              Output:["_col0","_col1","_col2","_col3"]
+                                              Filter Operator [FIL_165] (rows=57591150 width=77)
+                                                predicate:(sr_returned_date_sk is not null and sr_store_sk is not null)
+                                                TableScan [TS_20] (rows=57591150 width=77)
+                                                  default@store_returns,store_returns,Tbl:COMPLETE,Col:NONE,Output:["sr_returned_date_sk","sr_store_sk","sr_return_amt","sr_net_loss"]
+                          <-Reducer 4 [SIMPLE_EDGE]
+                            SHUFFLE [RS_40]
+                              PartitionCols:_col0
+                              Group By Operator [GBY_18] (rows=348477374 width=88)
+                                Output:["_col0","_col1","_col2"],aggregations:["sum(VALUE._col0)","sum(VALUE._col1)"],keys:KEY._col0
+                              <-Reducer 3 [SIMPLE_EDGE]
+                                SHUFFLE [RS_17]
+                                  PartitionCols:_col0
+                                  Group By Operator [GBY_16] (rows=696954748 width=88)
+                                    Output:["_col0","_col1","_col2"],aggregations:["sum(_col2)","sum(_col3)"],keys:_col6
+                                    Merge Join Operator [MERGEJOIN_179] (rows=696954748 width=88)
+                                      Conds:RS_12._col1=RS_13._col0(Inner),Output:["_col2","_col3","_col6"]
+                                    <-Map 25 [SIMPLE_EDGE]
+                                      SHUFFLE [RS_13]
+                                        PartitionCols:_col0
+                                        Select Operator [SEL_8] (rows=1704 width=1910)
+                                          Output:["_col0"]
+                                          Filter Operator [FIL_164] (rows=1704 width=1910)
+                                            predicate:s_store_sk is not null
+                                             Please refer to the previous TableScan [TS_6]
+                                    <-Reducer 2 [SIMPLE_EDGE]
+                                      SHUFFLE [RS_12]
+                                        PartitionCols:_col1
+                                        Merge Join Operator [MERGEJOIN_178] (rows=633595212 width=88)
+                                          Conds:RS_9._col0=RS_10._col0(Inner),Output:["_col1","_col2","_col3"]
+                                        <-Map 9 [SIMPLE_EDGE]
+                                          SHUFFLE [RS_10]
+                                            PartitionCols:_col0
+                                            Select Operator [SEL_5] (rows=8116 width=1119)
+                                              Output:["_col0"]
+                                              Filter Operator [FIL_163] (rows=8116 width=1119)
+                                                predicate:(CAST( d_date AS TIMESTAMP) BETWEEN 1998-08-04 00:00:00.0 AND 1998-09-03 00:00:00.0 and d_date_sk is not null)
+                                                 Please refer to the previous TableScan [TS_3]
+                                        <-Map 1 [SIMPLE_EDGE]
+                                          SHUFFLE [RS_9]
+                                            PartitionCols:_col0
+                                            Select Operator [SEL_2] (rows=575995635 width=88)
+                                              Output:["_col0","_col1","_col2","_col3"]
+                                              Filter Operator [FIL_162] (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_ext_sales_price","ss_net_profit"]
+

http://git-wip-us.apache.org/repos/asf/hive/blob/86b18772/ql/src/test/results/clientpositive/perf/query78.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/perf/query78.q.out b/ql/src/test/results/clientpositive/perf/query78.q.out
new file mode 100644
index 0000000..8710085
--- /dev/null
+++ b/ql/src/test/results/clientpositive/perf/query78.q.out
@@ -0,0 +1,302 @@
+PREHOOK: query: explain
+with ws as
+  (select d_year AS ws_sold_year, ws_item_sk,
+    ws_bill_customer_sk ws_customer_sk,
+    sum(ws_quantity) ws_qty,
+    sum(ws_wholesale_cost) ws_wc,
+    sum(ws_sales_price) ws_sp
+   from web_sales
+   left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk
+   join date_dim on ws_sold_date_sk = d_date_sk
+   where wr_order_number is null
+   group by d_year, ws_item_sk, ws_bill_customer_sk
+   ),
+cs as
+  (select d_year AS cs_sold_year, cs_item_sk,
+    cs_bill_customer_sk cs_customer_sk,
+    sum(cs_quantity) cs_qty,
+    sum(cs_wholesale_cost) cs_wc,
+    sum(cs_sales_price) cs_sp
+   from catalog_sales
+   left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk
+   join date_dim on cs_sold_date_sk = d_date_sk
+   where cr_order_number is null
+   group by d_year, cs_item_sk, cs_bill_customer_sk
+   ),
+ss as
+  (select d_year AS ss_sold_year, ss_item_sk,
+    ss_customer_sk,
+    sum(ss_quantity) ss_qty,
+    sum(ss_wholesale_cost) ss_wc,
+    sum(ss_sales_price) ss_sp
+   from store_sales
+   left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk
+   join date_dim on ss_sold_date_sk = d_date_sk
+   where sr_ticket_number is null
+   group by d_year, ss_item_sk, ss_customer_sk
+   )
+ select 
+ss_sold_year, ss_item_sk, ss_customer_sk,
+round(ss_qty/(coalesce(ws_qty+cs_qty,1)),2) ratio,
+ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price,
+coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty,
+coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost,
+coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price
+from ss
+left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk)
+left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=cs_item_sk and cs_customer_sk=ss_customer_sk)
+where coalesce(ws_qty,0)>0 and coalesce(cs_qty, 0)>0 and ss_sold_year=2000
+order by 
+  ss_sold_year, ss_item_sk, ss_customer_sk,
+  ss_qty desc, ss_wc desc, ss_sp desc,
+  other_chan_qty,
+  other_chan_wholesale_cost,
+  other_chan_sales_price,
+  round(ss_qty/(coalesce(ws_qty+cs_qty,1)),2)
+limit 100
+PREHOOK: type: QUERY
+POSTHOOK: query: explain
+with ws as
+  (select d_year AS ws_sold_year, ws_item_sk,
+    ws_bill_customer_sk ws_customer_sk,
+    sum(ws_quantity) ws_qty,
+    sum(ws_wholesale_cost) ws_wc,
+    sum(ws_sales_price) ws_sp
+   from web_sales
+   left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk
+   join date_dim on ws_sold_date_sk = d_date_sk
+   where wr_order_number is null
+   group by d_year, ws_item_sk, ws_bill_customer_sk
+   ),
+cs as
+  (select d_year AS cs_sold_year, cs_item_sk,
+    cs_bill_customer_sk cs_customer_sk,
+    sum(cs_quantity) cs_qty,
+    sum(cs_wholesale_cost) cs_wc,
+    sum(cs_sales_price) cs_sp
+   from catalog_sales
+   left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk
+   join date_dim on cs_sold_date_sk = d_date_sk
+   where cr_order_number is null
+   group by d_year, cs_item_sk, cs_bill_customer_sk
+   ),
+ss as
+  (select d_year AS ss_sold_year, ss_item_sk,
+    ss_customer_sk,
+    sum(ss_quantity) ss_qty,
+    sum(ss_wholesale_cost) ss_wc,
+    sum(ss_sales_price) ss_sp
+   from store_sales
+   left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk
+   join date_dim on ss_sold_date_sk = d_date_sk
+   where sr_ticket_number is null
+   group by d_year, ss_item_sk, ss_customer_sk
+   )
+ select 
+ss_sold_year, ss_item_sk, ss_customer_sk,
+round(ss_qty/(coalesce(ws_qty+cs_qty,1)),2) ratio,
+ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price,
+coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty,
+coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost,
+coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price
+from ss
+left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk)
+left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=cs_item_sk and cs_customer_sk=ss_customer_sk)
+where coalesce(ws_qty,0)>0 and coalesce(cs_qty, 0)>0 and ss_sold_year=2000
+order by 
+  ss_sold_year, ss_item_sk, ss_customer_sk,
+  ss_qty desc, ss_wc desc, ss_sp desc,
+  other_chan_qty,
+  other_chan_wholesale_cost,
+  other_chan_sales_price,
+  round(ss_qty/(coalesce(ws_qty+cs_qty,1)),2)
+limit 100
+POSTHOOK: type: QUERY
+Plan optimized by CBO.
+
+Vertex dependency in root stage
+Reducer 10 <- Reducer 9 (SIMPLE_EDGE)
+Reducer 12 <- Map 11 (SIMPLE_EDGE), Map 13 (SIMPLE_EDGE)
+Reducer 15 <- Map 14 (SIMPLE_EDGE), Map 16 (SIMPLE_EDGE)
+Reducer 18 <- Map 17 (SIMPLE_EDGE), Map 19 (SIMPLE_EDGE)
+Reducer 2 <- Map 1 (SIMPLE_EDGE), Reducer 12 (SIMPLE_EDGE)
+Reducer 3 <- Reducer 2 (SIMPLE_EDGE)
+Reducer 4 <- Reducer 3 (SIMPLE_EDGE), Reducer 8 (SIMPLE_EDGE)
+Reducer 5 <- Reducer 10 (SIMPLE_EDGE), Reducer 4 (SIMPLE_EDGE)
+Reducer 6 <- Reducer 5 (SIMPLE_EDGE)
+Reducer 7 <- Map 1 (SIMPLE_EDGE), Reducer 15 (SIMPLE_EDGE)
+Reducer 8 <- Reducer 7 (SIMPLE_EDGE)
+Reducer 9 <- Map 1 (SIMPLE_EDGE), Reducer 18 (SIMPLE_EDGE)
+
+Stage-0
+  Fetch Operator
+    limit:-1
+    Stage-1
+      Reducer 6
+      File Output Operator [FS_79]
+        Select Operator [SEL_78] (rows=100 width=135)
+          Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6","_col7","_col8","_col9"]
+          Limit [LIM_77] (rows=100 width=135)
+            Number of rows:100
+            Select Operator [SEL_76] (rows=31942874 width=135)
+              Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6","_col7","_col8"]
+            <-Reducer 5 [SIMPLE_EDGE]
+              SHUFFLE [RS_75]
+                Select Operator [SEL_74] (rows=31942874 width=135)
+                  Output:["_col0","_col1","_col6","_col7","_col8","_col9","_col10","_col11","_col12"]
+                  Filter Operator [FIL_73] (rows=31942874 width=135)
+                    predicate:(COALESCE(_col11,0) > 0)
+                    Merge Join Operator [MERGEJOIN_114] (rows=95828623 width=135)
+                      Conds:RS_70._col1=RS_71._col0(Left Outer),Output:["_col0","_col1","_col2","_col3","_col4","_col7","_col8","_col9","_col11","_col12","_col13"]
+                    <-Reducer 10 [SIMPLE_EDGE]
+                      SHUFFLE [RS_71]
+                        PartitionCols:_col0
+                        Select Operator [SEL_68] (rows=87116929 width=135)
+                          Output:["_col0","_col1","_col2","_col3"]
+                          Group By Operator [GBY_67] (rows=87116929 width=135)
+                            Output:["_col0","_col1","_col2","_col3","_col4"],aggregations:["sum(VALUE._col0)","sum(VALUE._col1)","sum(VALUE._col2)"],keys:KEY._col0, KEY._col1
+                          <-Reducer 9 [SIMPLE_EDGE]
+                            SHUFFLE [RS_66]
+                              PartitionCols:_col0, _col1
+                              Group By Operator [GBY_65] (rows=174233858 width=135)
+                                Output:["_col0","_col1","_col2","_col3","_col4"],aggregations:["sum(_col6)","sum(_col7)","sum(_col8)"],keys:_col3, _col4
+                                Merge Join Operator [MERGEJOIN_112] (rows=174233858 width=135)
+                                  Conds:RS_61._col0=RS_62._col0(Inner),Output:["_col3","_col4","_col6","_col7","_col8"]
+                                <-Map 1 [SIMPLE_EDGE]
+                                  SHUFFLE [RS_61]
+                                    PartitionCols:_col0
+                                    Select Operator [SEL_49] (rows=36524 width=1119)
+                                      Output:["_col0"]
+                                      Filter Operator [FIL_104] (rows=36524 width=1119)
+                                        predicate:((d_year = 2000) and d_date_sk is not null)
+                                        TableScan [TS_0] (rows=73049 width=1119)
+                                          default@date_dim,date_dim,Tbl:COMPLETE,Col:NONE,Output:["d_date_sk","d_year"]
+                                <-Reducer 18 [SIMPLE_EDGE]
+                                  SHUFFLE [RS_62]
+                                    PartitionCols:_col0
+                                    Select Operator [SEL_60] (rows=158394413 width=135)
+                                      Output:["_col0","_col1","_col2","_col4","_col5","_col6"]
+                                      Filter Operator [FIL_59] (rows=158394413 width=135)
+                                        predicate:_col8 is null
+                                        Merge Join Operator [MERGEJOIN_111] (rows=316788826 width=135)
+                                          Conds:RS_56._col2, _col3=RS_57._col0, _col1(Left Outer),Output:["_col0","_col1","_col2","_col4","_col5","_col6","_col8"]
+                                        <-Map 17 [SIMPLE_EDGE]
+                                          SHUFFLE [RS_56]
+                                            PartitionCols:_col2, _col3
+                                            Select Operator [SEL_52] (rows=287989836 width=135)
+                                              Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6"]
+                                              Filter Operator [FIL_105] (rows=287989836 width=135)
+                                                predicate:(cs_sold_date_sk is not null and cs_item_sk is not null)
+                                                TableScan [TS_50] (rows=287989836 width=135)
+                                                  default@catalog_sales,catalog_sales,Tbl:COMPLETE,Col:NONE,Output:["cs_sold_date_sk","cs_bill_customer_sk","cs_item_sk","cs_order_number","cs_quantity","cs_wholesale_cost","cs_sales_price"]
+                                        <-Map 19 [SIMPLE_EDGE]
+                                          SHUFFLE [RS_57]
+                                            PartitionCols:_col0, _col1
+                                            Select Operator [SEL_55] (rows=28798881 width=106)
+                                              Output:["_col0","_col1"]
+                                              Filter Operator [FIL_106] (rows=28798881 width=106)
+                                                predicate:cr_item_sk is not null
+                                                TableScan [TS_53] (rows=28798881 width=106)
+                                                  default@catalog_returns,catalog_returns,Tbl:COMPLETE,Col:NONE,Output:["cr_item_sk","cr_order_number"]
+                    <-Reducer 4 [SIMPLE_EDGE]
+                      SHUFFLE [RS_70]
+                        PartitionCols:_col1
+                        Filter Operator [FIL_45] (rows=63887519 width=88)
+                          predicate:(COALESCE(_col7,0) > 0)
+                          Merge Join Operator [MERGEJOIN_113] (rows=191662559 width=88)
+                            Conds:RS_42._col1, _col0=RS_43._col1, _col0(Left Outer),Output:["_col0","_col1","_col2","_col3","_col4","_col7","_col8","_col9"]
+                          <-Reducer 3 [SIMPLE_EDGE]
+                            SHUFFLE [RS_42]
+                              PartitionCols:_col1, _col0
+                              Select Operator [SEL_20] (rows=174238687 width=88)
+                                Output:["_col0","_col1","_col2","_col3","_col4"]
+                                Group By Operator [GBY_19] (rows=174238687 width=88)
+                                  Output:["_col0","_col1","_col2","_col3","_col4"],aggregations:["sum(VALUE._col0)","sum(VALUE._col1)","sum(VALUE._col2)"],keys:KEY._col0, KEY._col1
+                                <-Reducer 2 [SIMPLE_EDGE]
+                                  SHUFFLE [RS_18]
+                                    PartitionCols:_col0, _col1
+                                    Group By Operator [GBY_17] (rows=348477374 width=88)
+                                      Output:["_col0","_col1","_col2","_col3","_col4"],aggregations:["sum(_col6)","sum(_col7)","sum(_col8)"],keys:_col4, _col3
+                                      Merge Join Operator [MERGEJOIN_108] (rows=348477374 width=88)
+                                        Conds:RS_13._col0=RS_14._col0(Inner),Output:["_col3","_col4","_col6","_col7","_col8"]
+                                      <-Map 1 [SIMPLE_EDGE]
+                                        SHUFFLE [RS_13]
+                                          PartitionCols:_col0
+                                          Select Operator [SEL_2] (rows=36524 width=1119)
+                                            Output:["_col0"]
+                                            Filter Operator [FIL_98] (rows=36524 width=1119)
+                                              predicate:((d_year = 2000) and d_date_sk is not null)
+                                               Please refer to the previous TableScan [TS_0]
+                                      <-Reducer 12 [SIMPLE_EDGE]
+                                        SHUFFLE [RS_14]
+                                          PartitionCols:_col0
+                                          Select Operator [SEL_12] (rows=316797606 width=88)
+                                            Output:["_col0","_col1","_col2","_col4","_col5","_col6"]
+                                            Filter Operator [FIL_11] (rows=316797606 width=88)
+                                              predicate:_col8 is null
+                                              Merge Join Operator [MERGEJOIN_107] (rows=633595212 width=88)
+                                                Conds:RS_8._col1, _col3=RS_9._col0, _col1(Left Outer),Output:["_col0","_col1","_col2","_col4","_col5","_col6","_col8"]
+                                              <-Map 11 [SIMPLE_EDGE]
+                                                SHUFFLE [RS_8]
+                                                  PartitionCols:_col1, _col3
+                                                  Select Operator [SEL_5] (rows=575995635 width=88)
+                                                    Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6"]
+                                                    Filter Operator [FIL_99] (rows=575995635 width=88)
+                                                      predicate:ss_sold_date_sk is not null
+                                                      TableScan [TS_3] (rows=575995635 width=88)
+                                                        default@store_sales,store_sales,Tbl:COMPLETE,Col:NONE,Output:["ss_sold_date_sk","ss_item_sk","ss_customer_sk","ss_ticket_number","ss_quantity","ss_wholesale_cost","ss_sales_price"]
+                                              <-Map 13 [SIMPLE_EDGE]
+                                                SHUFFLE [RS_9]
+                                                  PartitionCols:_col0, _col1
+                                                  Select Operator [SEL_7] (rows=57591150 width=77)
+                                                    Output:["_col0","_col1"]
+                                                    TableScan [TS_6] (rows=57591150 width=77)
+                                                      default@store_returns,store_returns,Tbl:COMPLETE,Col:NONE,Output:["sr_item_sk","sr_ticket_number"]
+                          <-Reducer 8 [SIMPLE_EDGE]
+                            SHUFFLE [RS_43]
+                              PartitionCols:_col1, _col0
+                              Select Operator [SEL_41] (rows=43560808 width=135)
+                                Output:["_col0","_col1","_col2","_col3","_col4"]
+                                Group By Operator [GBY_40] (rows=43560808 width=135)
+                                  Output:["_col0","_col1","_col2","_col3","_col4"],aggregations:["sum(VALUE._col0)","sum(VALUE._col1)","sum(VALUE._col2)"],keys:KEY._col0, KEY._col1
+                                <-Reducer 7 [SIMPLE_EDGE]
+                                  SHUFFLE [RS_39]
+                                    PartitionCols:_col0, _col1
+                                    Group By Operator [GBY_38] (rows=87121617 width=135)
+                                      Output:["_col0","_col1","_col2","_col3","_col4"],aggregations:["sum(_col6)","sum(_col7)","sum(_col8)"],keys:_col4, _col3
+                                      Merge Join Operator [MERGEJOIN_110] (rows=87121617 width=135)
+                                        Conds:RS_34._col0=RS_35._col0(Inner),Output:["_col3","_col4","_col6","_col7","_col8"]
+                                      <-Map 1 [SIMPLE_EDGE]
+                                        SHUFFLE [RS_34]
+                                          PartitionCols:_col0
+                                          Select Operator [SEL_23] (rows=36524 width=1119)
+                                            Output:["_col0"]
+                                            Filter Operator [FIL_101] (rows=36524 width=1119)
+                                              predicate:((d_year = 2000) and d_date_sk is not null)
+                                               Please refer to the previous TableScan [TS_0]
+                                      <-Reducer 15 [SIMPLE_EDGE]
+                                        SHUFFLE [RS_35]
+                                          PartitionCols:_col0
+                                          Select Operator [SEL_33] (rows=79201469 width=135)
+                                            Output:["_col0","_col1","_col2","_col4","_col5","_col6"]
+                                            Filter Operator [FIL_32] (rows=79201469 width=135)
+                                              predicate:_col8 is null
+                                              Merge Join Operator [MERGEJOIN_109] (rows=158402938 width=135)
+                                                Conds:RS_29._col1, _col3=RS_30._col0, _col1(Left Outer),Output:["_col0","_col1","_col2","_col4","_col5","_col6","_col8"]
+                                              <-Map 14 [SIMPLE_EDGE]
+                                                SHUFFLE [RS_29]
+                                                  PartitionCols:_col1, _col3
+                                                  Select Operator [SEL_26] (rows=144002668 width=135)
+                                                    Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6"]
+                                                    Filter Operator [FIL_102] (rows=144002668 width=135)
+                                                      predicate:ws_sold_date_sk is not null
+                                                      TableScan [TS_24] (rows=144002668 width=135)
+                                                        default@web_sales,web_sales,Tbl:COMPLETE,Col:NONE,Output:["ws_sold_date_sk","ws_item_sk","ws_bill_customer_sk","ws_order_number","ws_quantity","ws_wholesale_cost","ws_sales_price"]
+                                              <-Map 16 [SIMPLE_EDGE]
+                                                SHUFFLE [RS_30]
+                                                  PartitionCols:_col0, _col1
+                                                  Select Operator [SEL_28] (rows=14398467 width=92)
+                                                    Output:["_col0","_col1"]
+                                                    TableScan [TS_27] (rows=14398467 width=92)
+                                                      default@web_returns,web_returns,Tbl:COMPLETE,Col:NONE,Output:["wr_item_sk","wr_order_number"]
+

http://git-wip-us.apache.org/repos/asf/hive/blob/86b18772/ql/src/test/results/clientpositive/perf/query79.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/perf/query79.q.out b/ql/src/test/results/clientpositive/perf/query79.q.out
index 4955745..18b32e0 100644
--- a/ql/src/test/results/clientpositive/perf/query79.q.out
+++ b/ql/src/test/results/clientpositive/perf/query79.q.out
@@ -1,6 +1,46 @@
-PREHOOK: query: explain select c_last_name,c_first_name,substr(s_city,1,30) sub,ss_ticket_number,amt,profit from (select ss_ticket_number ,ss_customer_sk ,store.s_city ,sum(ss_coupon_amt) amt ,sum(ss_net_profit) profit from store_sales,date_dim,store,household_demographics where store_sales.ss_sold_date_sk = date_dim.d_date_sk and store_sales.ss_store_sk = store.s_store_sk and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk and (household_demographics.hd_dep_count = 8 or household_demographics.hd_vehicle_count > 0) and date_dim.d_dow = 1 and date_dim.d_year in (1998,1998+1,1998+2) and store.s_number_employees between 200 and 295 group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer where ms.ss_customer_sk = customer.c_customer_sk order by c_last_name,c_first_name,sub, profit limit 100
+PREHOOK: query: explain
+select 
+  c_last_name,c_first_name,substr(s_city,1,30),ss_ticket_number,amt,profit
+  from
+   (select ss_ticket_number
+          ,ss_customer_sk
+          ,store.s_city
+          ,sum(ss_coupon_amt) amt
+          ,sum(ss_net_profit) profit
+    from store_sales,date_dim,store,household_demographics
+    where store_sales.ss_sold_date_sk = date_dim.d_date_sk
+    and store_sales.ss_store_sk = store.s_store_sk  
+    and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk
+    and (household_demographics.hd_dep_count = 8 or household_demographics.hd_vehicle_count > 0)
+    and date_dim.d_dow = 1
+    and date_dim.d_year in (1998,1998+1,1998+2) 
+    and store.s_number_employees between 200 and 295
+    group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer
+    where ss_customer_sk = c_customer_sk
+ order by c_last_name,c_first_name,substr(s_city,1,30), profit
+limit 100
 PREHOOK: type: QUERY
-POSTHOOK: query: explain select c_last_name,c_first_name,substr(s_city,1,30) sub,ss_ticket_number,amt,profit from (select ss_ticket_number ,ss_customer_sk ,store.s_city ,sum(ss_coupon_amt) amt ,sum(ss_net_profit) profit from store_sales,date_dim,store,household_demographics where store_sales.ss_sold_date_sk = date_dim.d_date_sk and store_sales.ss_store_sk = store.s_store_sk and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk and (household_demographics.hd_dep_count = 8 or household_demographics.hd_vehicle_count > 0) and date_dim.d_dow = 1 and date_dim.d_year in (1998,1998+1,1998+2) and store.s_number_employees between 200 and 295 group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer where ms.ss_customer_sk = customer.c_customer_sk order by c_last_name,c_first_name,sub, profit limit 100
+POSTHOOK: query: explain
+select 
+  c_last_name,c_first_name,substr(s_city,1,30),ss_ticket_number,amt,profit
+  from
+   (select ss_ticket_number
+          ,ss_customer_sk
+          ,store.s_city
+          ,sum(ss_coupon_amt) amt
+          ,sum(ss_net_profit) profit
+    from store_sales,date_dim,store,household_demographics
+    where store_sales.ss_sold_date_sk = date_dim.d_date_sk
+    and store_sales.ss_store_sk = store.s_store_sk  
+    and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk
+    and (household_demographics.hd_dep_count = 8 or household_demographics.hd_vehicle_count > 0)
+    and date_dim.d_dow = 1
+    and date_dim.d_year in (1998,1998+1,1998+2) 
+    and store.s_number_employees between 200 and 295
+    group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer
+    where ss_customer_sk = c_customer_sk
+ order by c_last_name,c_first_name,substr(s_city,1,30), profit
+limit 100
 POSTHOOK: type: QUERY
 Plan optimized by CBO.
 
@@ -14,10 +54,10 @@ Reducer 8 <- Reducer 7 (SIMPLE_EDGE)
 
 Stage-0
   Fetch Operator
-    limit:100
+    limit:-1
     Stage-1
       Reducer 3
-      File Output Operator [FS_37]
+      File Output Operator [FS_38]
         Limit [LIM_36] (rows=100 width=88)
           Number of rows:100
           Select Operator [SEL_35] (rows=421657640 width=88)
@@ -25,15 +65,15 @@ Stage-0
           <-Reducer 2 [SIMPLE_EDGE]
             SHUFFLE [RS_34]
               Select Operator [SEL_33] (rows=421657640 width=88)
-                Output:["_col0","_col1","_col2","_col3","_col4","_col5"]
-                Merge Join Operator [MERGEJOIN_60] (rows=421657640 width=88)
+                Output:["_col0","_col1","_col3","_col4","_col5","_col6"]
+                Merge Join Operator [MERGEJOIN_61] (rows=421657640 width=88)
                   Conds:RS_30._col0=RS_31._col1(Inner),Output:["_col1","_col2","_col3","_col5","_col6","_col7"]
                 <-Map 1 [SIMPLE_EDGE]
                   SHUFFLE [RS_30]
                     PartitionCols:_col0
                     Select Operator [SEL_2] (rows=80000000 width=860)
                       Output:["_col0","_col1","_col2"]
-                      Filter Operator [FIL_52] (rows=80000000 width=860)
+                      Filter Operator [FIL_53] (rows=80000000 width=860)
                         predicate:c_customer_sk is not null
                         TableScan [TS_0] (rows=80000000 width=860)
                           default@customer,customer,Tbl:COMPLETE,Col:NONE,Output:["c_customer_sk","c_first_name","c_last_name"]
@@ -49,42 +89,42 @@ Stage-0
                           PartitionCols:_col0, _col1, _col2, _col3
                           Group By Operator [GBY_25] (rows=766650239 width=88)
                             Output:["_col0","_col1","_col2","_col3","_col4","_col5"],aggregations:["sum(_col6)","sum(_col7)"],keys:_col1, _col3, _col5, _col13
-                            Merge Join Operator [MERGEJOIN_59] (rows=766650239 width=88)
+                            Merge Join Operator [MERGEJOIN_60] (rows=766650239 width=88)
                               Conds:RS_21._col2=RS_22._col0(Inner),Output:["_col1","_col3","_col5","_col6","_col7","_col13"]
                             <-Map 11 [SIMPLE_EDGE]
                               SHUFFLE [RS_22]
                                 PartitionCols:_col0
                                 Select Operator [SEL_14] (rows=6000 width=107)
                                   Output:["_col0"]
-                                  Filter Operator [FIL_56] (rows=6000 width=107)
+                                  Filter Operator [FIL_57] (rows=6000 width=107)
                                     predicate:(((hd_dep_count = 8) or (hd_vehicle_count > 0)) and hd_demo_sk is not null)
                                     TableScan [TS_12] (rows=7200 width=107)
                                       default@household_demographics,household_demographics,Tbl:COMPLETE,Col:NONE,Output:["hd_demo_sk","hd_dep_count","hd_vehicle_count"]
                             <-Reducer 6 [SIMPLE_EDGE]
                               SHUFFLE [RS_21]
                                 PartitionCols:_col2
-                                Merge Join Operator [MERGEJOIN_58] (rows=696954748 width=88)
+                                Merge Join Operator [MERGEJOIN_59] (rows=696954748 width=88)
                                   Conds:RS_18._col4=RS_19._col0(Inner),Output:["_col1","_col2","_col3","_col5","_col6","_col7","_col13"]
                                 <-Map 10 [SIMPLE_EDGE]
                                   SHUFFLE [RS_19]
                                     PartitionCols:_col0
                                     Select Operator [SEL_11] (rows=189 width=1910)
                                       Output:["_col0","_col2"]
-                                      Filter Operator [FIL_55] (rows=189 width=1910)
+                                      Filter Operator [FIL_56] (rows=189 width=1910)
                                         predicate:(s_number_employees BETWEEN 200 AND 295 and s_store_sk is not null)
                                         TableScan [TS_9] (rows=1704 width=1910)
                                           default@store,store,Tbl:COMPLETE,Col:NONE,Output:["s_store_sk","s_number_employees","s_city"]
                                 <-Reducer 5 [SIMPLE_EDGE]
                                   SHUFFLE [RS_18]
                                     PartitionCols:_col4
-                                    Merge Join Operator [MERGEJOIN_57] (rows=633595212 width=88)
+                                    Merge Join Operator [MERGEJOIN_58] (rows=633595212 width=88)
                                       Conds:RS_15._col0=RS_16._col0(Inner),Output:["_col1","_col2","_col3","_col4","_col5","_col6","_col7"]
                                     <-Map 4 [SIMPLE_EDGE]
                                       SHUFFLE [RS_15]
                                         PartitionCols:_col0
                                         Select Operator [SEL_5] (rows=575995635 width=88)
                                           Output:["_col0","_col1","_col2","_col3","_col4","_col5","_col6","_col7"]
-                                          Filter Operator [FIL_53] (rows=575995635 width=88)
+                                          Filter Operator [FIL_54] (rows=575995635 width=88)
                                             predicate:(ss_sold_date_sk is not null and ss_store_sk is not null and ss_hdemo_sk is not null and ss_customer_sk is not null)
                                             TableScan [TS_3] (rows=575995635 width=88)
                                               default@store_sales,store_sales,Tbl:COMPLETE,Col:NONE,Output:["ss_sold_date_sk","ss_customer_sk","ss_hdemo_sk","ss_addr_sk","ss_store_sk","ss_ticket_number","ss_coupon_amt","ss_net_profit"]
@@ -93,7 +133,7 @@ Stage-0
                                         PartitionCols:_col0
                                         Select Operator [SEL_8] (rows=18262 width=1119)
                                           Output:["_col0"]
-                                          Filter Operator [FIL_54] (rows=18262 width=1119)
+                                          Filter Operator [FIL_55] (rows=18262 width=1119)
                                             predicate:((d_year) IN (1998, 1999, 2000) and (d_dow = 1) 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_year","d_dow"]

http://git-wip-us.apache.org/repos/asf/hive/blob/86b18772/ql/src/test/results/clientpositive/perf/query81.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/perf/query81.q.out b/ql/src/test/results/clientpositive/perf/query81.q.out
index 3acee4d..abeb577 100644
--- a/ql/src/test/results/clientpositive/perf/query81.q.out
+++ b/ql/src/test/results/clientpositive/perf/query81.q.out
@@ -1,4 +1,5 @@
-PREHOOK: query: explain with customer_total_return as
+PREHOOK: query: explain
+with customer_total_return as
  (select cr_returning_customer_sk as ctr_customer_sk
         ,ca_state as ctr_state, 
  	sum(cr_return_amt_inc_tax) as ctr_total_return
@@ -27,7 +28,8 @@ PREHOOK: query: explain with customer_total_return as
                   ,ca_location_type,ctr_total_return
  limit 100
 PREHOOK: type: QUERY
-POSTHOOK: query: explain with customer_total_return as
+POSTHOOK: query: explain
+with customer_total_return as
  (select cr_returning_customer_sk as ctr_customer_sk
         ,ca_state as ctr_state, 
  	sum(cr_return_amt_inc_tax) as ctr_total_return

http://git-wip-us.apache.org/repos/asf/hive/blob/86b18772/ql/src/test/results/clientpositive/perf/query83.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/perf/query83.q.out b/ql/src/test/results/clientpositive/perf/query83.q.out
index f96306b..396c423 100644
--- a/ql/src/test/results/clientpositive/perf/query83.q.out
+++ b/ql/src/test/results/clientpositive/perf/query83.q.out
@@ -1,4 +1,5 @@
-PREHOOK: query: explain with sr_items as
+PREHOOK: query: explain
+with sr_items as
  (select i_item_id item_id,
         sum(sr_return_quantity) sr_item_qty
  from store_returns,
@@ -63,7 +64,8 @@ PREHOOK: query: explain with sr_items as
          ,sr_item_qty
  limit 100
 PREHOOK: type: QUERY
-POSTHOOK: query: explain with sr_items as
+POSTHOOK: query: explain
+with sr_items as
  (select i_item_id item_id,
         sum(sr_return_quantity) sr_item_qty
  from store_returns,

http://git-wip-us.apache.org/repos/asf/hive/blob/86b18772/ql/src/test/results/clientpositive/perf/query84.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/perf/query84.q.out b/ql/src/test/results/clientpositive/perf/query84.q.out
index cf68729..f23cddd 100644
--- a/ql/src/test/results/clientpositive/perf/query84.q.out
+++ b/ql/src/test/results/clientpositive/perf/query84.q.out
@@ -1,6 +1,42 @@
-PREHOOK: query: explain select c_customer_id as customer_id ,concat(c_last_name, ', ', c_first_name) as customername from customer ,customer_address ,customer_demographics ,household_demographics ,income_band ,store_returns where ca_city = 'Hopewell' and customer.c_current_addr_sk = customer_address.ca_address_sk and ib_lower_bound >= 32287 and ib_upper_bound <= 32287 + 50000 and income_band.ib_income_band_sk = household_demographics.hd_income_band_sk and customer_demographics.cd_demo_sk = customer.c_current_cdemo_sk and household_demographics.hd_demo_sk = customer.c_current_hdemo_sk and store_returns.sr_cdemo_sk = customer_demographics.cd_demo_sk order by customer_id limit 100
+PREHOOK: query: explain
+select  c_customer_id as customer_id
+       ,c_last_name || ', ' || c_first_name as customername
+ from customer
+     ,customer_address
+     ,customer_demographics
+     ,household_demographics
+     ,income_band
+     ,store_returns
+ where ca_city	        =  'Hopewell'
+   and c_current_addr_sk = ca_address_sk
+   and ib_lower_bound   >=  32287
+   and ib_upper_bound   <=  32287 + 50000
+   and ib_income_band_sk = hd_income_band_sk
+   and cd_demo_sk = c_current_cdemo_sk
+   and hd_demo_sk = c_current_hdemo_sk
+   and sr_cdemo_sk = cd_demo_sk
+ order by c_customer_id
+ limit 100
 PREHOOK: type: QUERY
-POSTHOOK: query: explain select c_customer_id as customer_id ,concat(c_last_name, ', ', c_first_name) as customername from customer ,customer_address ,customer_demographics ,household_demographics ,income_band ,store_returns where ca_city = 'Hopewell' and customer.c_current_addr_sk = customer_address.ca_address_sk and ib_lower_bound >= 32287 and ib_upper_bound <= 32287 + 50000 and income_band.ib_income_band_sk = household_demographics.hd_income_band_sk and customer_demographics.cd_demo_sk = customer.c_current_cdemo_sk and household_demographics.hd_demo_sk = customer.c_current_hdemo_sk and store_returns.sr_cdemo_sk = customer_demographics.cd_demo_sk order by customer_id limit 100
+POSTHOOK: query: explain
+select  c_customer_id as customer_id
+       ,c_last_name || ', ' || c_first_name as customername
+ from customer
+     ,customer_address
+     ,customer_demographics
+     ,household_demographics
+     ,income_band
+     ,store_returns
+ where ca_city	        =  'Hopewell'
+   and c_current_addr_sk = ca_address_sk
+   and ib_lower_bound   >=  32287
+   and ib_upper_bound   <=  32287 + 50000
+   and ib_income_band_sk = hd_income_band_sk
+   and cd_demo_sk = c_current_cdemo_sk
+   and hd_demo_sk = c_current_hdemo_sk
+   and sr_cdemo_sk = cd_demo_sk
+ order by c_customer_id
+ limit 100
 POSTHOOK: type: QUERY
 Plan optimized by CBO.
 
@@ -13,10 +49,10 @@ Reducer 7 <- Reducer 10 (SIMPLE_EDGE), Reducer 6 (SIMPLE_EDGE)
 
 Stage-0
   Fetch Operator
-    limit:100
+    limit:-1
     Stage-1
       Reducer 3
-      File Output Operator [FS_37]
+      File Output Operator [FS_38]
         Limit [LIM_36] (rows=100 width=860)
           Number of rows:100
           Select Operator [SEL_35] (rows=212960011 width=860)
@@ -24,15 +60,15 @@ Stage-0
           <-Reducer 2 [SIMPLE_EDGE]
             SHUFFLE [RS_34]
               Select Operator [SEL_33] (rows=212960011 width=860)
-                Output:["_col0","_col1"]
-                Merge Join Operator [MERGEJOIN_67] (rows=212960011 width=860)
+                Output:["_col1","_col2"]
+                Merge Join Operator [MERGEJOIN_68] (rows=212960011 width=860)
                   Conds:RS_29._col0=RS_30._col0(Inner),RS_30._col0=RS_31._col1(Inner),Output:["_col2","_col6","_col7"]
                 <-Map 1 [SIMPLE_EDGE]
                   SHUFFLE [RS_29]
                     PartitionCols:_col0
                     Select Operator [SEL_2] (rows=57591150 width=77)
                       Output:["_col0"]
-                      Filter Operator [FIL_58] (rows=57591150 width=77)
+                      Filter Operator [FIL_59] (rows=57591150 width=77)
                         predicate:sr_cdemo_sk is not null
                         TableScan [TS_0] (rows=57591150 width=77)
                           default@store_returns,store_returns,Tbl:COMPLETE,Col:NONE,Output:["sr_cdemo_sk"]
@@ -41,26 +77,26 @@ Stage-0
                     PartitionCols:_col0
                     Select Operator [SEL_5] (rows=1861800 width=385)
                       Output:["_col0"]
-                      Filter Operator [FIL_59] (rows=1861800 width=385)
+                      Filter Operator [FIL_60] (rows=1861800 width=385)
                         predicate:cd_demo_sk is not null
                         TableScan [TS_3] (rows=1861800 width=385)
                           default@customer_demographics,customer_demographics,Tbl:COMPLETE,Col:NONE,Output:["cd_demo_sk"]
                 <-Reducer 7 [SIMPLE_EDGE]
                   SHUFFLE [RS_31]
                     PartitionCols:_col1
-                    Merge Join Operator [MERGEJOIN_66] (rows=96800003 width=860)
+                    Merge Join Operator [MERGEJOIN_67] (rows=96800003 width=860)
                       Conds:RS_25._col2=RS_26._col0(Inner),Output:["_col0","_col1","_col4","_col5"]
                     <-Reducer 10 [SIMPLE_EDGE]
                       SHUFFLE [RS_26]
                         PartitionCols:_col0
-                        Merge Join Operator [MERGEJOIN_65] (rows=7920 width=107)
+                        Merge Join Operator [MERGEJOIN_66] (rows=7920 width=107)
                           Conds:RS_18._col1=RS_19._col0(Inner),Output:["_col0"]
                         <-Map 11 [SIMPLE_EDGE]
                           SHUFFLE [RS_19]
                             PartitionCols:_col0
                             Select Operator [SEL_17] (rows=2 width=12)
                               Output:["_col0"]
-                              Filter Operator [FIL_63] (rows=2 width=12)
+                              Filter Operator [FIL_64] (rows=2 width=12)
                                 predicate:((ib_lower_bound >= 32287) and (ib_upper_bound <= 82287) and ib_income_band_sk is not null)
                                 TableScan [TS_15] (rows=20 width=12)
                                   default@income_band,income_band,Tbl:COMPLETE,Col:NONE,Output:["ib_income_band_sk","ib_lower_bound","ib_upper_bound"]
@@ -69,21 +105,21 @@ Stage-0
                             PartitionCols:_col1
                             Select Operator [SEL_14] (rows=7200 width=107)
                               Output:["_col0","_col1"]
-                              Filter Operator [FIL_62] (rows=7200 width=107)
+                              Filter Operator [FIL_63] (rows=7200 width=107)
                                 predicate:(hd_demo_sk is not null and hd_income_band_sk is not null)
                                 TableScan [TS_12] (rows=7200 width=107)
                                   default@household_demographics,household_demographics,Tbl:COMPLETE,Col:NONE,Output:["hd_demo_sk","hd_income_band_sk"]
                     <-Reducer 6 [SIMPLE_EDGE]
                       SHUFFLE [RS_25]
                         PartitionCols:_col2
-                        Merge Join Operator [MERGEJOIN_64] (rows=88000001 width=860)
+                        Merge Join Operator [MERGEJOIN_65] (rows=88000001 width=860)
                           Conds:RS_22._col3=RS_23._col0(Inner),Output:["_col0","_col1","_col2","_col4","_col5"]
                         <-Map 5 [SIMPLE_EDGE]
                           SHUFFLE [RS_22]
                             PartitionCols:_col3
                             Select Operator [SEL_8] (rows=80000000 width=860)
                               Output:["_col0","_col1","_col2","_col3","_col4","_col5"]
-                              Filter Operator [FIL_60] (rows=80000000 width=860)
+                              Filter Operator [FIL_61] (rows=80000000 width=860)
                                 predicate:(c_current_addr_sk is not null and c_current_cdemo_sk is not null and c_current_hdemo_sk is not null)
                                 TableScan [TS_6] (rows=80000000 width=860)
                                   default@customer,customer,Tbl:COMPLETE,Col:NONE,Output:["c_customer_id","c_current_cdemo_sk","c_current_hdemo_sk","c_current_addr_sk","c_first_name","c_last_name"]
@@ -92,7 +128,7 @@ Stage-0
                             PartitionCols:_col0
                             Select Operator [SEL_11] (rows=20000000 width=1014)
                               Output:["_col0"]
-                              Filter Operator [FIL_61] (rows=20000000 width=1014)
+                              Filter Operator [FIL_62] (rows=20000000 width=1014)
                                 predicate:((ca_city = 'Hopewell') and ca_address_sk is not null)
                                 TableScan [TS_9] (rows=40000000 width=1014)
                                   default@customer_address,customer_address,Tbl:COMPLETE,Col:NONE,Output:["ca_address_sk","ca_city"]

http://git-wip-us.apache.org/repos/asf/hive/blob/86b18772/ql/src/test/results/clientpositive/perf/query85.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/perf/query85.q.out b/ql/src/test/results/clientpositive/perf/query85.q.out
index 82df27b..86b961b 100644
--- a/ql/src/test/results/clientpositive/perf/query85.q.out
+++ b/ql/src/test/results/clientpositive/perf/query85.q.out
@@ -1,6 +1,168 @@
-PREHOOK: query: explain select substr(r_reason_desc,1,20) as r ,avg(ws_quantity) wq ,avg(wr_refunded_cash) ref ,avg(wr_fee) fee from web_sales, web_returns, web_page, customer_demographics cd1, customer_demographics cd2, customer_address, date_dim, reason where web_sales.ws_web_page_sk = web_page.wp_web_page_sk and web_sales.ws_item_sk = web_returns.wr_item_sk and web_sales.ws_order_number = web_returns.wr_order_number and web_sales.ws_sold_date_sk = date_dim.d_date_sk and d_year = 1998 and cd1.cd_demo_sk = web_returns.wr_refunded_cdemo_sk and cd2.cd_demo_sk = web_returns.wr_returning_cdemo_sk and customer_address.ca_address_sk = web_returns.wr_refunded_addr_sk and reason.r_reason_sk = web_returns.wr_reason_sk and ( ( cd1.cd_marital_status = 'M' and cd1.cd_marital_status = cd2.cd_marital_status and cd1.cd_education_status = '4 yr Degree' and cd1.cd_education_status = cd2.cd_education_status and ws_sales_price between 100.00 and 150.00 ) or ( cd1.cd_marital_status = 'D' and cd1.cd_ma
 rital_status = cd2.cd_marital_status and cd1.cd_education_status = 'Primary' and cd1.cd_education_status = cd2.cd_education_status and ws_sales_price between 50.00 and 100.00 ) or ( cd1.cd_marital_status = 'U' and cd1.cd_marital_status = cd2.cd_marital_status and cd1.cd_education_status = 'Advanced Degree' and cd1.cd_education_status = cd2.cd_education_status and ws_sales_price between 150.00 and 200.00 ) ) and ( ( ca_country = 'United States' and ca_state in ('KY', 'GA', 'NM') and ws_net_profit between 100 and 200 ) or ( ca_country = 'United States' and ca_state in ('MT', 'OR', 'IN') and ws_net_profit between 150 and 300 ) or ( ca_country = 'United States' and ca_state in ('WI', 'MO', 'WV') and ws_net_profit between 50 and 250 ) ) group by r_reason_desc order by r, wq, ref, fee limit 100
+PREHOOK: query: explain
+select  substr(r_reason_desc,1,20)
+       ,avg(ws_quantity)
+       ,avg(wr_refunded_cash)
+       ,avg(wr_fee)
+ from web_sales, web_returns, web_page, customer_demographics cd1,
+      customer_demographics cd2, customer_address, date_dim, reason 
+ where ws_web_page_sk = wp_web_page_sk
+   and ws_item_sk = wr_item_sk
+   and ws_order_number = wr_order_number
+   and ws_sold_date_sk = d_date_sk and d_year = 1998
+   and cd1.cd_demo_sk = wr_refunded_cdemo_sk 
+   and cd2.cd_demo_sk = wr_returning_cdemo_sk
+   and ca_address_sk = wr_refunded_addr_sk
+   and r_reason_sk = wr_reason_sk
+   and
+   (
+    (
+     cd1.cd_marital_status = 'M'
+     and
+     cd1.cd_marital_status = cd2.cd_marital_status
+     and
+     cd1.cd_education_status = '4 yr Degree'
+     and 
+     cd1.cd_education_status = cd2.cd_education_status
+     and
+     ws_sales_price between 100.00 and 150.00
+    )
+   or
+    (
+     cd1.cd_marital_status = 'D'
+     and
+     cd1.cd_marital_status = cd2.cd_marital_status
+     and
+     cd1.cd_education_status = 'Primary' 
+     and
+     cd1.cd_education_status = cd2.cd_education_status
+     and
+     ws_sales_price between 50.00 and 100.00
+    )
+   or
+    (
+     cd1.cd_marital_status = 'U'
+     and
+     cd1.cd_marital_status = cd2.cd_marital_status
+     and
+     cd1.cd_education_status = 'Advanced Degree'
+     and
+     cd1.cd_education_status = cd2.cd_education_status
+     and
+     ws_sales_price between 150.00 and 200.00
+    )
+   )
+   and
+   (
+    (
+     ca_country = 'United States'
+     and
+     ca_state in ('KY', 'GA', 'NM')
+     and ws_net_profit between 100 and 200  
+    )
+    or
+    (
+     ca_country = 'United States'
+     and
+     ca_state in ('MT', 'OR', 'IN')
+     and ws_net_profit between 150 and 300  
+    )
+    or
+    (
+     ca_country = 'United States'
+     and
+     ca_state in ('WI', 'MO', 'WV')
+     and ws_net_profit between 50 and 250  
+    )
+   )
+group by r_reason_desc
+order by substr(r_reason_desc,1,20)
+        ,avg(ws_quantity)
+        ,avg(wr_refunded_cash)
+        ,avg(wr_fee)
+limit 100
 PREHOOK: type: QUERY
-POSTHOOK: query: explain select substr(r_reason_desc,1,20) as r ,avg(ws_quantity) wq ,avg(wr_refunded_cash) ref ,avg(wr_fee) fee from web_sales, web_returns, web_page, customer_demographics cd1, customer_demographics cd2, customer_address, date_dim, reason where web_sales.ws_web_page_sk = web_page.wp_web_page_sk and web_sales.ws_item_sk = web_returns.wr_item_sk and web_sales.ws_order_number = web_returns.wr_order_number and web_sales.ws_sold_date_sk = date_dim.d_date_sk and d_year = 1998 and cd1.cd_demo_sk = web_returns.wr_refunded_cdemo_sk and cd2.cd_demo_sk = web_returns.wr_returning_cdemo_sk and customer_address.ca_address_sk = web_returns.wr_refunded_addr_sk and reason.r_reason_sk = web_returns.wr_reason_sk and ( ( cd1.cd_marital_status = 'M' and cd1.cd_marital_status = cd2.cd_marital_status and cd1.cd_education_status = '4 yr Degree' and cd1.cd_education_status = cd2.cd_education_status and ws_sales_price between 100.00 and 150.00 ) or ( cd1.cd_marital_status = 'D' and cd1.cd_m
 arital_status = cd2.cd_marital_status and cd1.cd_education_status = 'Primary' and cd1.cd_education_status = cd2.cd_education_status and ws_sales_price between 50.00 and 100.00 ) or ( cd1.cd_marital_status = 'U' and cd1.cd_marital_status = cd2.cd_marital_status and cd1.cd_education_status = 'Advanced Degree' and cd1.cd_education_status = cd2.cd_education_status and ws_sales_price between 150.00 and 200.00 ) ) and ( ( ca_country = 'United States' and ca_state in ('KY', 'GA', 'NM') and ws_net_profit between 100 and 200 ) or ( ca_country = 'United States' and ca_state in ('MT', 'OR', 'IN') and ws_net_profit between 150 and 300 ) or ( ca_country = 'United States' and ca_state in ('WI', 'MO', 'WV') and ws_net_profit between 50 and 250 ) ) group by r_reason_desc order by r, wq, ref, fee limit 100
+POSTHOOK: query: explain
+select  substr(r_reason_desc,1,20)
+       ,avg(ws_quantity)
+       ,avg(wr_refunded_cash)
+       ,avg(wr_fee)
+ from web_sales, web_returns, web_page, customer_demographics cd1,
+      customer_demographics cd2, customer_address, date_dim, reason 
+ where ws_web_page_sk = wp_web_page_sk
+   and ws_item_sk = wr_item_sk
+   and ws_order_number = wr_order_number
+   and ws_sold_date_sk = d_date_sk and d_year = 1998
+   and cd1.cd_demo_sk = wr_refunded_cdemo_sk 
+   and cd2.cd_demo_sk = wr_returning_cdemo_sk
+   and ca_address_sk = wr_refunded_addr_sk
+   and r_reason_sk = wr_reason_sk
+   and
+   (
+    (
+     cd1.cd_marital_status = 'M'
+     and
+     cd1.cd_marital_status = cd2.cd_marital_status
+     and
+     cd1.cd_education_status = '4 yr Degree'
+     and 
+     cd1.cd_education_status = cd2.cd_education_status
+     and
+     ws_sales_price between 100.00 and 150.00
+    )
+   or
+    (
+     cd1.cd_marital_status = 'D'
+     and
+     cd1.cd_marital_status = cd2.cd_marital_status
+     and
+     cd1.cd_education_status = 'Primary' 
+     and
+     cd1.cd_education_status = cd2.cd_education_status
+     and
+     ws_sales_price between 50.00 and 100.00
+    )
+   or
+    (
+     cd1.cd_marital_status = 'U'
+     and
+     cd1.cd_marital_status = cd2.cd_marital_status
+     and
+     cd1.cd_education_status = 'Advanced Degree'
+     and
+     cd1.cd_education_status = cd2.cd_education_status
+     and
+     ws_sales_price between 150.00 and 200.00
+    )
+   )
+   and
+   (
+    (
+     ca_country = 'United States'
+     and
+     ca_state in ('KY', 'GA', 'NM')
+     and ws_net_profit between 100 and 200  
+    )
+    or
+    (
+     ca_country = 'United States'
+     and
+     ca_state in ('MT', 'OR', 'IN')
+     and ws_net_profit between 150 and 300  
+    )
+    or
+    (
+     ca_country = 'United States'
+     and
+     ca_state in ('WI', 'MO', 'WV')
+     and ws_net_profit between 50 and 250  
+    )
+   )
+group by r_reason_desc
+order by substr(r_reason_desc,1,20)
+        ,avg(ws_quantity)
+        ,avg(wr_refunded_cash)
+        ,avg(wr_fee)
+limit 100
 POSTHOOK: type: QUERY
 Plan optimized by CBO.
 
@@ -28,7 +190,7 @@ Stage-0
           <-Reducer 9 [SIMPLE_EDGE]
             SHUFFLE [RS_52]
               Select Operator [SEL_51] (rows=1023990 width=385)
-                Output:["_col0","_col1","_col2","_col3"]
+                Output:["_col5","_col6","_col7","_col8"]
                 Group By Operator [GBY_50] (rows=1023990 width=385)
                   Output:["_col0","_col1","_col2","_col3"],aggregations:["avg(VALUE._col0)","avg(VALUE._col1)","avg(VALUE._col2)"],keys:KEY._col0
                 <-Reducer 8 [SIMPLE_EDGE]

http://git-wip-us.apache.org/repos/asf/hive/blob/86b18772/ql/src/test/results/clientpositive/perf/query86.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/perf/query86.q.out b/ql/src/test/results/clientpositive/perf/query86.q.out
index bc86291..16f2cb9 100644
--- a/ql/src/test/results/clientpositive/perf/query86.q.out
+++ b/ql/src/test/results/clientpositive/perf/query86.q.out
@@ -5,9 +5,9 @@ select
    ,i_class
    ,grouping(i_category)+grouping(i_class) as lochierarchy
    ,rank() over (
-     partition by grouping(i_category)+grouping(i_class),
-     case when grouping(i_class) = 0 then i_category end 
-     order by sum(ws_net_paid) desc) as rank_within_parent
+ 	partition by grouping(i_category)+grouping(i_class),
+ 	case when grouping(i_class) = 0 then i_category end 
+ 	order by sum(ws_net_paid) desc) as rank_within_parent
  from
     web_sales
    ,date_dim       d1
@@ -30,9 +30,9 @@ select
    ,i_class
    ,grouping(i_category)+grouping(i_class) as lochierarchy
    ,rank() over (
-     partition by grouping(i_category)+grouping(i_class),
-     case when grouping(i_class) = 0 then i_category end 
-     order by sum(ws_net_paid) desc) as rank_within_parent
+ 	partition by grouping(i_category)+grouping(i_class),
+ 	case when grouping(i_class) = 0 then i_category end 
+ 	order by sum(ws_net_paid) desc) as rank_within_parent
  from
     web_sales
    ,date_dim       d1