                                                                                                                     QUERY PLAN                                                                                                                      
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=898777.61..898777.86 rows=100 width=210)
   ->  Sort  (cost=898777.61..898780.11 rows=1001 width=210)
         Sort Key: ((GROUPING(item.i_category) + GROUPING(item.i_class))) DESC, (CASE WHEN (((GROUPING(item.i_category) + GROUPING(item.i_class))) = 0) THEN item.i_category ELSE NULL::bpchar END), (rank() OVER (?))
         ->  WindowAgg  (cost=898704.31..898739.35 rows=1001 width=210)
               ->  Sort  (cost=898704.31..898706.82 rows=1001 width=178)
                     Sort Key: ((GROUPING(item.i_category) + GROUPING(item.i_class))), (CASE WHEN (GROUPING(item.i_class) = 0) THEN item.i_category ELSE NULL::bpchar END), ((sum(store_sales.ss_net_profit) / sum(store_sales.ss_ext_sales_price)))
                     ->  MixedAggregate  (cost=11581.80..898654.43 rows=1001 width=178)
                           Hash Key: item.i_category, item.i_class
                           Hash Key: item.i_category
                           Group Key: ()
                           ->  Hash Join  (cost=11581.80..895837.70 rows=124187 width=114)
                                 Hash Cond: (store_sales.ss_item_sk = item.i_item_sk)
                                 ->  Nested Loop  (cost=2322.80..886252.70 rows=124187 width=16)
                                       ->  Hash Join  (cost=2322.65..882847.36 rows=136613 width=20)
                                             Hash Cond: (store_sales.ss_sold_date_sk = d1.d_date_sk)
                                             ->  Seq Scan on store_sales  (cost=0.00..804917.92 rows=28800992 width=24)
                                             ->  Hash  (cost=2318.11..2318.11 rows=363 width=4)
                                                   ->  Seq Scan on date_dim d1  (cost=0.00..2318.11 rows=363 width=4)
                                                         Filter: (d_year = 2001)
                                       ->  Result Cache  (cost=0.15..0.18 rows=1 width=4)
                                             Cache Key: store_sales.ss_store_sk
                                             ->  Index Scan using store_pkey on store  (cost=0.14..0.17 rows=1 width=4)
                                                   Index Cond: (s_store_sk = store_sales.ss_store_sk)
                                                   Filter: (s_state = ANY ('{TN,TN,TN,TN,TN,TN,TN,TN}'::bpchar[]))
                                 ->  Hash  (cost=7984.00..7984.00 rows=102000 width=106)
                                       ->  Seq Scan on item  (cost=0.00..7984.00 rows=102000 width=106)
(26 rows)

