                                                                                                                     QUERY PLAN                                                                                                                      
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=895753.37..895753.62 rows=100 width=210) (actual time=21684.336..21684.360 rows=100 loops=1)
   Buffers: shared hit=525294
   ->  Sort  (cost=895753.37..895755.87 rows=1001 width=210) (actual time=21684.333..21684.345 rows=100 loops=1)
         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 (?))
         Sort Method: quicksort  Memory: 61kB
         Buffers: shared hit=525294
         ->  WindowAgg  (cost=895680.08..895715.11 rows=1001 width=210) (actual time=21683.402..21683.746 rows=166 loops=1)
               Buffers: shared hit=525285
               ->  Sort  (cost=895680.08..895682.58 rows=1001 width=178) (actual time=21683.384..21683.403 rows=166 loops=1)
                     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)))
                     Sort Method: quicksort  Memory: 61kB
                     Buffers: shared hit=525285
                     ->  MixedAggregate  (cost=11589.90..895630.19 rows=1001 width=178) (actual time=21682.581..21682.902 rows=166 loops=1)
                           Hash Key: item.i_category, item.i_class
                           Hash Key: item.i_category
                           Group Key: ()
                           Batches: 1  Memory Usage: 329kB
                           Buffers: shared hit=525282
                           ->  Hash Join  (cost=11589.90..892813.46 rows=124187 width=114) (actual time=126.048..16390.644 rows=1888703 loops=1)
                                 Hash Cond: (store_sales.ss_item_sk = item.i_item_sk)
                                 Buffers: shared hit=525282
                                 ->  Hash Join  (cost=2330.90..883228.46 rows=124187 width=16) (actual time=19.335..14867.812 rows=1888703 loops=1)
                                       Hash Cond: (store_sales.ss_store_sk = store.s_store_sk)
                                       Buffers: shared hit=518318
                                       ->  Hash Join  (cost=2322.65..882847.36 rows=136613 width=20) (actual time=19.139..13374.555 rows=5470761 loops=1)
                                             Hash Cond: (store_sales.ss_sold_date_sk = d1.d_date_sk)
                                             Buffers: shared hit=518313
                                             ->  Seq Scan on store_sales  (cost=0.00..804917.92 rows=28800992 width=24) (actual time=0.005..3936.546 rows=28800991 loops=1)
                                                   Buffers: shared hit=516908
                                             ->  Hash  (cost=2318.11..2318.11 rows=363 width=4) (actual time=19.086..19.087 rows=365 loops=1)
                                                   Buckets: 1024  Batches: 1  Memory Usage: 21kB
                                                   Buffers: shared hit=1405
                                                   ->  Seq Scan on date_dim d1  (cost=0.00..2318.11 rows=363 width=4) (actual time=9.777..18.982 rows=365 loops=1)
                                                         Filter: (d_year = 2001)
                                                         Rows Removed by Filter: 72684
                                                         Buffers: shared hit=1405
                                       ->  Hash  (cost=7.04..7.04 rows=97 width=4) (actual time=0.159..0.160 rows=32 loops=1)
                                             Buckets: 1024  Batches: 1  Memory Usage: 10kB
                                             Buffers: shared hit=5
                                             ->  Seq Scan on store  (cost=0.00..7.04 rows=97 width=4) (actual time=0.014..0.144 rows=32 loops=1)
                                                   Filter: (s_state = ANY ('{TN,TN,TN,TN,TN,TN,TN,TN}'::bpchar[]))
                                                   Rows Removed by Filter: 70
                                                   Buffers: shared hit=5
                                 ->  Hash  (cost=7984.00..7984.00 rows=102000 width=106) (actual time=106.287..106.287 rows=102000 loops=1)
                                       Buckets: 131072  Batches: 1  Memory Usage: 14946kB
                                       Buffers: shared hit=6964
                                       ->  Seq Scan on item  (cost=0.00..7984.00 rows=102000 width=106) (actual time=0.013..63.606 rows=102000 loops=1)
                                             Buffers: shared hit=6964
 Planning:
   Buffers: shared hit=415
 Planning Time: 2.478 ms
 Execution Time: 21684.757 ms
(52 rows)

