                                                                            QUERY PLAN                                                                             
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=3524256.05..3524256.30 rows=13 width=108)
   CTE cross_items
     ->  Hash Join  (cost=1768414.34..1777201.59 rows=27 width=4)
           Hash Cond: ((item_3.i_brand_id = a.brand_id) AND (item_3.i_class_id = a.class_id) AND (item_3.i_category_id = a.category_id))
           ->  Seq Scan on item item_3  (cost=0.00..7984.00 rows=102000 width=16)
           ->  Hash  (cost=1768235.84..1768235.84 rows=10200 width=12)
                 ->  Subquery Scan on a  (cost=11773.03..1768235.84 rows=10200 width=12)
                       ->  HashSetOp Intersect  (cost=11773.03..1768133.84 rows=10200 width=16)
                             ->  Append  (cost=11773.03..1767271.35 rows=114999 width=16)
                                   ->  Result  (cost=11773.03..1474977.78 rows=10200 width=16)
                                         ->  HashSetOp Intersect  (cost=11773.03..1474875.78 rows=10200 width=16)
                                               ->  Append  (cost=11773.03..1470307.47 rows=609108 width=16)
                                                     ->  Subquery Scan on "*SELECT* 1"  (cost=11773.03..897353.20 rows=400429 width=16)
                                                           ->  Hash Join  (cost=11773.03..893348.91 rows=400429 width=12)
                                                                 Hash Cond: (store_sales_1.ss_item_sk = iss.i_item_sk)
                                                                 ->  Hash Join  (cost=2514.03..883038.74 rows=400429 width=4)
                                                                       Hash Cond: (store_sales_1.ss_sold_date_sk = d1.d_date_sk)
                                                                       ->  Seq Scan on store_sales store_sales_1  (cost=0.00..804917.92 rows=28800992 width=8)
                                                                       ->  Hash  (cost=2500.73..2500.73 rows=1064 width=4)
                                                                             ->  Seq Scan on date_dim d1  (cost=0.00..2500.73 rows=1064 width=4)
                                                                                   Filter: ((d_year >= 1999) AND (d_year <= 2001))
                                                                 ->  Hash  (cost=7984.00..7984.00 rows=102000 width=16)
                                                                       ->  Seq Scan on item iss  (cost=0.00..7984.00 rows=102000 width=16)
                                                     ->  Subquery Scan on "*SELECT* 2"  (cost=11773.03..569908.73 rows=208679 width=16)
                                                           ->  Hash Join  (cost=11773.03..567821.94 rows=208679 width=12)
                                                                 Hash Cond: (catalog_sales_1.cs_item_sk = ics.i_item_sk)
                                                                 ->  Hash Join  (cost=2514.03..558015.14 rows=208679 width=4)
                                                                       Hash Cond: (catalog_sales_1.cs_sold_date_sk = d2.d_date_sk)
                                                                       ->  Seq Scan on catalog_sales catalog_sales_1  (cost=0.00..517695.61 rows=14401261 width=8)
                                                                       ->  Hash  (cost=2500.73..2500.73 rows=1064 width=4)
                                                                             ->  Seq Scan on date_dim d2  (cost=0.00..2500.73 rows=1064 width=4)
                                                                                   Filter: ((d_year >= 1999) AND (d_year <= 2001))
                                                                 ->  Hash  (cost=7984.00..7984.00 rows=102000 width=16)
                                                                       ->  Seq Scan on item ics  (cost=0.00..7984.00 rows=102000 width=16)
                                   ->  Subquery Scan on "*SELECT* 3"  (cost=11773.03..291718.57 rows=104799 width=16)
                                         ->  Hash Join  (cost=11773.03..290670.58 rows=104799 width=12)
                                               Hash Cond: (web_sales_1.ws_item_sk = iws.i_item_sk)
                                               ->  Hash Join  (cost=2514.03..281136.47 rows=104799 width=4)
                                                     Hash Cond: (web_sales_1.ws_sold_date_sk = d3.d_date_sk)
                                                     ->  Seq Scan on web_sales web_sales_1  (cost=0.00..259726.89 rows=7197889 width=8)
                                                     ->  Hash  (cost=2500.73..2500.73 rows=1064 width=4)
                                                           ->  Seq Scan on date_dim d3  (cost=0.00..2500.73 rows=1064 width=4)
                                                                 Filter: ((d_year >= 1999) AND (d_year <= 2001))
                                               ->  Hash  (cost=7984.00..7984.00 rows=102000 width=16)
                                                     ->  Seq Scan on item iws  (cost=0.00..7984.00 rows=102000 width=16)
   CTE avg_sales
     ->  Aggregate  (cost=1738253.26..1738253.27 rows=1 width=32)
           ->  Append  (cost=2514.03..1732898.96 rows=713907 width=10)
                 ->  Hash Join  (cost=2514.03..883038.74 rows=400429 width=10)
                       Hash Cond: (store_sales_2.ss_sold_date_sk = date_dim_3.d_date_sk)
                       ->  Seq Scan on store_sales store_sales_2  (cost=0.00..804917.92 rows=28800992 width=14)
                       ->  Hash  (cost=2500.73..2500.73 rows=1064 width=4)
                             ->  Seq Scan on date_dim date_dim_3  (cost=0.00..2500.73 rows=1064 width=4)
                                   Filter: ((d_year >= 1999) AND (d_year <= 2001))
                 ->  Hash Join  (cost=2514.03..558015.14 rows=208679 width=10)
                       Hash Cond: (catalog_sales_2.cs_sold_date_sk = date_dim_4.d_date_sk)
                       ->  Seq Scan on catalog_sales catalog_sales_2  (cost=0.00..517695.61 rows=14401261 width=14)
                       ->  Hash  (cost=2500.73..2500.73 rows=1064 width=4)
                             ->  Seq Scan on date_dim date_dim_4  (cost=0.00..2500.73 rows=1064 width=4)
                                   Filter: ((d_year >= 1999) AND (d_year <= 2001))
                 ->  Hash Join  (cost=2514.03..281136.47 rows=104799 width=10)
                       Hash Cond: (web_sales_2.ws_sold_date_sk = date_dim_5.d_date_sk)
                       ->  Seq Scan on web_sales web_sales_2  (cost=0.00..259726.89 rows=7197889 width=14)
                       ->  Hash  (cost=2500.73..2500.73 rows=1064 width=4)
                             ->  Seq Scan on date_dim date_dim_5  (cost=0.00..2500.73 rows=1064 width=4)
                                   Filter: ((d_year >= 1999) AND (d_year <= 2001))
   ->  GroupAggregate  (cost=8801.19..8801.43 rows=13 width=108)
         Group Key: ('store'::text), item.i_brand_id, item.i_class_id, item.i_category_id
         Group Key: ('store'::text), item.i_brand_id, item.i_class_id
         Group Key: ('store'::text), item.i_brand_id
         Group Key: ('store'::text)
         Group Key: ()
         ->  Sort  (cost=8801.19..8801.19 rows=3 width=84)
               Sort Key: ('store'::text), item.i_brand_id, item.i_class_id, item.i_category_id
               ->  Append  (cost=5281.11..8801.16 rows=3 width=84)
                     ->  GroupAggregate  (cost=5281.11..5281.25 rows=1 width=84)
                           Group Key: item.i_brand_id, item.i_class_id, item.i_category_id
                           Filter: (sum(((store_sales.ss_quantity)::numeric * store_sales.ss_list_price)) > $2)
                           InitPlan 3 (returns $2)
                             ->  CTE Scan on avg_sales  (cost=0.00..0.02 rows=1 width=32)
                           ->  Sort  (cost=5281.09..5281.10 rows=4 width=22)
                                 Sort Key: item.i_brand_id, item.i_class_id, item.i_category_id
                                 ->  Hash Join  (cost=2502.45..5281.05 rows=4 width=22)
                                       Hash Cond: (store_sales.ss_sold_date_sk = date_dim.d_date_sk)
                                       ->  Nested Loop  (cost=1.34..2755.68 rows=9242 width=26)
                                             ->  Nested Loop  (cost=0.90..221.25 rows=27 width=20)
                                                   ->  HashAggregate  (cost=0.61..0.88 rows=27 width=4)
                                                         Group Key: cross_items.ss_item_sk
                                                         ->  CTE Scan on cross_items  (cost=0.00..0.54 rows=27 width=4)
                                                   ->  Index Scan using item_pkey on item  (cost=0.29..8.16 rows=1 width=16)
                                                         Index Cond: (i_item_sk = cross_items.ss_item_sk)
                                             ->  Index Scan using store_sales_ss_item_sk_idx on store_sales  (cost=0.44..90.45 rows=342 width=18)
                                                   Index Cond: (ss_item_sk = item.i_item_sk)
                                       ->  Hash  (cost=2500.73..2500.73 rows=30 width=4)
                                             ->  Seq Scan on date_dim  (cost=0.00..2500.73 rows=30 width=4)
                                                   Filter: ((d_year = 2001) AND (d_moy = 11))
                     ->  GroupAggregate  (cost=2260.04..2260.11 rows=1 width=84)
                           Group Key: item_1.i_brand_id, item_1.i_class_id, item_1.i_category_id
                           Filter: (sum(((catalog_sales.cs_quantity)::numeric * catalog_sales.cs_list_price)) > $3)
                           InitPlan 4 (returns $3)
                             ->  CTE Scan on avg_sales avg_sales_1  (cost=0.00..0.02 rows=1 width=32)
                           ->  Sort  (cost=2260.02..2260.02 rows=2 width=22)
                                 Sort Key: item_1.i_brand_id, item_1.i_class_id, item_1.i_category_id
                                 ->  Nested Loop  (cost=1.63..2260.01 rows=2 width=22)
                                       ->  Nested Loop  (cost=1.33..771.73 rows=4718 width=26)
                                             ->  Nested Loop  (cost=0.90..221.25 rows=27 width=20)
                                                   ->  HashAggregate  (cost=0.61..0.88 rows=27 width=4)
                                                         Group Key: cross_items_1.ss_item_sk
                                                         ->  CTE Scan on cross_items cross_items_1  (cost=0.00..0.54 rows=27 width=4)
                                                   ->  Index Scan using item_pkey on item item_1  (cost=0.29..8.16 rows=1 width=16)
                                                         Index Cond: (i_item_sk = cross_items_1.ss_item_sk)
                                             ->  Index Scan using catalog_sales_cs_item_sk_idx on catalog_sales  (cost=0.43..18.64 rows=175 width=18)
                                                   Index Cond: (cs_item_sk = item_1.i_item_sk)
                                       ->  Index Scan using date_dim_pkey on date_dim date_dim_1  (cost=0.29..0.32 rows=1 width=4)
                                             Index Cond: (d_date_sk = catalog_sales.cs_sold_date_sk)
                                             Filter: ((d_year = 2001) AND (d_moy = 11))
                     ->  GroupAggregate  (cost=1259.72..1259.76 rows=1 width=84)
                           Group Key: item_2.i_brand_id, item_2.i_class_id, item_2.i_category_id
                           Filter: (sum(((web_sales.ws_quantity)::numeric * web_sales.ws_list_price)) > $4)
                           InitPlan 5 (returns $4)
                             ->  CTE Scan on avg_sales avg_sales_2  (cost=0.00..0.02 rows=1 width=32)
                           ->  Sort  (cost=1259.70..1259.71 rows=1 width=22)
                                 Sort Key: item_2.i_brand_id, item_2.i_class_id, item_2.i_category_id
                                 ->  Nested Loop  (cost=1.62..1259.69 rows=1 width=22)
                                       ->  Nested Loop  (cost=1.33..524.61 rows=2327 width=26)
                                             ->  Nested Loop  (cost=0.90..221.25 rows=27 width=20)
                                                   ->  HashAggregate  (cost=0.61..0.88 rows=27 width=4)
                                                         Group Key: cross_items_2.ss_item_sk
                                                         ->  CTE Scan on cross_items cross_items_2  (cost=0.00..0.54 rows=27 width=4)
                                                   ->  Index Scan using item_pkey on item item_2  (cost=0.29..8.16 rows=1 width=16)
                                                         Index Cond: (i_item_sk = cross_items_2.ss_item_sk)
                                             ->  Index Scan using web_sales_pkey on web_sales  (cost=0.43..10.38 rows=86 width=18)
                                                   Index Cond: (ws_item_sk = item_2.i_item_sk)
                                       ->  Index Scan using date_dim_pkey on date_dim date_dim_2  (cost=0.29..0.32 rows=1 width=4)
                                             Index Cond: (d_date_sk = web_sales.ws_sold_date_sk)
                                             Filter: ((d_year = 2001) AND (d_moy = 11))
(136 rows)

