http://git-wip-us.apache.org/repos/asf/hive/blob/b8299551/ql/src/test/results/clientpositive/perf/tez/cbo_query64.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/perf/tez/cbo_query64.q.out 
b/ql/src/test/results/clientpositive/perf/tez/cbo_query64.q.out
new file mode 100644
index 0000000..3b59bd8
--- /dev/null
+++ b/ql/src/test/results/clientpositive/perf/tez/cbo_query64.q.out
@@ -0,0 +1,438 @@
+PREHOOK: query: explain cbo
+with cs_ui as
+ (select cs_item_sk
+        ,sum(cs_ext_list_price) as 
sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund
+  from catalog_sales
+      ,catalog_returns
+  where cs_item_sk = cr_item_sk
+    and cs_order_number = cr_order_number
+  group by cs_item_sk
+  having 
sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)),
+cross_sales as
+ (select i_product_name product_name
+     ,i_item_sk item_sk
+     ,s_store_name store_name
+     ,s_zip store_zip
+     ,ad1.ca_street_number b_street_number
+     ,ad1.ca_street_name b_streen_name
+     ,ad1.ca_city b_city
+     ,ad1.ca_zip b_zip
+     ,ad2.ca_street_number c_street_number
+     ,ad2.ca_street_name c_street_name
+     ,ad2.ca_city c_city
+     ,ad2.ca_zip c_zip
+     ,d1.d_year as syear
+     ,d2.d_year as fsyear
+     ,d3.d_year s2year
+     ,count(*) cnt
+     ,sum(ss_wholesale_cost) s1
+     ,sum(ss_list_price) s2
+     ,sum(ss_coupon_amt) s3
+  FROM   store_sales
+        ,store_returns
+        ,cs_ui
+        ,date_dim d1
+        ,date_dim d2
+        ,date_dim d3
+        ,store
+        ,customer
+        ,customer_demographics cd1
+        ,customer_demographics cd2
+        ,promotion
+        ,household_demographics hd1
+        ,household_demographics hd2
+        ,customer_address ad1
+        ,customer_address ad2
+        ,income_band ib1
+        ,income_band ib2
+        ,item
+  WHERE  ss_store_sk = s_store_sk AND
+         ss_sold_date_sk = d1.d_date_sk AND
+         ss_customer_sk = c_customer_sk AND
+         ss_cdemo_sk= cd1.cd_demo_sk AND
+         ss_hdemo_sk = hd1.hd_demo_sk AND
+         ss_addr_sk = ad1.ca_address_sk and
+         ss_item_sk = i_item_sk and
+         ss_item_sk = sr_item_sk and
+         ss_ticket_number = sr_ticket_number and
+         ss_item_sk = cs_ui.cs_item_sk and
+         c_current_cdemo_sk = cd2.cd_demo_sk AND
+         c_current_hdemo_sk = hd2.hd_demo_sk AND
+         c_current_addr_sk = ad2.ca_address_sk and
+         c_first_sales_date_sk = d2.d_date_sk and
+         c_first_shipto_date_sk = d3.d_date_sk and
+         ss_promo_sk = p_promo_sk and
+         hd1.hd_income_band_sk = ib1.ib_income_band_sk and
+         hd2.hd_income_band_sk = ib2.ib_income_band_sk and
+         cd1.cd_marital_status <> cd2.cd_marital_status and
+         i_color in ('maroon','burnished','dim','steel','navajo','chocolate') 
and
+         i_current_price between 35 and 35 + 10 and
+         i_current_price between 35 + 1 and 35 + 15
+group by i_product_name
+       ,i_item_sk
+       ,s_store_name
+       ,s_zip
+       ,ad1.ca_street_number
+       ,ad1.ca_street_name
+       ,ad1.ca_city
+       ,ad1.ca_zip
+       ,ad2.ca_street_number
+       ,ad2.ca_street_name
+       ,ad2.ca_city
+       ,ad2.ca_zip
+       ,d1.d_year
+       ,d2.d_year
+       ,d3.d_year
+)
+select cs1.product_name
+     ,cs1.store_name
+     ,cs1.store_zip
+     ,cs1.b_street_number
+     ,cs1.b_streen_name
+     ,cs1.b_city
+     ,cs1.b_zip
+     ,cs1.c_street_number
+     ,cs1.c_street_name
+     ,cs1.c_city
+     ,cs1.c_zip
+     ,cs1.syear
+     ,cs1.cnt
+     ,cs1.s1
+     ,cs1.s2
+     ,cs1.s3
+     ,cs2.s1
+     ,cs2.s2
+     ,cs2.s3
+     ,cs2.syear
+     ,cs2.cnt
+from cross_sales cs1,cross_sales cs2
+where cs1.item_sk=cs2.item_sk and
+     cs1.syear = 2000 and
+     cs2.syear = 2000 + 1 and
+     cs2.cnt <= cs1.cnt and
+     cs1.store_name = cs2.store_name and
+     cs1.store_zip = cs2.store_zip
+order by cs1.product_name
+       ,cs1.store_name
+       ,cs2.cnt
+PREHOOK: type: QUERY
+PREHOOK: Input: default@catalog_returns
+PREHOOK: Input: default@catalog_sales
+PREHOOK: Input: default@customer
+PREHOOK: Input: default@customer_address
+PREHOOK: Input: default@customer_demographics
+PREHOOK: Input: default@date_dim
+PREHOOK: Input: default@household_demographics
+PREHOOK: Input: default@income_band
+PREHOOK: Input: default@item
+PREHOOK: Input: default@promotion
+PREHOOK: Input: default@store
+PREHOOK: Input: default@store_returns
+PREHOOK: Input: default@store_sales
+PREHOOK: Output: hdfs://### HDFS PATH ###
+POSTHOOK: query: explain cbo
+with cs_ui as
+ (select cs_item_sk
+        ,sum(cs_ext_list_price) as 
sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund
+  from catalog_sales
+      ,catalog_returns
+  where cs_item_sk = cr_item_sk
+    and cs_order_number = cr_order_number
+  group by cs_item_sk
+  having 
sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)),
+cross_sales as
+ (select i_product_name product_name
+     ,i_item_sk item_sk
+     ,s_store_name store_name
+     ,s_zip store_zip
+     ,ad1.ca_street_number b_street_number
+     ,ad1.ca_street_name b_streen_name
+     ,ad1.ca_city b_city
+     ,ad1.ca_zip b_zip
+     ,ad2.ca_street_number c_street_number
+     ,ad2.ca_street_name c_street_name
+     ,ad2.ca_city c_city
+     ,ad2.ca_zip c_zip
+     ,d1.d_year as syear
+     ,d2.d_year as fsyear
+     ,d3.d_year s2year
+     ,count(*) cnt
+     ,sum(ss_wholesale_cost) s1
+     ,sum(ss_list_price) s2
+     ,sum(ss_coupon_amt) s3
+  FROM   store_sales
+        ,store_returns
+        ,cs_ui
+        ,date_dim d1
+        ,date_dim d2
+        ,date_dim d3
+        ,store
+        ,customer
+        ,customer_demographics cd1
+        ,customer_demographics cd2
+        ,promotion
+        ,household_demographics hd1
+        ,household_demographics hd2
+        ,customer_address ad1
+        ,customer_address ad2
+        ,income_band ib1
+        ,income_band ib2
+        ,item
+  WHERE  ss_store_sk = s_store_sk AND
+         ss_sold_date_sk = d1.d_date_sk AND
+         ss_customer_sk = c_customer_sk AND
+         ss_cdemo_sk= cd1.cd_demo_sk AND
+         ss_hdemo_sk = hd1.hd_demo_sk AND
+         ss_addr_sk = ad1.ca_address_sk and
+         ss_item_sk = i_item_sk and
+         ss_item_sk = sr_item_sk and
+         ss_ticket_number = sr_ticket_number and
+         ss_item_sk = cs_ui.cs_item_sk and
+         c_current_cdemo_sk = cd2.cd_demo_sk AND
+         c_current_hdemo_sk = hd2.hd_demo_sk AND
+         c_current_addr_sk = ad2.ca_address_sk and
+         c_first_sales_date_sk = d2.d_date_sk and
+         c_first_shipto_date_sk = d3.d_date_sk and
+         ss_promo_sk = p_promo_sk and
+         hd1.hd_income_band_sk = ib1.ib_income_band_sk and
+         hd2.hd_income_band_sk = ib2.ib_income_band_sk and
+         cd1.cd_marital_status <> cd2.cd_marital_status and
+         i_color in ('maroon','burnished','dim','steel','navajo','chocolate') 
and
+         i_current_price between 35 and 35 + 10 and
+         i_current_price between 35 + 1 and 35 + 15
+group by i_product_name
+       ,i_item_sk
+       ,s_store_name
+       ,s_zip
+       ,ad1.ca_street_number
+       ,ad1.ca_street_name
+       ,ad1.ca_city
+       ,ad1.ca_zip
+       ,ad2.ca_street_number
+       ,ad2.ca_street_name
+       ,ad2.ca_city
+       ,ad2.ca_zip
+       ,d1.d_year
+       ,d2.d_year
+       ,d3.d_year
+)
+select cs1.product_name
+     ,cs1.store_name
+     ,cs1.store_zip
+     ,cs1.b_street_number
+     ,cs1.b_streen_name
+     ,cs1.b_city
+     ,cs1.b_zip
+     ,cs1.c_street_number
+     ,cs1.c_street_name
+     ,cs1.c_city
+     ,cs1.c_zip
+     ,cs1.syear
+     ,cs1.cnt
+     ,cs1.s1
+     ,cs1.s2
+     ,cs1.s3
+     ,cs2.s1
+     ,cs2.s2
+     ,cs2.s3
+     ,cs2.syear
+     ,cs2.cnt
+from cross_sales cs1,cross_sales cs2
+where cs1.item_sk=cs2.item_sk and
+     cs1.syear = 2000 and
+     cs2.syear = 2000 + 1 and
+     cs2.cnt <= cs1.cnt and
+     cs1.store_name = cs2.store_name and
+     cs1.store_zip = cs2.store_zip
+order by cs1.product_name
+       ,cs1.store_name
+       ,cs2.cnt
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@catalog_returns
+POSTHOOK: Input: default@catalog_sales
+POSTHOOK: Input: default@customer
+POSTHOOK: Input: default@customer_address
+POSTHOOK: Input: default@customer_demographics
+POSTHOOK: Input: default@date_dim
+POSTHOOK: Input: default@household_demographics
+POSTHOOK: Input: default@income_band
+POSTHOOK: Input: default@item
+POSTHOOK: Input: default@promotion
+POSTHOOK: Input: default@store
+POSTHOOK: Input: default@store_returns
+POSTHOOK: Input: default@store_sales
+POSTHOOK: Output: hdfs://### HDFS PATH ###
+CBO PLAN:
+HiveProject(product_name=[$0], store_name=[$1], store_zip=[$2], 
b_street_number=[$3], b_streen_name=[$4], b_city=[$5], b_zip=[$6], 
c_street_number=[$7], c_street_name=[$8], c_city=[$9], c_zip=[$10], 
syear=[CAST(2000):INTEGER], cnt=[$11], s1=[$12], s2=[$13], s3=[$14], s11=[$15], 
s21=[$16], s31=[$17], syear1=[CAST(2001):INTEGER], cnt1=[$18])
+  HiveSortLimit(sort0=[$0], sort1=[$1], sort2=[$18], dir0=[ASC], dir1=[ASC], 
dir2=[ASC])
+    HiveProject(product_name=[$0], store_name=[$2], store_zip=[$3], 
b_street_number=[$4], b_streen_name=[$5], b_city=[$6], b_zip=[$7], 
c_street_number=[$8], c_street_name=[$9], c_city=[$10], c_zip=[$11], cnt=[$12], 
s1=[$13], s2=[$14], s3=[$15], s11=[$20], s21=[$21], s31=[$22], cnt1=[$19])
+      HiveJoin(condition=[AND(AND(AND(=($1, $16), <=($19, $12)), =($2, $17)), 
=($3, $18))], joinType=[inner], algorithm=[none], cost=[not available])
+        HiveProject($f0=[$13], $f1=[$12], $f2=[$10], $f3=[$11], $f4=[$6], 
$f5=[$7], $f6=[$8], $f7=[$9], $f8=[$2], $f9=[$3], $f10=[$4], $f11=[$5], 
$f15=[$14], $f16=[$15], $f17=[$16], $f18=[$17])
+          HiveAggregate(group=[{9, 11, 16, 17, 18, 19, 25, 26, 27, 28, 30, 31, 
48, 51}], agg#0=[count()], agg#1=[sum($45)], agg#2=[sum($46)], agg#3=[sum($47)])
+            HiveJoin(condition=[AND(<>($1, $21), =($39, $0))], 
joinType=[inner], algorithm=[none], cost=[not available])
+              HiveProject(cd_demo_sk=[$0], cd_marital_status=[$2])
+                HiveFilter(condition=[IS NOT NULL($0)])
+                  HiveTableScan(table=[[default, customer_demographics]], 
table:alias=[cd1])
+              HiveJoin(condition=[=($36, $0)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                HiveJoin(condition=[=($1, $18)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                  HiveJoin(condition=[=($3, $13)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                    HiveJoin(condition=[=($2, $10)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                      HiveJoin(condition=[=($4, $8)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                        HiveJoin(condition=[=($5, $6)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                          HiveProject(c_customer_sk=[$0], 
c_current_cdemo_sk=[$2], c_current_hdemo_sk=[$3], c_current_addr_sk=[$4], 
c_first_shipto_date_sk=[$5], c_first_sales_date_sk=[$6])
+                            HiveFilter(condition=[AND(IS NOT NULL($0), IS NOT 
NULL($6), IS NOT NULL($5), IS NOT NULL($2), IS NOT NULL($3), IS NOT NULL($4))])
+                              HiveTableScan(table=[[default, customer]], 
table:alias=[customer])
+                          HiveProject(d_date_sk=[$0], d_year=[$6])
+                            HiveFilter(condition=[IS NOT NULL($0)])
+                              HiveTableScan(table=[[default, date_dim]], 
table:alias=[d2])
+                        HiveProject(d_date_sk=[$0], d_year=[$6])
+                          HiveFilter(condition=[IS NOT NULL($0)])
+                            HiveTableScan(table=[[default, date_dim]], 
table:alias=[d3])
+                      HiveProject(hd_demo_sk=[$0], hd_income_band_sk=[$1], 
ib_income_band_sk=[$2])
+                        HiveJoin(condition=[=($1, $2)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                          HiveProject(hd_demo_sk=[$0], hd_income_band_sk=[$1])
+                            HiveFilter(condition=[AND(IS NOT NULL($0), IS NOT 
NULL($1))])
+                              HiveTableScan(table=[[default, 
household_demographics]], table:alias=[hd2])
+                          HiveProject(ib_income_band_sk=[$0])
+                            HiveFilter(condition=[IS NOT NULL($0)])
+                              HiveTableScan(table=[[default, income_band]], 
table:alias=[ib2])
+                    HiveProject(ca_address_sk=[$0], ca_street_number=[$2], 
ca_street_name=[$3], ca_city=[$6], ca_zip=[$9])
+                      HiveFilter(condition=[IS NOT NULL($0)])
+                        HiveTableScan(table=[[default, customer_address]], 
table:alias=[ad2])
+                  HiveProject(cd_demo_sk=[$0], cd_marital_status=[$2])
+                    HiveFilter(condition=[IS NOT NULL($0)])
+                      HiveTableScan(table=[[default, customer_demographics]], 
table:alias=[cd2])
+                HiveProject(sr_item_sk=[$0], sr_ticket_number=[$1], 
ca_address_sk=[$2], ca_street_number=[$3], ca_street_name=[$4], ca_city=[$5], 
ca_zip=[$6], s_store_sk=[$7], s_store_name=[$8], s_zip=[$9], hd_demo_sk=[$10], 
hd_income_band_sk=[$11], ib_income_band_sk=[$12], p_promo_sk=[$13], 
ss_sold_date_sk=[$14], ss_item_sk=[$15], ss_customer_sk=[$16], 
ss_cdemo_sk=[$17], ss_hdemo_sk=[$18], ss_addr_sk=[$19], ss_store_sk=[$20], 
ss_promo_sk=[$21], ss_ticket_number=[$22], ss_wholesale_cost=[$23], 
ss_list_price=[$24], ss_coupon_amt=[$25], i_item_sk=[$26], 
i_current_price=[$27], i_color=[$28], i_product_name=[$29], d_date_sk=[$30], 
d_year=[$31], $f0=[$32], $f1=[$33], $f2=[$34])
+                  HiveJoin(condition=[AND(=($15, $0), =($22, $1))], 
joinType=[inner], algorithm=[none], cost=[not available])
+                    HiveProject(sr_item_sk=[$2], sr_ticket_number=[$9])
+                      HiveFilter(condition=[AND(IS NOT NULL($2), IS NOT 
NULL($9))])
+                        HiveTableScan(table=[[default, store_returns]], 
table:alias=[store_returns])
+                    HiveJoin(condition=[=($17, $0)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                      HiveProject(ca_address_sk=[$0], ca_street_number=[$2], 
ca_street_name=[$3], ca_city=[$6], ca_zip=[$9])
+                        HiveFilter(condition=[IS NOT NULL($0)])
+                          HiveTableScan(table=[[default, customer_address]], 
table:alias=[ad1])
+                      HiveJoin(condition=[=($13, $0)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                        HiveProject(s_store_sk=[$0], s_store_name=[$5], 
s_zip=[$25])
+                          HiveFilter(condition=[AND(IS NOT NULL($0), IS NOT 
NULL($5), IS NOT NULL($25))])
+                            HiveTableScan(table=[[default, store]], 
table:alias=[store])
+                        HiveJoin(condition=[=($5, $22)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                          HiveJoin(condition=[=($8, $0)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                            HiveJoin(condition=[=($1, $2)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                              HiveProject(hd_demo_sk=[$0], 
hd_income_band_sk=[$1])
+                                HiveFilter(condition=[AND(IS NOT NULL($0), IS 
NOT NULL($1))])
+                                  HiveTableScan(table=[[default, 
household_demographics]], table:alias=[hd1])
+                              HiveProject(ib_income_band_sk=[$0])
+                                HiveFilter(condition=[IS NOT NULL($0)])
+                                  HiveTableScan(table=[[default, 
income_band]], table:alias=[ib1])
+                            HiveProject(p_promo_sk=[$0], ss_sold_date_sk=[$1], 
ss_item_sk=[$2], ss_customer_sk=[$3], ss_cdemo_sk=[$4], ss_hdemo_sk=[$5], 
ss_addr_sk=[$6], ss_store_sk=[$7], ss_promo_sk=[$8], ss_ticket_number=[$9], 
ss_wholesale_cost=[$10], ss_list_price=[$11], ss_coupon_amt=[$12], 
i_item_sk=[$13], i_current_price=[$14], i_color=[$15], i_product_name=[$16], 
d_date_sk=[$17], d_year=[$18])
+                              HiveJoin(condition=[=($8, $0)], 
joinType=[inner], algorithm=[none], cost=[not available])
+                                HiveProject(p_promo_sk=[$0])
+                                  HiveFilter(condition=[IS NOT NULL($0)])
+                                    HiveTableScan(table=[[default, 
promotion]], table:alias=[promotion])
+                                HiveJoin(condition=[=($0, $16)], 
joinType=[inner], algorithm=[none], cost=[not available])
+                                  HiveJoin(condition=[=($1, $12)], 
joinType=[inner], algorithm=[none], cost=[not available])
+                                    HiveProject(ss_sold_date_sk=[$0], 
ss_item_sk=[$2], ss_customer_sk=[$3], ss_cdemo_sk=[$4], ss_hdemo_sk=[$5], 
ss_addr_sk=[$6], ss_store_sk=[$7], ss_promo_sk=[$8], ss_ticket_number=[$9], 
ss_wholesale_cost=[$11], ss_list_price=[$12], ss_coupon_amt=[$19])
+                                      HiveFilter(condition=[AND(IS NOT 
NULL($2), IS NOT NULL($9), IS NOT NULL($0), IS NOT NULL($7), IS NOT NULL($3), 
IS NOT NULL($4), IS NOT NULL($8), IS NOT NULL($5), IS NOT NULL($6))])
+                                        HiveTableScan(table=[[default, 
store_sales]], table:alias=[store_sales])
+                                    HiveProject(i_item_sk=[$0], 
i_current_price=[$5], i_color=[$17], i_product_name=[$21])
+                                      HiveFilter(condition=[AND(IN($17, 
_UTF-16LE'maroon', _UTF-16LE'burnished', _UTF-16LE'dim', _UTF-16LE'steel', 
_UTF-16LE'navajo', _UTF-16LE'chocolate'), BETWEEN(false, $5, 35, 45), 
BETWEEN(false, $5, 36, 50), IS NOT NULL($0))])
+                                        HiveTableScan(table=[[default, item]], 
table:alias=[item])
+                                  HiveProject(d_date_sk=[$0], 
d_year=[CAST(2000):INTEGER])
+                                    HiveFilter(condition=[AND(=($6, 2000), IS 
NOT NULL($0))])
+                                      HiveTableScan(table=[[default, 
date_dim]], table:alias=[d1])
+                          HiveProject($f0=[$0], $f1=[$1], $f2=[$2])
+                            HiveFilter(condition=[>($1, *(2, $2))])
+                              HiveAggregate(group=[{0}], agg#0=[sum($1)], 
agg#1=[sum($2)])
+                                HiveProject($f0=[$0], $f1=[$2], $f2=[+(+($5, 
$6), $7)])
+                                  HiveJoin(condition=[AND(=($0, $3), =($1, 
$4))], joinType=[inner], algorithm=[none], cost=[not available])
+                                    HiveProject(cs_item_sk=[$15], 
cs_order_number=[$17], cs_ext_list_price=[$25])
+                                      HiveFilter(condition=[AND(IS NOT 
NULL($15), IS NOT NULL($17))])
+                                        HiveTableScan(table=[[default, 
catalog_sales]], table:alias=[catalog_sales])
+                                    HiveProject(cr_item_sk=[$2], 
cr_order_number=[$16], cr_refunded_cash=[$23], cr_reversed_charge=[$24], 
cr_store_credit=[$25])
+                                      HiveFilter(condition=[AND(IS NOT 
NULL($2), IS NOT NULL($16))])
+                                        HiveTableScan(table=[[default, 
catalog_returns]], table:alias=[catalog_returns])
+        HiveProject($f1=[$12], $f2=[$10], $f3=[$11], $f15=[$14], $f16=[$15], 
$f17=[$16], $f18=[$17])
+          HiveAggregate(group=[{9, 11, 16, 17, 18, 19, 25, 26, 27, 28, 30, 31, 
48, 51}], agg#0=[count()], agg#1=[sum($45)], agg#2=[sum($46)], agg#3=[sum($47)])
+            HiveJoin(condition=[AND(<>($1, $21), =($39, $0))], 
joinType=[inner], algorithm=[none], cost=[not available])
+              HiveProject(cd_demo_sk=[$0], cd_marital_status=[$2])
+                HiveFilter(condition=[IS NOT NULL($0)])
+                  HiveTableScan(table=[[default, customer_demographics]], 
table:alias=[cd1])
+              HiveJoin(condition=[=($36, $0)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                HiveJoin(condition=[=($1, $18)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                  HiveJoin(condition=[=($3, $13)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                    HiveJoin(condition=[=($2, $10)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                      HiveJoin(condition=[=($4, $8)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                        HiveJoin(condition=[=($5, $6)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                          HiveProject(c_customer_sk=[$0], 
c_current_cdemo_sk=[$2], c_current_hdemo_sk=[$3], c_current_addr_sk=[$4], 
c_first_shipto_date_sk=[$5], c_first_sales_date_sk=[$6])
+                            HiveFilter(condition=[AND(IS NOT NULL($0), IS NOT 
NULL($6), IS NOT NULL($5), IS NOT NULL($2), IS NOT NULL($3), IS NOT NULL($4))])
+                              HiveTableScan(table=[[default, customer]], 
table:alias=[customer])
+                          HiveProject(d_date_sk=[$0], d_year=[$6])
+                            HiveFilter(condition=[IS NOT NULL($0)])
+                              HiveTableScan(table=[[default, date_dim]], 
table:alias=[d2])
+                        HiveProject(d_date_sk=[$0], d_year=[$6])
+                          HiveFilter(condition=[IS NOT NULL($0)])
+                            HiveTableScan(table=[[default, date_dim]], 
table:alias=[d3])
+                      HiveProject(hd_demo_sk=[$0], hd_income_band_sk=[$1], 
ib_income_band_sk=[$2])
+                        HiveJoin(condition=[=($1, $2)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                          HiveProject(hd_demo_sk=[$0], hd_income_band_sk=[$1])
+                            HiveFilter(condition=[AND(IS NOT NULL($0), IS NOT 
NULL($1))])
+                              HiveTableScan(table=[[default, 
household_demographics]], table:alias=[hd2])
+                          HiveProject(ib_income_band_sk=[$0])
+                            HiveFilter(condition=[IS NOT NULL($0)])
+                              HiveTableScan(table=[[default, income_band]], 
table:alias=[ib2])
+                    HiveProject(ca_address_sk=[$0], ca_street_number=[$2], 
ca_street_name=[$3], ca_city=[$6], ca_zip=[$9])
+                      HiveFilter(condition=[IS NOT NULL($0)])
+                        HiveTableScan(table=[[default, customer_address]], 
table:alias=[ad2])
+                  HiveProject(cd_demo_sk=[$0], cd_marital_status=[$2])
+                    HiveFilter(condition=[IS NOT NULL($0)])
+                      HiveTableScan(table=[[default, customer_demographics]], 
table:alias=[cd2])
+                HiveProject(sr_item_sk=[$0], sr_ticket_number=[$1], 
ca_address_sk=[$2], ca_street_number=[$3], ca_street_name=[$4], ca_city=[$5], 
ca_zip=[$6], s_store_sk=[$7], s_store_name=[$8], s_zip=[$9], hd_demo_sk=[$10], 
hd_income_band_sk=[$11], ib_income_band_sk=[$12], p_promo_sk=[$13], 
ss_sold_date_sk=[$14], ss_item_sk=[$15], ss_customer_sk=[$16], 
ss_cdemo_sk=[$17], ss_hdemo_sk=[$18], ss_addr_sk=[$19], ss_store_sk=[$20], 
ss_promo_sk=[$21], ss_ticket_number=[$22], ss_wholesale_cost=[$23], 
ss_list_price=[$24], ss_coupon_amt=[$25], i_item_sk=[$26], 
i_current_price=[$27], i_color=[$28], i_product_name=[$29], d_date_sk=[$30], 
d_year=[$31], $f0=[$32], $f1=[$33], $f2=[$34])
+                  HiveJoin(condition=[AND(=($15, $0), =($22, $1))], 
joinType=[inner], algorithm=[none], cost=[not available])
+                    HiveProject(sr_item_sk=[$2], sr_ticket_number=[$9])
+                      HiveFilter(condition=[AND(IS NOT NULL($2), IS NOT 
NULL($9))])
+                        HiveTableScan(table=[[default, store_returns]], 
table:alias=[store_returns])
+                    HiveJoin(condition=[=($17, $0)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                      HiveProject(ca_address_sk=[$0], ca_street_number=[$2], 
ca_street_name=[$3], ca_city=[$6], ca_zip=[$9])
+                        HiveFilter(condition=[IS NOT NULL($0)])
+                          HiveTableScan(table=[[default, customer_address]], 
table:alias=[ad1])
+                      HiveJoin(condition=[=($13, $0)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                        HiveProject(s_store_sk=[$0], s_store_name=[$5], 
s_zip=[$25])
+                          HiveFilter(condition=[AND(IS NOT NULL($0), IS NOT 
NULL($5), IS NOT NULL($25))])
+                            HiveTableScan(table=[[default, store]], 
table:alias=[store])
+                        HiveJoin(condition=[=($5, $22)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                          HiveJoin(condition=[=($8, $0)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                            HiveJoin(condition=[=($1, $2)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                              HiveProject(hd_demo_sk=[$0], 
hd_income_band_sk=[$1])
+                                HiveFilter(condition=[AND(IS NOT NULL($0), IS 
NOT NULL($1))])
+                                  HiveTableScan(table=[[default, 
household_demographics]], table:alias=[hd1])
+                              HiveProject(ib_income_band_sk=[$0])
+                                HiveFilter(condition=[IS NOT NULL($0)])
+                                  HiveTableScan(table=[[default, 
income_band]], table:alias=[ib1])
+                            HiveProject(p_promo_sk=[$0], ss_sold_date_sk=[$1], 
ss_item_sk=[$2], ss_customer_sk=[$3], ss_cdemo_sk=[$4], ss_hdemo_sk=[$5], 
ss_addr_sk=[$6], ss_store_sk=[$7], ss_promo_sk=[$8], ss_ticket_number=[$9], 
ss_wholesale_cost=[$10], ss_list_price=[$11], ss_coupon_amt=[$12], 
i_item_sk=[$13], i_current_price=[$14], i_color=[$15], i_product_name=[$16], 
d_date_sk=[$17], d_year=[$18])
+                              HiveJoin(condition=[=($8, $0)], 
joinType=[inner], algorithm=[none], cost=[not available])
+                                HiveProject(p_promo_sk=[$0])
+                                  HiveFilter(condition=[IS NOT NULL($0)])
+                                    HiveTableScan(table=[[default, 
promotion]], table:alias=[promotion])
+                                HiveJoin(condition=[=($0, $16)], 
joinType=[inner], algorithm=[none], cost=[not available])
+                                  HiveJoin(condition=[=($1, $12)], 
joinType=[inner], algorithm=[none], cost=[not available])
+                                    HiveProject(ss_sold_date_sk=[$0], 
ss_item_sk=[$2], ss_customer_sk=[$3], ss_cdemo_sk=[$4], ss_hdemo_sk=[$5], 
ss_addr_sk=[$6], ss_store_sk=[$7], ss_promo_sk=[$8], ss_ticket_number=[$9], 
ss_wholesale_cost=[$11], ss_list_price=[$12], ss_coupon_amt=[$19])
+                                      HiveFilter(condition=[AND(IS NOT 
NULL($2), IS NOT NULL($9), IS NOT NULL($0), IS NOT NULL($7), IS NOT NULL($3), 
IS NOT NULL($4), IS NOT NULL($8), IS NOT NULL($5), IS NOT NULL($6))])
+                                        HiveTableScan(table=[[default, 
store_sales]], table:alias=[store_sales])
+                                    HiveProject(i_item_sk=[$0], 
i_current_price=[$5], i_color=[$17], i_product_name=[$21])
+                                      HiveFilter(condition=[AND(IN($17, 
_UTF-16LE'maroon', _UTF-16LE'burnished', _UTF-16LE'dim', _UTF-16LE'steel', 
_UTF-16LE'navajo', _UTF-16LE'chocolate'), BETWEEN(false, $5, 35, 45), 
BETWEEN(false, $5, 36, 50), IS NOT NULL($0))])
+                                        HiveTableScan(table=[[default, item]], 
table:alias=[item])
+                                  HiveProject(d_date_sk=[$0], 
d_year=[CAST(2001):INTEGER])
+                                    HiveFilter(condition=[AND(=($6, 2001), IS 
NOT NULL($0))])
+                                      HiveTableScan(table=[[default, 
date_dim]], table:alias=[d1])
+                          HiveProject($f0=[$0], $f1=[$1], $f2=[$2])
+                            HiveFilter(condition=[>($1, *(2, $2))])
+                              HiveAggregate(group=[{0}], agg#0=[sum($1)], 
agg#1=[sum($2)])
+                                HiveProject($f0=[$0], $f1=[$2], $f2=[+(+($5, 
$6), $7)])
+                                  HiveJoin(condition=[AND(=($0, $3), =($1, 
$4))], joinType=[inner], algorithm=[none], cost=[not available])
+                                    HiveProject(cs_item_sk=[$15], 
cs_order_number=[$17], cs_ext_list_price=[$25])
+                                      HiveFilter(condition=[AND(IS NOT 
NULL($15), IS NOT NULL($17))])
+                                        HiveTableScan(table=[[default, 
catalog_sales]], table:alias=[catalog_sales])
+                                    HiveProject(cr_item_sk=[$2], 
cr_order_number=[$16], cr_refunded_cash=[$23], cr_reversed_charge=[$24], 
cr_store_credit=[$25])
+                                      HiveFilter(condition=[AND(IS NOT 
NULL($2), IS NOT NULL($16))])
+                                        HiveTableScan(table=[[default, 
catalog_returns]], table:alias=[catalog_returns])
+

http://git-wip-us.apache.org/repos/asf/hive/blob/b8299551/ql/src/test/results/clientpositive/perf/tez/cbo_query65.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/perf/tez/cbo_query65.q.out 
b/ql/src/test/results/clientpositive/perf/tez/cbo_query65.q.out
new file mode 100644
index 0000000..1b154a4
--- /dev/null
+++ b/ql/src/test/results/clientpositive/perf/tez/cbo_query65.q.out
@@ -0,0 +1,99 @@
+PREHOOK: query: explain cbo
+select 
+       s_store_name,
+       i_item_desc,
+       sc.revenue,
+       i_current_price,
+       i_wholesale_cost,
+       i_brand
+ from store, item,
+     (select ss_store_sk, avg(revenue) as ave
+       from
+           (select  ss_store_sk, ss_item_sk, 
+                    sum(ss_sales_price) as revenue
+               from store_sales, date_dim
+               where ss_sold_date_sk = d_date_sk and d_month_seq between 1212 
and 1212+11
+               group by ss_store_sk, ss_item_sk) sa
+       group by ss_store_sk) sb,
+     (select  ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue
+       from store_sales, date_dim
+       where ss_sold_date_sk = d_date_sk and d_month_seq between 1212 and 
1212+11
+       group by ss_store_sk, ss_item_sk) sc
+ where sb.ss_store_sk = sc.ss_store_sk and 
+       sc.revenue <= 0.1 * sb.ave and
+       s_store_sk = sc.ss_store_sk and
+       i_item_sk = sc.ss_item_sk
+ order by s_store_name, i_item_desc
+limit 100
+PREHOOK: type: QUERY
+PREHOOK: Input: default@date_dim
+PREHOOK: Input: default@item
+PREHOOK: Input: default@store
+PREHOOK: Input: default@store_sales
+PREHOOK: Output: hdfs://### HDFS PATH ###
+POSTHOOK: query: explain cbo
+select 
+       s_store_name,
+       i_item_desc,
+       sc.revenue,
+       i_current_price,
+       i_wholesale_cost,
+       i_brand
+ from store, item,
+     (select ss_store_sk, avg(revenue) as ave
+       from
+           (select  ss_store_sk, ss_item_sk, 
+                    sum(ss_sales_price) as revenue
+               from store_sales, date_dim
+               where ss_sold_date_sk = d_date_sk and d_month_seq between 1212 
and 1212+11
+               group by ss_store_sk, ss_item_sk) sa
+       group by ss_store_sk) sb,
+     (select  ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue
+       from store_sales, date_dim
+       where ss_sold_date_sk = d_date_sk and d_month_seq between 1212 and 
1212+11
+       group by ss_store_sk, ss_item_sk) sc
+ where sb.ss_store_sk = sc.ss_store_sk and 
+       sc.revenue <= 0.1 * sb.ave and
+       s_store_sk = sc.ss_store_sk and
+       i_item_sk = sc.ss_item_sk
+ order by s_store_name, i_item_desc
+limit 100
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@date_dim
+POSTHOOK: Input: default@item
+POSTHOOK: Input: default@store
+POSTHOOK: Input: default@store_sales
+POSTHOOK: Output: hdfs://### HDFS PATH ###
+CBO PLAN:
+HiveSortLimit(sort0=[$0], sort1=[$1], dir0=[ASC], dir1=[ASC], fetch=[100])
+  HiveProject(s_store_name=[$11], i_item_desc=[$1], revenue=[$7], 
i_current_price=[$2], i_wholesale_cost=[$3], i_brand=[$4])
+    HiveJoin(condition=[=($0, $6)], joinType=[inner], algorithm=[none], 
cost=[not available])
+      HiveProject(i_item_sk=[$0], i_item_desc=[$4], i_current_price=[$5], 
i_wholesale_cost=[$6], i_brand=[$8])
+        HiveFilter(condition=[IS NOT NULL($0)])
+          HiveTableScan(table=[[default, item]], table:alias=[item])
+      HiveJoin(condition=[=($5, $0)], joinType=[inner], algorithm=[none], 
cost=[not available])
+        HiveJoin(condition=[AND(=($3, $0), <=($2, *(0.1, $4)))], 
joinType=[inner], algorithm=[none], cost=[not available])
+          HiveProject(ss_store_sk=[$1], ss_item_sk=[$0], $f2=[$2])
+            HiveAggregate(group=[{1, 2}], agg#0=[sum($3)])
+              HiveJoin(condition=[=($0, $4)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                HiveProject(ss_sold_date_sk=[$0], ss_item_sk=[$2], 
ss_store_sk=[$7], ss_sales_price=[$13])
+                  HiveFilter(condition=[AND(IS NOT NULL($0), IS NOT NULL($7), 
IS NOT NULL($2))])
+                    HiveTableScan(table=[[default, store_sales]], 
table:alias=[store_sales])
+                HiveProject(d_date_sk=[$0], d_month_seq=[$3])
+                  HiveFilter(condition=[AND(BETWEEN(false, $3, 1212, 1223), IS 
NOT NULL($0))])
+                    HiveTableScan(table=[[default, date_dim]], 
table:alias=[date_dim])
+          HiveProject($f0=[$0], $f1=[/($1, $2)])
+            HiveAggregate(group=[{1}], agg#0=[sum($2)], agg#1=[count($2)])
+              HiveProject(ss_item_sk=[$0], ss_store_sk=[$1], $f2=[$2])
+                HiveAggregate(group=[{1, 2}], agg#0=[sum($3)])
+                  HiveJoin(condition=[=($0, $4)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                    HiveProject(ss_sold_date_sk=[$0], ss_item_sk=[$2], 
ss_store_sk=[$7], ss_sales_price=[$13])
+                      HiveFilter(condition=[AND(IS NOT NULL($0), IS NOT 
NULL($7))])
+                        HiveTableScan(table=[[default, store_sales]], 
table:alias=[store_sales])
+                    HiveProject(d_date_sk=[$0], d_month_seq=[$3])
+                      HiveFilter(condition=[AND(BETWEEN(false, $3, 1212, 
1223), IS NOT NULL($0))])
+                        HiveTableScan(table=[[default, date_dim]], 
table:alias=[date_dim])
+        HiveProject(s_store_sk=[$0], s_store_name=[$5])
+          HiveFilter(condition=[IS NOT NULL($0)])
+            HiveTableScan(table=[[default, store]], table:alias=[store])
+

http://git-wip-us.apache.org/repos/asf/hive/blob/b8299551/ql/src/test/results/clientpositive/perf/tez/cbo_query66.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/perf/tez/cbo_query66.q.out 
b/ql/src/test/results/clientpositive/perf/tez/cbo_query66.q.out
new file mode 100644
index 0000000..d97f351
--- /dev/null
+++ b/ql/src/test/results/clientpositive/perf/tez/cbo_query66.q.out
@@ -0,0 +1,508 @@
+PREHOOK: query: explain cbo
+select   
+         w_warehouse_name
+       ,w_warehouse_sq_ft
+       ,w_city
+       ,w_county
+       ,w_state
+       ,w_country
+        ,ship_carriers
+        ,year
+       ,sum(jan_sales) as jan_sales
+       ,sum(feb_sales) as feb_sales
+       ,sum(mar_sales) as mar_sales
+       ,sum(apr_sales) as apr_sales
+       ,sum(may_sales) as may_sales
+       ,sum(jun_sales) as jun_sales
+       ,sum(jul_sales) as jul_sales
+       ,sum(aug_sales) as aug_sales
+       ,sum(sep_sales) as sep_sales
+       ,sum(oct_sales) as oct_sales
+       ,sum(nov_sales) as nov_sales
+       ,sum(dec_sales) as dec_sales
+       ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot
+       ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot
+       ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot
+       ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot
+       ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot
+       ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot
+       ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot
+       ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot
+       ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot
+       ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot
+       ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot
+       ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot
+       ,sum(jan_net) as jan_net
+       ,sum(feb_net) as feb_net
+       ,sum(mar_net) as mar_net
+       ,sum(apr_net) as apr_net
+       ,sum(may_net) as may_net
+       ,sum(jun_net) as jun_net
+       ,sum(jul_net) as jul_net
+       ,sum(aug_net) as aug_net
+       ,sum(sep_net) as sep_net
+       ,sum(oct_net) as oct_net
+       ,sum(nov_net) as nov_net
+       ,sum(dec_net) as dec_net
+ from (
+    (select 
+       w_warehouse_name
+       ,w_warehouse_sq_ft
+       ,w_city
+       ,w_county
+       ,w_state
+       ,w_country
+       ,'DIAMOND' || ',' || 'AIRBORNE' as ship_carriers
+       ,d_year as year
+       ,sum(case when d_moy = 1 
+               then ws_sales_price* ws_quantity else 0 end) as jan_sales
+       ,sum(case when d_moy = 2 
+               then ws_sales_price* ws_quantity else 0 end) as feb_sales
+       ,sum(case when d_moy = 3 
+               then ws_sales_price* ws_quantity else 0 end) as mar_sales
+       ,sum(case when d_moy = 4 
+               then ws_sales_price* ws_quantity else 0 end) as apr_sales
+       ,sum(case when d_moy = 5 
+               then ws_sales_price* ws_quantity else 0 end) as may_sales
+       ,sum(case when d_moy = 6 
+               then ws_sales_price* ws_quantity else 0 end) as jun_sales
+       ,sum(case when d_moy = 7 
+               then ws_sales_price* ws_quantity else 0 end) as jul_sales
+       ,sum(case when d_moy = 8 
+               then ws_sales_price* ws_quantity else 0 end) as aug_sales
+       ,sum(case when d_moy = 9 
+               then ws_sales_price* ws_quantity else 0 end) as sep_sales
+       ,sum(case when d_moy = 10 
+               then ws_sales_price* ws_quantity else 0 end) as oct_sales
+       ,sum(case when d_moy = 11
+               then ws_sales_price* ws_quantity else 0 end) as nov_sales
+       ,sum(case when d_moy = 12
+               then ws_sales_price* ws_quantity else 0 end) as dec_sales
+       ,sum(case when d_moy = 1 
+               then ws_net_paid_inc_tax * ws_quantity else 0 end) as jan_net
+       ,sum(case when d_moy = 2
+               then ws_net_paid_inc_tax * ws_quantity else 0 end) as feb_net
+       ,sum(case when d_moy = 3 
+               then ws_net_paid_inc_tax * ws_quantity else 0 end) as mar_net
+       ,sum(case when d_moy = 4 
+               then ws_net_paid_inc_tax * ws_quantity else 0 end) as apr_net
+       ,sum(case when d_moy = 5 
+               then ws_net_paid_inc_tax * ws_quantity else 0 end) as may_net
+       ,sum(case when d_moy = 6 
+               then ws_net_paid_inc_tax * ws_quantity else 0 end) as jun_net
+       ,sum(case when d_moy = 7 
+               then ws_net_paid_inc_tax * ws_quantity else 0 end) as jul_net
+       ,sum(case when d_moy = 8 
+               then ws_net_paid_inc_tax * ws_quantity else 0 end) as aug_net
+       ,sum(case when d_moy = 9 
+               then ws_net_paid_inc_tax * ws_quantity else 0 end) as sep_net
+       ,sum(case when d_moy = 10 
+               then ws_net_paid_inc_tax * ws_quantity else 0 end) as oct_net
+       ,sum(case when d_moy = 11
+               then ws_net_paid_inc_tax * ws_quantity else 0 end) as nov_net
+       ,sum(case when d_moy = 12
+               then ws_net_paid_inc_tax * ws_quantity else 0 end) as dec_net
+     from
+          web_sales
+         ,warehouse
+         ,date_dim
+         ,time_dim
+         ,ship_mode
+     where
+            ws_warehouse_sk =  w_warehouse_sk
+        and ws_sold_date_sk = d_date_sk
+        and ws_sold_time_sk = t_time_sk
+       and ws_ship_mode_sk = sm_ship_mode_sk
+        and d_year = 2002
+       and t_time between 49530 and 49530+28800 
+       and sm_carrier in ('DIAMOND','AIRBORNE')
+     group by 
+        w_warehouse_name
+       ,w_warehouse_sq_ft
+       ,w_city
+       ,w_county
+       ,w_state
+       ,w_country
+       ,d_year
+       )
+ union all
+    (select 
+       w_warehouse_name
+       ,w_warehouse_sq_ft
+       ,w_city
+       ,w_county
+       ,w_state
+       ,w_country
+       ,'DIAMOND' || ',' || 'AIRBORNE' as ship_carriers
+       ,d_year as year
+       ,sum(case when d_moy = 1 
+               then cs_ext_sales_price* cs_quantity else 0 end) as jan_sales
+       ,sum(case when d_moy = 2 
+               then cs_ext_sales_price* cs_quantity else 0 end) as feb_sales
+       ,sum(case when d_moy = 3 
+               then cs_ext_sales_price* cs_quantity else 0 end) as mar_sales
+       ,sum(case when d_moy = 4 
+               then cs_ext_sales_price* cs_quantity else 0 end) as apr_sales
+       ,sum(case when d_moy = 5 
+               then cs_ext_sales_price* cs_quantity else 0 end) as may_sales
+       ,sum(case when d_moy = 6 
+               then cs_ext_sales_price* cs_quantity else 0 end) as jun_sales
+       ,sum(case when d_moy = 7 
+               then cs_ext_sales_price* cs_quantity else 0 end) as jul_sales
+       ,sum(case when d_moy = 8 
+               then cs_ext_sales_price* cs_quantity else 0 end) as aug_sales
+       ,sum(case when d_moy = 9 
+               then cs_ext_sales_price* cs_quantity else 0 end) as sep_sales
+       ,sum(case when d_moy = 10 
+               then cs_ext_sales_price* cs_quantity else 0 end) as oct_sales
+       ,sum(case when d_moy = 11
+               then cs_ext_sales_price* cs_quantity else 0 end) as nov_sales
+       ,sum(case when d_moy = 12
+               then cs_ext_sales_price* cs_quantity else 0 end) as dec_sales
+       ,sum(case when d_moy = 1 
+               then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as 
jan_net
+       ,sum(case when d_moy = 2 
+               then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as 
feb_net
+       ,sum(case when d_moy = 3 
+               then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as 
mar_net
+       ,sum(case when d_moy = 4 
+               then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as 
apr_net
+       ,sum(case when d_moy = 5 
+               then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as 
may_net
+       ,sum(case when d_moy = 6 
+               then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as 
jun_net
+       ,sum(case when d_moy = 7 
+               then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as 
jul_net
+       ,sum(case when d_moy = 8 
+               then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as 
aug_net
+       ,sum(case when d_moy = 9 
+               then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as 
sep_net
+       ,sum(case when d_moy = 10 
+               then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as 
oct_net
+       ,sum(case when d_moy = 11
+               then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as 
nov_net
+       ,sum(case when d_moy = 12
+               then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as 
dec_net
+     from
+          catalog_sales
+         ,warehouse
+         ,date_dim
+         ,time_dim
+        ,ship_mode
+     where
+            cs_warehouse_sk =  w_warehouse_sk
+        and cs_sold_date_sk = d_date_sk
+        and cs_sold_time_sk = t_time_sk
+       and cs_ship_mode_sk = sm_ship_mode_sk
+        and d_year = 2002
+       and t_time between 49530 AND 49530+28800 
+       and sm_carrier in ('DIAMOND','AIRBORNE')
+     group by 
+        w_warehouse_name
+       ,w_warehouse_sq_ft
+       ,w_city
+       ,w_county
+       ,w_state
+       ,w_country
+       ,d_year
+     ) 
+ ) x
+ group by 
+        w_warehouse_name
+       ,w_warehouse_sq_ft
+       ,w_city
+       ,w_county
+       ,w_state
+       ,w_country
+       ,ship_carriers
+       ,year
+ order by w_warehouse_name
+ limit 100
+PREHOOK: type: QUERY
+PREHOOK: Input: default@catalog_sales
+PREHOOK: Input: default@date_dim
+PREHOOK: Input: default@ship_mode
+PREHOOK: Input: default@time_dim
+PREHOOK: Input: default@warehouse
+PREHOOK: Input: default@web_sales
+PREHOOK: Output: hdfs://### HDFS PATH ###
+POSTHOOK: query: explain cbo
+select   
+         w_warehouse_name
+       ,w_warehouse_sq_ft
+       ,w_city
+       ,w_county
+       ,w_state
+       ,w_country
+        ,ship_carriers
+        ,year
+       ,sum(jan_sales) as jan_sales
+       ,sum(feb_sales) as feb_sales
+       ,sum(mar_sales) as mar_sales
+       ,sum(apr_sales) as apr_sales
+       ,sum(may_sales) as may_sales
+       ,sum(jun_sales) as jun_sales
+       ,sum(jul_sales) as jul_sales
+       ,sum(aug_sales) as aug_sales
+       ,sum(sep_sales) as sep_sales
+       ,sum(oct_sales) as oct_sales
+       ,sum(nov_sales) as nov_sales
+       ,sum(dec_sales) as dec_sales
+       ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot
+       ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot
+       ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot
+       ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot
+       ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot
+       ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot
+       ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot
+       ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot
+       ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot
+       ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot
+       ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot
+       ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot
+       ,sum(jan_net) as jan_net
+       ,sum(feb_net) as feb_net
+       ,sum(mar_net) as mar_net
+       ,sum(apr_net) as apr_net
+       ,sum(may_net) as may_net
+       ,sum(jun_net) as jun_net
+       ,sum(jul_net) as jul_net
+       ,sum(aug_net) as aug_net
+       ,sum(sep_net) as sep_net
+       ,sum(oct_net) as oct_net
+       ,sum(nov_net) as nov_net
+       ,sum(dec_net) as dec_net
+ from (
+    (select 
+       w_warehouse_name
+       ,w_warehouse_sq_ft
+       ,w_city
+       ,w_county
+       ,w_state
+       ,w_country
+       ,'DIAMOND' || ',' || 'AIRBORNE' as ship_carriers
+       ,d_year as year
+       ,sum(case when d_moy = 1 
+               then ws_sales_price* ws_quantity else 0 end) as jan_sales
+       ,sum(case when d_moy = 2 
+               then ws_sales_price* ws_quantity else 0 end) as feb_sales
+       ,sum(case when d_moy = 3 
+               then ws_sales_price* ws_quantity else 0 end) as mar_sales
+       ,sum(case when d_moy = 4 
+               then ws_sales_price* ws_quantity else 0 end) as apr_sales
+       ,sum(case when d_moy = 5 
+               then ws_sales_price* ws_quantity else 0 end) as may_sales
+       ,sum(case when d_moy = 6 
+               then ws_sales_price* ws_quantity else 0 end) as jun_sales
+       ,sum(case when d_moy = 7 
+               then ws_sales_price* ws_quantity else 0 end) as jul_sales
+       ,sum(case when d_moy = 8 
+               then ws_sales_price* ws_quantity else 0 end) as aug_sales
+       ,sum(case when d_moy = 9 
+               then ws_sales_price* ws_quantity else 0 end) as sep_sales
+       ,sum(case when d_moy = 10 
+               then ws_sales_price* ws_quantity else 0 end) as oct_sales
+       ,sum(case when d_moy = 11
+               then ws_sales_price* ws_quantity else 0 end) as nov_sales
+       ,sum(case when d_moy = 12
+               then ws_sales_price* ws_quantity else 0 end) as dec_sales
+       ,sum(case when d_moy = 1 
+               then ws_net_paid_inc_tax * ws_quantity else 0 end) as jan_net
+       ,sum(case when d_moy = 2
+               then ws_net_paid_inc_tax * ws_quantity else 0 end) as feb_net
+       ,sum(case when d_moy = 3 
+               then ws_net_paid_inc_tax * ws_quantity else 0 end) as mar_net
+       ,sum(case when d_moy = 4 
+               then ws_net_paid_inc_tax * ws_quantity else 0 end) as apr_net
+       ,sum(case when d_moy = 5 
+               then ws_net_paid_inc_tax * ws_quantity else 0 end) as may_net
+       ,sum(case when d_moy = 6 
+               then ws_net_paid_inc_tax * ws_quantity else 0 end) as jun_net
+       ,sum(case when d_moy = 7 
+               then ws_net_paid_inc_tax * ws_quantity else 0 end) as jul_net
+       ,sum(case when d_moy = 8 
+               then ws_net_paid_inc_tax * ws_quantity else 0 end) as aug_net
+       ,sum(case when d_moy = 9 
+               then ws_net_paid_inc_tax * ws_quantity else 0 end) as sep_net
+       ,sum(case when d_moy = 10 
+               then ws_net_paid_inc_tax * ws_quantity else 0 end) as oct_net
+       ,sum(case when d_moy = 11
+               then ws_net_paid_inc_tax * ws_quantity else 0 end) as nov_net
+       ,sum(case when d_moy = 12
+               then ws_net_paid_inc_tax * ws_quantity else 0 end) as dec_net
+     from
+          web_sales
+         ,warehouse
+         ,date_dim
+         ,time_dim
+         ,ship_mode
+     where
+            ws_warehouse_sk =  w_warehouse_sk
+        and ws_sold_date_sk = d_date_sk
+        and ws_sold_time_sk = t_time_sk
+       and ws_ship_mode_sk = sm_ship_mode_sk
+        and d_year = 2002
+       and t_time between 49530 and 49530+28800 
+       and sm_carrier in ('DIAMOND','AIRBORNE')
+     group by 
+        w_warehouse_name
+       ,w_warehouse_sq_ft
+       ,w_city
+       ,w_county
+       ,w_state
+       ,w_country
+       ,d_year
+       )
+ union all
+    (select 
+       w_warehouse_name
+       ,w_warehouse_sq_ft
+       ,w_city
+       ,w_county
+       ,w_state
+       ,w_country
+       ,'DIAMOND' || ',' || 'AIRBORNE' as ship_carriers
+       ,d_year as year
+       ,sum(case when d_moy = 1 
+               then cs_ext_sales_price* cs_quantity else 0 end) as jan_sales
+       ,sum(case when d_moy = 2 
+               then cs_ext_sales_price* cs_quantity else 0 end) as feb_sales
+       ,sum(case when d_moy = 3 
+               then cs_ext_sales_price* cs_quantity else 0 end) as mar_sales
+       ,sum(case when d_moy = 4 
+               then cs_ext_sales_price* cs_quantity else 0 end) as apr_sales
+       ,sum(case when d_moy = 5 
+               then cs_ext_sales_price* cs_quantity else 0 end) as may_sales
+       ,sum(case when d_moy = 6 
+               then cs_ext_sales_price* cs_quantity else 0 end) as jun_sales
+       ,sum(case when d_moy = 7 
+               then cs_ext_sales_price* cs_quantity else 0 end) as jul_sales
+       ,sum(case when d_moy = 8 
+               then cs_ext_sales_price* cs_quantity else 0 end) as aug_sales
+       ,sum(case when d_moy = 9 
+               then cs_ext_sales_price* cs_quantity else 0 end) as sep_sales
+       ,sum(case when d_moy = 10 
+               then cs_ext_sales_price* cs_quantity else 0 end) as oct_sales
+       ,sum(case when d_moy = 11
+               then cs_ext_sales_price* cs_quantity else 0 end) as nov_sales
+       ,sum(case when d_moy = 12
+               then cs_ext_sales_price* cs_quantity else 0 end) as dec_sales
+       ,sum(case when d_moy = 1 
+               then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as 
jan_net
+       ,sum(case when d_moy = 2 
+               then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as 
feb_net
+       ,sum(case when d_moy = 3 
+               then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as 
mar_net
+       ,sum(case when d_moy = 4 
+               then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as 
apr_net
+       ,sum(case when d_moy = 5 
+               then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as 
may_net
+       ,sum(case when d_moy = 6 
+               then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as 
jun_net
+       ,sum(case when d_moy = 7 
+               then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as 
jul_net
+       ,sum(case when d_moy = 8 
+               then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as 
aug_net
+       ,sum(case when d_moy = 9 
+               then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as 
sep_net
+       ,sum(case when d_moy = 10 
+               then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as 
oct_net
+       ,sum(case when d_moy = 11
+               then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as 
nov_net
+       ,sum(case when d_moy = 12
+               then cs_net_paid_inc_ship_tax * cs_quantity else 0 end) as 
dec_net
+     from
+          catalog_sales
+         ,warehouse
+         ,date_dim
+         ,time_dim
+        ,ship_mode
+     where
+            cs_warehouse_sk =  w_warehouse_sk
+        and cs_sold_date_sk = d_date_sk
+        and cs_sold_time_sk = t_time_sk
+       and cs_ship_mode_sk = sm_ship_mode_sk
+        and d_year = 2002
+       and t_time between 49530 AND 49530+28800 
+       and sm_carrier in ('DIAMOND','AIRBORNE')
+     group by 
+        w_warehouse_name
+       ,w_warehouse_sq_ft
+       ,w_city
+       ,w_county
+       ,w_state
+       ,w_country
+       ,d_year
+     ) 
+ ) x
+ group by 
+        w_warehouse_name
+       ,w_warehouse_sq_ft
+       ,w_city
+       ,w_county
+       ,w_state
+       ,w_country
+       ,ship_carriers
+       ,year
+ order by w_warehouse_name
+ limit 100
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@catalog_sales
+POSTHOOK: Input: default@date_dim
+POSTHOOK: Input: default@ship_mode
+POSTHOOK: Input: default@time_dim
+POSTHOOK: Input: default@warehouse
+POSTHOOK: Input: default@web_sales
+POSTHOOK: Output: hdfs://### HDFS PATH ###
+CBO PLAN:
+HiveProject(w_warehouse_name=[$0], w_warehouse_sq_ft=[$1], w_city=[$2], 
w_county=[$3], w_state=[$4], w_country=[$5], 
ship_carriers=[CAST(_UTF-16LE'DIAMOND,AIRBORNE'):VARCHAR(2147483647) CHARACTER 
SET "UTF-16LE" COLLATE "ISO-8859-1$en_US$primary"], year=[CAST(2002):INTEGER], 
jan_sales=[$6], feb_sales=[$7], mar_sales=[$8], apr_sales=[$9], 
may_sales=[$10], jun_sales=[$11], jul_sales=[$12], aug_sales=[$13], 
sep_sales=[$14], oct_sales=[$15], nov_sales=[$16], dec_sales=[$17], 
jan_sales_per_sq_foot=[$18], feb_sales_per_sq_foot=[$19], 
mar_sales_per_sq_foot=[$20], apr_sales_per_sq_foot=[$21], 
may_sales_per_sq_foot=[$22], jun_sales_per_sq_foot=[$23], 
jul_sales_per_sq_foot=[$24], aug_sales_per_sq_foot=[$25], 
sep_sales_per_sq_foot=[$26], oct_sales_per_sq_foot=[$27], 
nov_sales_per_sq_foot=[$28], dec_sales_per_sq_foot=[$29], jan_net=[$30], 
feb_net=[$31], mar_net=[$32], apr_net=[$33], may_net=[$34], jun_net=[$35], 
jul_net=[$36], aug_net=[$37], sep_net=[$38], oct_net=[$39], nov_net=[$40], 
dec_net=[
 $41])
+  HiveSortLimit(sort0=[$0], dir0=[ASC], fetch=[100])
+    HiveProject($f0=[$0], $f1=[$1], $f2=[$2], $f3=[$3], $f4=[$4], $f5=[$5], 
$f6=[$6], $f7=[$7], $f8=[$8], $f9=[$9], $f10=[$10], $f11=[$11], $f12=[$12], 
$f13=[$13], $f14=[$14], $f15=[$15], $f16=[$16], $f17=[$17], $f18=[$18], 
$f19=[$19], $f20=[$20], $f21=[$21], $f22=[$22], $f23=[$23], $f24=[$24], 
$f25=[$25], $f26=[$26], $f27=[$27], $f28=[$28], $f29=[$29], $f30=[$30], 
$f31=[$31], $f32=[$32], $f33=[$33], $f34=[$34], $f35=[$35], $f36=[$36], 
$f37=[$37], $f38=[$38], $f39=[$39], $f40=[$40], $f41=[$41])
+      HiveAggregate(group=[{0, 1, 2, 3, 4, 5}], agg#0=[sum($6)], 
agg#1=[sum($7)], agg#2=[sum($8)], agg#3=[sum($9)], agg#4=[sum($10)], 
agg#5=[sum($11)], agg#6=[sum($12)], agg#7=[sum($13)], agg#8=[sum($14)], 
agg#9=[sum($15)], agg#10=[sum($16)], agg#11=[sum($17)], agg#12=[sum($18)], 
agg#13=[sum($19)], agg#14=[sum($20)], agg#15=[sum($21)], agg#16=[sum($22)], 
agg#17=[sum($23)], agg#18=[sum($24)], agg#19=[sum($25)], agg#20=[sum($26)], 
agg#21=[sum($27)], agg#22=[sum($28)], agg#23=[sum($29)], agg#24=[sum($30)], 
agg#25=[sum($31)], agg#26=[sum($32)], agg#27=[sum($33)], agg#28=[sum($34)], 
agg#29=[sum($35)], agg#30=[sum($36)], agg#31=[sum($37)], agg#32=[sum($38)], 
agg#33=[sum($39)], agg#34=[sum($40)], agg#35=[sum($41)])
+        HiveProject($f0=[$0], $f1=[$1], $f2=[$2], $f3=[$3], $f4=[$4], 
$f5=[$5], $f8=[$6], $f9=[$7], $f10=[$8], $f11=[$9], $f12=[$10], $f13=[$11], 
$f14=[$12], $f15=[$13], $f16=[$14], $f17=[$15], $f18=[$16], $f19=[$17], 
$f20=[/($6, CAST($1):DECIMAL(10, 0))], $f21=[/($7, CAST($1):DECIMAL(10, 0))], 
$f22=[/($8, CAST($1):DECIMAL(10, 0))], $f23=[/($9, CAST($1):DECIMAL(10, 0))], 
$f24=[/($10, CAST($1):DECIMAL(10, 0))], $f25=[/($11, CAST($1):DECIMAL(10, 0))], 
$f26=[/($12, CAST($1):DECIMAL(10, 0))], $f27=[/($13, CAST($1):DECIMAL(10, 0))], 
$f28=[/($14, CAST($1):DECIMAL(10, 0))], $f29=[/($15, CAST($1):DECIMAL(10, 0))], 
$f30=[/($16, CAST($1):DECIMAL(10, 0))], $f31=[/($17, CAST($1):DECIMAL(10, 0))], 
$f32=[$18], $f33=[$19], $f34=[$20], $f35=[$21], $f36=[$22], $f37=[$23], 
$f38=[$24], $f39=[$25], $f40=[$26], $f41=[$27], $f42=[$28], $f43=[$29])
+          HiveUnion(all=[true])
+            HiveProject($f0=[$0], $f1=[$1], $f2=[$2], $f3=[$3], $f4=[$4], 
$f5=[$5], $f6=[$6], $f7=[$7], $f8=[$8], $f9=[$9], $f10=[$10], $f11=[$11], 
$f12=[$12], $f13=[$13], $f14=[$14], $f15=[$15], $f16=[$16], $f17=[$17], 
$f18=[$18], $f19=[$19], $f20=[$20], $f21=[$21], $f22=[$22], $f23=[$23], 
$f24=[$24], $f25=[$25], $f26=[$26], $f27=[$27], $f28=[$28], $f29=[$29])
+              HiveAggregate(group=[{0, 1, 2, 3, 4, 5}], agg#0=[sum($6)], 
agg#1=[sum($7)], agg#2=[sum($8)], agg#3=[sum($9)], agg#4=[sum($10)], 
agg#5=[sum($11)], agg#6=[sum($12)], agg#7=[sum($13)], agg#8=[sum($14)], 
agg#9=[sum($15)], agg#10=[sum($16)], agg#11=[sum($17)], agg#12=[sum($18)], 
agg#13=[sum($19)], agg#14=[sum($20)], agg#15=[sum($21)], agg#16=[sum($22)], 
agg#17=[sum($23)], agg#18=[sum($24)], agg#19=[sum($25)], agg#20=[sum($26)], 
agg#21=[sum($27)], agg#22=[sum($28)], agg#23=[sum($29)])
+                HiveProject($f0=[$1], $f1=[$2], $f2=[$3], $f3=[$4], $f4=[$5], 
$f5=[$6], $f7=[CASE(=($18, 1), *($12, CAST($11):DECIMAL(10, 0)), 0)], 
$f8=[CASE(=($18, 2), *($12, CAST($11):DECIMAL(10, 0)), 0)], $f9=[CASE(=($18, 
3), *($12, CAST($11):DECIMAL(10, 0)), 0)], $f10=[CASE(=($18, 4), *($12, 
CAST($11):DECIMAL(10, 0)), 0)], $f11=[CASE(=($18, 5), *($12, 
CAST($11):DECIMAL(10, 0)), 0)], $f12=[CASE(=($18, 6), *($12, 
CAST($11):DECIMAL(10, 0)), 0)], $f13=[CASE(=($18, 7), *($12, 
CAST($11):DECIMAL(10, 0)), 0)], $f14=[CASE(=($18, 8), *($12, 
CAST($11):DECIMAL(10, 0)), 0)], $f15=[CASE(=($18, 9), *($12, 
CAST($11):DECIMAL(10, 0)), 0)], $f16=[CASE(=($18, 10), *($12, 
CAST($11):DECIMAL(10, 0)), 0)], $f17=[CASE(=($18, 11), *($12, 
CAST($11):DECIMAL(10, 0)), 0)], $f18=[CASE(=($18, 12), *($12, 
CAST($11):DECIMAL(10, 0)), 0)], $f19=[CASE(=($18, 1), *($13, 
CAST($11):DECIMAL(10, 0)), 0)], $f20=[CASE(=($18, 2), *($13, 
CAST($11):DECIMAL(10, 0)), 0)], $f21=[CASE(=($18, 3), *($13, 
CAST($11):DECIMAL(10, 0)),
  0)], $f22=[CASE(=($18, 4), *($13, CAST($11):DECIMAL(10, 0)), 0)], 
$f23=[CASE(=($18, 5), *($13, CAST($11):DECIMAL(10, 0)), 0)], $f24=[CASE(=($18, 
6), *($13, CAST($11):DECIMAL(10, 0)), 0)], $f25=[CASE(=($18, 7), *($13, 
CAST($11):DECIMAL(10, 0)), 0)], $f26=[CASE(=($18, 8), *($13, 
CAST($11):DECIMAL(10, 0)), 0)], $f27=[CASE(=($18, 9), *($13, 
CAST($11):DECIMAL(10, 0)), 0)], $f28=[CASE(=($18, 10), *($13, 
CAST($11):DECIMAL(10, 0)), 0)], $f29=[CASE(=($18, 11), *($13, 
CAST($11):DECIMAL(10, 0)), 0)], $f30=[CASE(=($18, 12), *($13, 
CAST($11):DECIMAL(10, 0)), 0)])
+                  HiveJoin(condition=[=($10, $0)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                    HiveProject(w_warehouse_sk=[$0], w_warehouse_name=[$2], 
w_warehouse_sq_ft=[$3], w_city=[$8], w_county=[$9], w_state=[$10], 
w_country=[$12])
+                      HiveFilter(condition=[IS NOT NULL($0)])
+                        HiveTableScan(table=[[default, warehouse]], 
table:alias=[warehouse])
+                    HiveJoin(condition=[=($2, $12)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                      HiveJoin(condition=[=($0, $9)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                        HiveJoin(condition=[=($1, $7)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                          HiveProject(ws_sold_date_sk=[$0], 
ws_sold_time_sk=[$1], ws_ship_mode_sk=[$14], ws_warehouse_sk=[$15], 
ws_quantity=[$18], ws_sales_price=[$21], ws_net_paid_inc_tax=[$30])
+                            HiveFilter(condition=[AND(IS NOT NULL($15), IS NOT 
NULL($0), IS NOT NULL($1), IS NOT NULL($14))])
+                              HiveTableScan(table=[[default, web_sales]], 
table:alias=[web_sales])
+                          HiveProject(t_time_sk=[$0], t_time=[$2])
+                            HiveFilter(condition=[AND(BETWEEN(false, $2, 
49530, 78330), IS NOT NULL($0))])
+                              HiveTableScan(table=[[default, time_dim]], 
table:alias=[time_dim])
+                        HiveProject(d_date_sk=[$0], 
d_year=[CAST(2002):INTEGER], d_moy=[$8])
+                          HiveFilter(condition=[AND(=($6, 2002), IS NOT 
NULL($0))])
+                            HiveTableScan(table=[[default, date_dim]], 
table:alias=[date_dim])
+                      HiveProject(sm_ship_mode_sk=[$0], sm_carrier=[$4])
+                        HiveFilter(condition=[AND(IN($4, _UTF-16LE'DIAMOND', 
_UTF-16LE'AIRBORNE'), IS NOT NULL($0))])
+                          HiveTableScan(table=[[default, ship_mode]], 
table:alias=[ship_mode])
+            HiveProject($f0=[$0], $f1=[$1], $f2=[$2], $f3=[$3], $f4=[$4], 
$f5=[$5], $f6=[$6], $f7=[$7], $f8=[$8], $f9=[$9], $f10=[$10], $f11=[$11], 
$f12=[$12], $f13=[$13], $f14=[$14], $f15=[$15], $f16=[$16], $f17=[$17], 
$f18=[$18], $f19=[$19], $f20=[$20], $f21=[$21], $f22=[$22], $f23=[$23], 
$f24=[$24], $f25=[$25], $f26=[$26], $f27=[$27], $f28=[$28], $f29=[$29])
+              HiveAggregate(group=[{0, 1, 2, 3, 4, 5}], agg#0=[sum($6)], 
agg#1=[sum($7)], agg#2=[sum($8)], agg#3=[sum($9)], agg#4=[sum($10)], 
agg#5=[sum($11)], agg#6=[sum($12)], agg#7=[sum($13)], agg#8=[sum($14)], 
agg#9=[sum($15)], agg#10=[sum($16)], agg#11=[sum($17)], agg#12=[sum($18)], 
agg#13=[sum($19)], agg#14=[sum($20)], agg#15=[sum($21)], agg#16=[sum($22)], 
agg#17=[sum($23)], agg#18=[sum($24)], agg#19=[sum($25)], agg#20=[sum($26)], 
agg#21=[sum($27)], agg#22=[sum($28)], agg#23=[sum($29)])
+                HiveProject($f0=[$15], $f1=[$16], $f2=[$17], $f3=[$18], 
$f4=[$19], $f5=[$20], $f7=[CASE(=($11, 1), *($5, CAST($4):DECIMAL(10, 0)), 0)], 
$f8=[CASE(=($11, 2), *($5, CAST($4):DECIMAL(10, 0)), 0)], $f9=[CASE(=($11, 3), 
*($5, CAST($4):DECIMAL(10, 0)), 0)], $f10=[CASE(=($11, 4), *($5, 
CAST($4):DECIMAL(10, 0)), 0)], $f11=[CASE(=($11, 5), *($5, CAST($4):DECIMAL(10, 
0)), 0)], $f12=[CASE(=($11, 6), *($5, CAST($4):DECIMAL(10, 0)), 0)], 
$f13=[CASE(=($11, 7), *($5, CAST($4):DECIMAL(10, 0)), 0)], $f14=[CASE(=($11, 
8), *($5, CAST($4):DECIMAL(10, 0)), 0)], $f15=[CASE(=($11, 9), *($5, 
CAST($4):DECIMAL(10, 0)), 0)], $f16=[CASE(=($11, 10), *($5, 
CAST($4):DECIMAL(10, 0)), 0)], $f17=[CASE(=($11, 11), *($5, 
CAST($4):DECIMAL(10, 0)), 0)], $f18=[CASE(=($11, 12), *($5, 
CAST($4):DECIMAL(10, 0)), 0)], $f19=[CASE(=($11, 1), *($6, CAST($4):DECIMAL(10, 
0)), 0)], $f20=[CASE(=($11, 2), *($6, CAST($4):DECIMAL(10, 0)), 0)], 
$f21=[CASE(=($11, 3), *($6, CAST($4):DECIMAL(10, 0)), 0)], $f22=[CASE(=($11, 
 4), *($6, CAST($4):DECIMAL(10, 0)), 0)], $f23=[CASE(=($11, 5), *($6, 
CAST($4):DECIMAL(10, 0)), 0)], $f24=[CASE(=($11, 6), *($6, CAST($4):DECIMAL(10, 
0)), 0)], $f25=[CASE(=($11, 7), *($6, CAST($4):DECIMAL(10, 0)), 0)], 
$f26=[CASE(=($11, 8), *($6, CAST($4):DECIMAL(10, 0)), 0)], $f27=[CASE(=($11, 
9), *($6, CAST($4):DECIMAL(10, 0)), 0)], $f28=[CASE(=($11, 10), *($6, 
CAST($4):DECIMAL(10, 0)), 0)], $f29=[CASE(=($11, 11), *($6, 
CAST($4):DECIMAL(10, 0)), 0)], $f30=[CASE(=($11, 12), *($6, 
CAST($4):DECIMAL(10, 0)), 0)])
+                  HiveJoin(condition=[=($3, $14)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                    HiveJoin(condition=[=($2, $12)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                      HiveJoin(condition=[=($0, $9)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                        HiveJoin(condition=[=($1, $7)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                          HiveProject(cs_sold_date_sk=[$0], 
cs_sold_time_sk=[$1], cs_ship_mode_sk=[$13], cs_warehouse_sk=[$14], 
cs_quantity=[$18], cs_ext_sales_price=[$23], cs_net_paid_inc_ship_tax=[$32])
+                            HiveFilter(condition=[AND(IS NOT NULL($14), IS NOT 
NULL($0), IS NOT NULL($1), IS NOT NULL($13))])
+                              HiveTableScan(table=[[default, catalog_sales]], 
table:alias=[catalog_sales])
+                          HiveProject(t_time_sk=[$0], t_time=[$2])
+                            HiveFilter(condition=[AND(BETWEEN(false, $2, 
49530, 78330), IS NOT NULL($0))])
+                              HiveTableScan(table=[[default, time_dim]], 
table:alias=[time_dim])
+                        HiveProject(d_date_sk=[$0], 
d_year=[CAST(2002):INTEGER], d_moy=[$8])
+                          HiveFilter(condition=[AND(=($6, 2002), IS NOT 
NULL($0))])
+                            HiveTableScan(table=[[default, date_dim]], 
table:alias=[date_dim])
+                      HiveProject(sm_ship_mode_sk=[$0], sm_carrier=[$4])
+                        HiveFilter(condition=[AND(IN($4, _UTF-16LE'DIAMOND', 
_UTF-16LE'AIRBORNE'), IS NOT NULL($0))])
+                          HiveTableScan(table=[[default, ship_mode]], 
table:alias=[ship_mode])
+                    HiveProject(w_warehouse_sk=[$0], w_warehouse_name=[$2], 
w_warehouse_sq_ft=[$3], w_city=[$8], w_county=[$9], w_state=[$10], 
w_country=[$12])
+                      HiveFilter(condition=[IS NOT NULL($0)])
+                        HiveTableScan(table=[[default, warehouse]], 
table:alias=[warehouse])
+

http://git-wip-us.apache.org/repos/asf/hive/blob/b8299551/ql/src/test/results/clientpositive/perf/tez/cbo_query67.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/perf/tez/cbo_query67.q.out 
b/ql/src/test/results/clientpositive/perf/tez/cbo_query67.q.out
new file mode 100644
index 0000000..fbe6779
--- /dev/null
+++ b/ql/src/test/results/clientpositive/perf/tez/cbo_query67.q.out
@@ -0,0 +1,120 @@
+PREHOOK: query: explain cbo
+select  *
+from (select i_category
+            ,i_class
+            ,i_brand
+            ,i_product_name
+            ,d_year
+            ,d_qoy
+            ,d_moy
+            ,s_store_id
+            ,sumsales
+            ,rank() over (partition by i_category order by sumsales desc) rk
+      from (select i_category
+                  ,i_class
+                  ,i_brand
+                  ,i_product_name
+                  ,d_year
+                  ,d_qoy
+                  ,d_moy
+                  ,s_store_id
+                  ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales
+            from store_sales
+                ,date_dim
+                ,store
+                ,item
+       where  ss_sold_date_sk=d_date_sk
+          and ss_item_sk=i_item_sk
+          and ss_store_sk = s_store_sk
+          and d_month_seq between 1212 and 1212+11
+       group by  rollup(i_category, i_class, i_brand, i_product_name, d_year, 
d_qoy, d_moy,s_store_id))dw1) dw2
+where rk <= 100
+order by i_category
+        ,i_class
+        ,i_brand
+        ,i_product_name
+        ,d_year
+        ,d_qoy
+        ,d_moy
+        ,s_store_id
+        ,sumsales
+        ,rk
+limit 100
+PREHOOK: type: QUERY
+PREHOOK: Input: default@date_dim
+PREHOOK: Input: default@item
+PREHOOK: Input: default@store
+PREHOOK: Input: default@store_sales
+PREHOOK: Output: hdfs://### HDFS PATH ###
+POSTHOOK: query: explain cbo
+select  *
+from (select i_category
+            ,i_class
+            ,i_brand
+            ,i_product_name
+            ,d_year
+            ,d_qoy
+            ,d_moy
+            ,s_store_id
+            ,sumsales
+            ,rank() over (partition by i_category order by sumsales desc) rk
+      from (select i_category
+                  ,i_class
+                  ,i_brand
+                  ,i_product_name
+                  ,d_year
+                  ,d_qoy
+                  ,d_moy
+                  ,s_store_id
+                  ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales
+            from store_sales
+                ,date_dim
+                ,store
+                ,item
+       where  ss_sold_date_sk=d_date_sk
+          and ss_item_sk=i_item_sk
+          and ss_store_sk = s_store_sk
+          and d_month_seq between 1212 and 1212+11
+       group by  rollup(i_category, i_class, i_brand, i_product_name, d_year, 
d_qoy, d_moy,s_store_id))dw1) dw2
+where rk <= 100
+order by i_category
+        ,i_class
+        ,i_brand
+        ,i_product_name
+        ,d_year
+        ,d_qoy
+        ,d_moy
+        ,s_store_id
+        ,sumsales
+        ,rk
+limit 100
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@date_dim
+POSTHOOK: Input: default@item
+POSTHOOK: Input: default@store
+POSTHOOK: Input: default@store_sales
+POSTHOOK: Output: hdfs://### HDFS PATH ###
+CBO PLAN:
+HiveSortLimit(sort0=[$0], sort1=[$1], sort2=[$2], sort3=[$3], sort4=[$4], 
sort5=[$5], sort6=[$6], sort7=[$7], sort8=[$8], sort9=[$9], dir0=[ASC], 
dir1=[ASC], dir2=[ASC], dir3=[ASC], dir4=[ASC], dir5=[ASC], dir6=[ASC], 
dir7=[ASC], dir8=[ASC], dir9=[ASC], fetch=[100])
+  HiveProject(i_category=[$0], i_class=[$1], i_brand=[$2], 
i_product_name=[$3], d_year=[$4], d_qoy=[$5], d_moy=[$6], s_store_id=[$7], 
sumsales=[$8], rank_window_0=[$9])
+    HiveFilter(condition=[<=($9, 100)])
+      HiveProject(i_category=[$0], i_class=[$1], i_brand=[$2], 
i_product_name=[$3], d_year=[$4], d_qoy=[$5], d_moy=[$6], s_store_id=[$7], 
sumsales=[$8], rank_window_0=[rank() OVER (PARTITION BY $0 ORDER BY $8 DESC 
NULLS LAST ROWS BETWEEN 2147483647 FOLLOWING AND 2147483647 PRECEDING)])
+        HiveProject($f0=[$0], $f1=[$1], $f2=[$2], $f3=[$3], $f4=[$4], 
$f5=[$5], $f6=[$6], $f7=[$7], $f8=[$8])
+          HiveAggregate(group=[{0, 1, 2, 3, 4, 5, 6, 7}], groups=[[{0, 1, 2, 
3, 4, 5, 6, 7}, {0, 1, 2, 3, 4, 5, 6}, {0, 1, 2, 3, 4, 5}, {0, 1, 2, 3, 4}, {0, 
1, 2, 3}, {0, 1, 2}, {0, 1}, {0}, {}]], agg#0=[sum($8)])
+            HiveProject($f0=[$3], $f1=[$2], $f2=[$1], $f3=[$4], $f4=[$12], 
$f5=[$14], $f6=[$13], $f7=[$16], $f8=[CASE(AND(IS NOT NULL($9), IS NOT 
NULL($8)), *($9, CAST($8):DECIMAL(10, 0)), 0)])
+              HiveJoin(condition=[=($6, $0)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                HiveProject(i_item_sk=[$0], i_brand=[$8], i_class=[$10], 
i_category=[$12], i_product_name=[$21])
+                  HiveFilter(condition=[IS NOT NULL($0)])
+                    HiveTableScan(table=[[default, item]], table:alias=[item])
+                HiveJoin(condition=[=($2, $10)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                  HiveJoin(condition=[=($0, $5)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                    HiveProject(ss_sold_date_sk=[$0], ss_item_sk=[$2], 
ss_store_sk=[$7], ss_quantity=[$10], ss_sales_price=[$13])
+                      HiveFilter(condition=[AND(IS NOT NULL($0), IS NOT 
NULL($7), IS NOT NULL($2))])
+                        HiveTableScan(table=[[default, store_sales]], 
table:alias=[store_sales])
+                    HiveProject(d_date_sk=[$0], d_month_seq=[$3], d_year=[$6], 
d_moy=[$8], d_qoy=[$10])
+                      HiveFilter(condition=[AND(BETWEEN(false, $3, 1212, 
1223), IS NOT NULL($0))])
+                        HiveTableScan(table=[[default, date_dim]], 
table:alias=[date_dim])
+                  HiveProject(s_store_sk=[$0], s_store_id=[$1])
+                    HiveFilter(condition=[IS NOT NULL($0)])
+                      HiveTableScan(table=[[default, store]], 
table:alias=[store])
+

http://git-wip-us.apache.org/repos/asf/hive/blob/b8299551/ql/src/test/results/clientpositive/perf/tez/cbo_query68.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/perf/tez/cbo_query68.q.out 
b/ql/src/test/results/clientpositive/perf/tez/cbo_query68.q.out
new file mode 100644
index 0000000..cd71cda
--- /dev/null
+++ b/ql/src/test/results/clientpositive/perf/tez/cbo_query68.q.out
@@ -0,0 +1,129 @@
+PREHOOK: query: explain cbo
+select  c_last_name
+       ,c_first_name
+       ,ca_city
+       ,bought_city
+       ,ss_ticket_number
+       ,extended_price
+       ,extended_tax
+       ,list_price
+ from (select ss_ticket_number
+             ,ss_customer_sk
+             ,ca_city bought_city
+             ,sum(ss_ext_sales_price) extended_price 
+             ,sum(ss_ext_list_price) list_price
+             ,sum(ss_ext_tax) extended_tax 
+       from store_sales
+           ,date_dim
+           ,store
+           ,household_demographics
+           ,customer_address 
+       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 store_sales.ss_addr_sk = customer_address.ca_address_sk
+        and date_dim.d_dom between 1 and 2 
+        and (household_demographics.hd_dep_count = 2 or
+             household_demographics.hd_vehicle_count= 1)
+        and date_dim.d_year in (1998,1998+1,1998+2)
+        and store.s_city in ('Cedar Grove','Wildwood')
+       group by ss_ticket_number
+               ,ss_customer_sk
+               ,ss_addr_sk,ca_city) dn
+      ,customer
+      ,customer_address current_addr
+ where ss_customer_sk = c_customer_sk
+   and customer.c_current_addr_sk = current_addr.ca_address_sk
+   and current_addr.ca_city <> bought_city
+ order by c_last_name
+         ,ss_ticket_number
+ limit 100
+PREHOOK: type: QUERY
+PREHOOK: Input: default@customer
+PREHOOK: Input: default@customer_address
+PREHOOK: Input: default@date_dim
+PREHOOK: Input: default@household_demographics
+PREHOOK: Input: default@store
+PREHOOK: Input: default@store_sales
+PREHOOK: Output: hdfs://### HDFS PATH ###
+POSTHOOK: query: explain cbo
+select  c_last_name
+       ,c_first_name
+       ,ca_city
+       ,bought_city
+       ,ss_ticket_number
+       ,extended_price
+       ,extended_tax
+       ,list_price
+ from (select ss_ticket_number
+             ,ss_customer_sk
+             ,ca_city bought_city
+             ,sum(ss_ext_sales_price) extended_price 
+             ,sum(ss_ext_list_price) list_price
+             ,sum(ss_ext_tax) extended_tax 
+       from store_sales
+           ,date_dim
+           ,store
+           ,household_demographics
+           ,customer_address 
+       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 store_sales.ss_addr_sk = customer_address.ca_address_sk
+        and date_dim.d_dom between 1 and 2 
+        and (household_demographics.hd_dep_count = 2 or
+             household_demographics.hd_vehicle_count= 1)
+        and date_dim.d_year in (1998,1998+1,1998+2)
+        and store.s_city in ('Cedar Grove','Wildwood')
+       group by ss_ticket_number
+               ,ss_customer_sk
+               ,ss_addr_sk,ca_city) dn
+      ,customer
+      ,customer_address current_addr
+ where ss_customer_sk = c_customer_sk
+   and customer.c_current_addr_sk = current_addr.ca_address_sk
+   and current_addr.ca_city <> bought_city
+ order by c_last_name
+         ,ss_ticket_number
+ limit 100
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@customer
+POSTHOOK: Input: default@customer_address
+POSTHOOK: Input: default@date_dim
+POSTHOOK: Input: default@household_demographics
+POSTHOOK: Input: default@store
+POSTHOOK: Input: default@store_sales
+POSTHOOK: Output: hdfs://### HDFS PATH ###
+CBO PLAN:
+HiveSortLimit(sort0=[$0], sort1=[$4], dir0=[ASC], dir1=[ASC], fetch=[100])
+  HiveProject(c_last_name=[$3], c_first_name=[$2], ca_city=[$5], 
bought_city=[$8], ss_ticket_number=[$6], extended_price=[$9], 
extended_tax=[$11], list_price=[$10])
+    HiveJoin(condition=[AND(<>($5, $8), =($7, $0))], joinType=[inner], 
algorithm=[none], cost=[not available])
+      HiveJoin(condition=[=($1, $4)], joinType=[inner], algorithm=[none], 
cost=[not available])
+        HiveProject(c_customer_sk=[$0], c_current_addr_sk=[$4], 
c_first_name=[$8], c_last_name=[$9])
+          HiveFilter(condition=[AND(IS NOT NULL($0), IS NOT NULL($4))])
+            HiveTableScan(table=[[default, customer]], table:alias=[customer])
+        HiveProject(ca_address_sk=[$0], ca_city=[$6])
+          HiveFilter(condition=[IS NOT NULL($0)])
+            HiveTableScan(table=[[default, customer_address]], 
table:alias=[current_addr])
+      HiveProject(ss_ticket_number=[$3], ss_customer_sk=[$1], 
bought_city=[$0], extended_price=[$4], list_price=[$5], extended_tax=[$6])
+        HiveAggregate(group=[{1, 3, 5, 7}], agg#0=[sum($8)], agg#1=[sum($9)], 
agg#2=[sum($10)])
+          HiveJoin(condition=[=($5, $0)], joinType=[inner], algorithm=[none], 
cost=[not available])
+            HiveProject(ca_address_sk=[$0], ca_city=[$6])
+              HiveFilter(condition=[IS NOT NULL($0)])
+                HiveTableScan(table=[[default, customer_address]], 
table:alias=[customer_address])
+            HiveJoin(condition=[=($2, $14)], joinType=[inner], 
algorithm=[none], cost=[not available])
+              HiveJoin(condition=[=($4, $12)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                HiveJoin(condition=[=($0, $9)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                  HiveProject(ss_sold_date_sk=[$0], ss_customer_sk=[$3], 
ss_hdemo_sk=[$5], ss_addr_sk=[$6], ss_store_sk=[$7], ss_ticket_number=[$9], 
ss_ext_sales_price=[$15], ss_ext_list_price=[$17], ss_ext_tax=[$18])
+                    HiveFilter(condition=[AND(IS NOT NULL($0), IS NOT 
NULL($7), IS NOT NULL($5), IS NOT NULL($6), IS NOT NULL($3))])
+                      HiveTableScan(table=[[default, store_sales]], 
table:alias=[store_sales])
+                  HiveProject(d_date_sk=[$0], d_year=[$6], d_dom=[$9])
+                    HiveFilter(condition=[AND(IN($6, 1998, 1999, 2000), 
BETWEEN(false, $9, 1, 2), IS NOT NULL($0))])
+                      HiveTableScan(table=[[default, date_dim]], 
table:alias=[date_dim])
+                HiveProject(s_store_sk=[$0], s_city=[$22])
+                  HiveFilter(condition=[AND(IN($22, _UTF-16LE'Cedar Grove', 
_UTF-16LE'Wildwood'), IS NOT NULL($0))])
+                    HiveTableScan(table=[[default, store]], 
table:alias=[store])
+              HiveProject(hd_demo_sk=[$0], hd_dep_count=[$3], 
hd_vehicle_count=[$4])
+                HiveFilter(condition=[AND(OR(=($3, 2), =($4, 1)), IS NOT 
NULL($0))])
+                  HiveTableScan(table=[[default, household_demographics]], 
table:alias=[household_demographics])
+

http://git-wip-us.apache.org/repos/asf/hive/blob/b8299551/ql/src/test/results/clientpositive/perf/tez/cbo_query69.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/perf/tez/cbo_query69.q.out 
b/ql/src/test/results/clientpositive/perf/tez/cbo_query69.q.out
new file mode 100644
index 0000000..9089fc8
--- /dev/null
+++ b/ql/src/test/results/clientpositive/perf/tez/cbo_query69.q.out
@@ -0,0 +1,156 @@
+PREHOOK: query: explain cbo
+select  
+  cd_gender,
+  cd_marital_status,
+  cd_education_status,
+  count(*) cnt1,
+  cd_purchase_estimate,
+  count(*) cnt2,
+  cd_credit_rating,
+  count(*) cnt3
+ from
+  customer c,customer_address ca,customer_demographics
+ where
+  c.c_current_addr_sk = ca.ca_address_sk and
+  ca_state in ('CO','IL','MN') and
+  cd_demo_sk = c.c_current_cdemo_sk and 
+  exists (select *
+          from store_sales,date_dim
+          where c.c_customer_sk = ss_customer_sk and
+                ss_sold_date_sk = d_date_sk and
+                d_year = 1999 and
+                d_moy between 1 and 1+2) and
+   (not exists (select *
+            from web_sales,date_dim
+            where c.c_customer_sk = ws_bill_customer_sk and
+                  ws_sold_date_sk = d_date_sk and
+                  d_year = 1999 and
+                  d_moy between 1 and 1+2) and
+    not exists (select * 
+            from catalog_sales,date_dim
+            where c.c_customer_sk = cs_ship_customer_sk and
+                  cs_sold_date_sk = d_date_sk and
+                  d_year = 1999 and
+                  d_moy between 1 and 1+2))
+ group by cd_gender,
+          cd_marital_status,
+          cd_education_status,
+          cd_purchase_estimate,
+          cd_credit_rating
+ order by cd_gender,
+          cd_marital_status,
+          cd_education_status,
+          cd_purchase_estimate,
+          cd_credit_rating
+ limit 100
+PREHOOK: type: QUERY
+PREHOOK: Input: default@catalog_sales
+PREHOOK: Input: default@customer
+PREHOOK: Input: default@customer_address
+PREHOOK: Input: default@customer_demographics
+PREHOOK: Input: default@date_dim
+PREHOOK: Input: default@store_sales
+PREHOOK: Input: default@web_sales
+PREHOOK: Output: hdfs://### HDFS PATH ###
+POSTHOOK: query: explain cbo
+select  
+  cd_gender,
+  cd_marital_status,
+  cd_education_status,
+  count(*) cnt1,
+  cd_purchase_estimate,
+  count(*) cnt2,
+  cd_credit_rating,
+  count(*) cnt3
+ from
+  customer c,customer_address ca,customer_demographics
+ where
+  c.c_current_addr_sk = ca.ca_address_sk and
+  ca_state in ('CO','IL','MN') and
+  cd_demo_sk = c.c_current_cdemo_sk and 
+  exists (select *
+          from store_sales,date_dim
+          where c.c_customer_sk = ss_customer_sk and
+                ss_sold_date_sk = d_date_sk and
+                d_year = 1999 and
+                d_moy between 1 and 1+2) and
+   (not exists (select *
+            from web_sales,date_dim
+            where c.c_customer_sk = ws_bill_customer_sk and
+                  ws_sold_date_sk = d_date_sk and
+                  d_year = 1999 and
+                  d_moy between 1 and 1+2) and
+    not exists (select * 
+            from catalog_sales,date_dim
+            where c.c_customer_sk = cs_ship_customer_sk and
+                  cs_sold_date_sk = d_date_sk and
+                  d_year = 1999 and
+                  d_moy between 1 and 1+2))
+ group by cd_gender,
+          cd_marital_status,
+          cd_education_status,
+          cd_purchase_estimate,
+          cd_credit_rating
+ order by cd_gender,
+          cd_marital_status,
+          cd_education_status,
+          cd_purchase_estimate,
+          cd_credit_rating
+ limit 100
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@catalog_sales
+POSTHOOK: Input: default@customer
+POSTHOOK: Input: default@customer_address
+POSTHOOK: Input: default@customer_demographics
+POSTHOOK: Input: default@date_dim
+POSTHOOK: Input: default@store_sales
+POSTHOOK: Input: default@web_sales
+POSTHOOK: Output: hdfs://### HDFS PATH ###
+CBO PLAN:
+HiveSortLimit(sort0=[$0], sort1=[$1], sort2=[$2], sort3=[$4], sort4=[$6], 
dir0=[ASC], dir1=[ASC], dir2=[ASC], dir3=[ASC], dir4=[ASC], fetch=[100])
+  HiveProject(cd_gender=[$0], cd_marital_status=[$1], 
cd_education_status=[$2], cnt1=[$5], cd_purchase_estimate=[$3], cnt2=[$5], 
cd_credit_rating=[$4], cnt3=[$5])
+    HiveAggregate(group=[{6, 7, 8, 9, 10}], agg#0=[count()])
+      HiveFilter(condition=[IS NULL($14)])
+        HiveJoin(condition=[=($0, $13)], joinType=[left], algorithm=[none], 
cost=[not available])
+          HiveProject(c_customer_sk=[$0], c_current_cdemo_sk=[$1], 
c_current_addr_sk=[$2], ca_address_sk=[$3], ca_state=[$4], cd_demo_sk=[$5], 
cd_gender=[$6], cd_marital_status=[$7], cd_education_status=[$8], 
cd_purchase_estimate=[$9], cd_credit_rating=[$10], ws_bill_customer_sk0=[$11], 
$f1=[$12])
+            HiveFilter(condition=[IS NULL($12)])
+              HiveJoin(condition=[=($0, $11)], joinType=[left], 
algorithm=[none], cost=[not available])
+                HiveSemiJoin(condition=[=($0, $11)], joinType=[inner])
+                  HiveJoin(condition=[=($5, $1)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                    HiveJoin(condition=[=($2, $3)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                      HiveProject(c_customer_sk=[$0], c_current_cdemo_sk=[$2], 
c_current_addr_sk=[$4])
+                        HiveFilter(condition=[AND(IS NOT NULL($4), IS NOT 
NULL($2), IS NOT NULL($0))])
+                          HiveTableScan(table=[[default, customer]], 
table:alias=[c])
+                      HiveProject(ca_address_sk=[$0], ca_state=[$8])
+                        HiveFilter(condition=[AND(IN($8, _UTF-16LE'CO', 
_UTF-16LE'IL', _UTF-16LE'MN'), IS NOT NULL($0))])
+                          HiveTableScan(table=[[default, customer_address]], 
table:alias=[ca])
+                    HiveProject(cd_demo_sk=[$0], cd_gender=[$1], 
cd_marital_status=[$2], cd_education_status=[$3], cd_purchase_estimate=[$4], 
cd_credit_rating=[$5])
+                      HiveFilter(condition=[IS NOT NULL($0)])
+                        HiveTableScan(table=[[default, 
customer_demographics]], table:alias=[customer_demographics])
+                  HiveProject(ss_customer_sk0=[$1])
+                    HiveJoin(condition=[=($0, $2)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                      HiveProject(ss_sold_date_sk=[$0], ss_customer_sk=[$3])
+                        HiveFilter(condition=[AND(IS NOT NULL($3), IS NOT 
NULL($0))])
+                          HiveTableScan(table=[[default, store_sales]], 
table:alias=[store_sales])
+                      HiveProject(d_date_sk=[$0], d_year=[CAST(1999):INTEGER], 
d_moy=[$8])
+                        HiveFilter(condition=[AND(=($6, 1999), BETWEEN(false, 
$8, 1, 3), IS NOT NULL($0))])
+                          HiveTableScan(table=[[default, date_dim]], 
table:alias=[date_dim])
+                HiveProject(ws_bill_customer_sk0=[$0], $f1=[true])
+                  HiveAggregate(group=[{1}])
+                    HiveJoin(condition=[=($0, $2)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                      HiveProject(ws_sold_date_sk=[$0], 
ws_bill_customer_sk=[$4])
+                        HiveFilter(condition=[AND(IS NOT NULL($4), IS NOT 
NULL($0))])
+                          HiveTableScan(table=[[default, web_sales]], 
table:alias=[web_sales])
+                      HiveProject(d_date_sk=[$0], d_year=[CAST(1999):INTEGER], 
d_moy=[$8])
+                        HiveFilter(condition=[AND(=($6, 1999), BETWEEN(false, 
$8, 1, 3), IS NOT NULL($0))])
+                          HiveTableScan(table=[[default, date_dim]], 
table:alias=[date_dim])
+          HiveProject(cs_ship_customer_sk0=[$0], $f1=[true])
+            HiveAggregate(group=[{1}])
+              HiveJoin(condition=[=($0, $2)], joinType=[inner], 
algorithm=[none], cost=[not available])
+                HiveProject(cs_sold_date_sk=[$0], cs_ship_customer_sk=[$7])
+                  HiveFilter(condition=[AND(IS NOT NULL($7), IS NOT NULL($0))])
+                    HiveTableScan(table=[[default, catalog_sales]], 
table:alias=[catalog_sales])
+                HiveProject(d_date_sk=[$0], d_year=[CAST(1999):INTEGER], 
d_moy=[$8])
+                  HiveFilter(condition=[AND(=($6, 1999), BETWEEN(false, $8, 1, 
3), IS NOT NULL($0))])
+                    HiveTableScan(table=[[default, date_dim]], 
table:alias=[date_dim])
+

http://git-wip-us.apache.org/repos/asf/hive/blob/b8299551/ql/src/test/results/clientpositive/perf/tez/cbo_query7.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/perf/tez/cbo_query7.q.out 
b/ql/src/test/results/clientpositive/perf/tez/cbo_query7.q.out
new file mode 100644
index 0000000..29415ca
--- /dev/null
+++ b/ql/src/test/results/clientpositive/perf/tez/cbo_query7.q.out
@@ -0,0 +1,76 @@
+PREHOOK: query: explain cbo
+select  i_item_id, 
+        avg(ss_quantity) agg1,
+        avg(ss_list_price) agg2,
+        avg(ss_coupon_amt) agg3,
+        avg(ss_sales_price) agg4 
+ from store_sales, customer_demographics, date_dim, item, promotion
+ where ss_sold_date_sk = d_date_sk and
+       ss_item_sk = i_item_sk and
+       ss_cdemo_sk = cd_demo_sk and
+       ss_promo_sk = p_promo_sk and
+       cd_gender = 'F' and 
+       cd_marital_status = 'W' and
+       cd_education_status = 'Primary' and
+       (p_channel_email = 'N' or p_channel_event = 'N') and
+       d_year = 1998 
+ group by i_item_id
+ order by i_item_id
+ limit 100
+PREHOOK: type: QUERY
+PREHOOK: Input: default@customer_demographics
+PREHOOK: Input: default@date_dim
+PREHOOK: Input: default@item
+PREHOOK: Input: default@promotion
+PREHOOK: Input: default@store_sales
+PREHOOK: Output: hdfs://### HDFS PATH ###
+POSTHOOK: query: explain cbo
+select  i_item_id, 
+        avg(ss_quantity) agg1,
+        avg(ss_list_price) agg2,
+        avg(ss_coupon_amt) agg3,
+        avg(ss_sales_price) agg4 
+ from store_sales, customer_demographics, date_dim, item, promotion
+ where ss_sold_date_sk = d_date_sk and
+       ss_item_sk = i_item_sk and
+       ss_cdemo_sk = cd_demo_sk and
+       ss_promo_sk = p_promo_sk and
+       cd_gender = 'F' and 
+       cd_marital_status = 'W' and
+       cd_education_status = 'Primary' and
+       (p_channel_email = 'N' or p_channel_event = 'N') and
+       d_year = 1998 
+ group by i_item_id
+ order by i_item_id
+ limit 100
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@customer_demographics
+POSTHOOK: Input: default@date_dim
+POSTHOOK: Input: default@item
+POSTHOOK: Input: default@promotion
+POSTHOOK: Input: default@store_sales
+POSTHOOK: Output: hdfs://### HDFS PATH ###
+CBO PLAN:
+HiveSortLimit(sort0=[$0], dir0=[ASC], fetch=[100])
+  HiveProject($f0=[$0], $f1=[/(CAST($1):DOUBLE, $2)], $f2=[/($3, $4)], 
$f3=[/($5, $6)], $f4=[/($7, $8)])
+    HiveAggregate(group=[{1}], agg#0=[sum($6)], agg#1=[count($6)], 
agg#2=[sum($7)], agg#3=[count($7)], agg#4=[sum($9)], agg#5=[count($9)], 
agg#6=[sum($8)], agg#7=[count($8)])
+      HiveJoin(condition=[=($3, $0)], joinType=[inner], algorithm=[none], 
cost=[not available])
+        HiveProject(i_item_sk=[$0], i_item_id=[$1])
+          HiveFilter(condition=[IS NOT NULL($0)])
+            HiveTableScan(table=[[default, item]], table:alias=[item])
+        HiveJoin(condition=[=($3, $14)], joinType=[inner], algorithm=[none], 
cost=[not available])
+          HiveJoin(condition=[=($0, $12)], joinType=[inner], algorithm=[none], 
cost=[not available])
+            HiveJoin(condition=[=($2, $8)], joinType=[inner], 
algorithm=[none], cost=[not available])
+              HiveProject(ss_sold_date_sk=[$0], ss_item_sk=[$2], 
ss_cdemo_sk=[$4], ss_promo_sk=[$8], ss_quantity=[$10], ss_list_price=[$12], 
ss_sales_price=[$13], ss_coupon_amt=[$19])
+                HiveFilter(condition=[AND(IS NOT NULL($4), IS NOT NULL($0), IS 
NOT NULL($2), IS NOT NULL($8))])
+                  HiveTableScan(table=[[default, store_sales]], 
table:alias=[store_sales])
+              HiveProject(cd_demo_sk=[$0], 
cd_gender=[CAST(_UTF-16LE'F'):VARCHAR(2147483647) CHARACTER SET "UTF-16LE" 
COLLATE "ISO-8859-1$en_US$primary"], 
cd_marital_status=[CAST(_UTF-16LE'W'):VARCHAR(2147483647) CHARACTER SET 
"UTF-16LE" COLLATE "ISO-8859-1$en_US$primary"], 
cd_education_status=[CAST(_UTF-16LE'Primary'):VARCHAR(2147483647) CHARACTER SET 
"UTF-16LE" COLLATE "ISO-8859-1$en_US$primary"])
+                HiveFilter(condition=[AND(=($1, _UTF-16LE'F'), =($2, 
_UTF-16LE'W'), =($3, _UTF-16LE'Primary'), IS NOT NULL($0))])
+                  HiveTableScan(table=[[default, customer_demographics]], 
table:alias=[customer_demographics])
+            HiveProject(d_date_sk=[$0], d_year=[CAST(1998):INTEGER])
+              HiveFilter(condition=[AND(=($6, 1998), IS NOT NULL($0))])
+                HiveTableScan(table=[[default, date_dim]], 
table:alias=[date_dim])
+          HiveProject(p_promo_sk=[$0], p_channel_email=[$9], 
p_channel_event=[$14])
+            HiveFilter(condition=[AND(OR(=($9, _UTF-16LE'N'), =($14, 
_UTF-16LE'N')), IS NOT NULL($0))])
+              HiveTableScan(table=[[default, promotion]], 
table:alias=[promotion])
+

Reply via email to