                                                                                 QUERY PLAN                                                                                 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=908714.76..908715.01 rows=100 width=152) (actual time=12381.220..12381.247 rows=100 loops=1)
   Buffers: shared hit=596299
   ->  Sort  (cost=908714.76..908727.18 rows=4967 width=152) (actual time=12381.218..12381.233 rows=100 loops=1)
         Sort Key: customer.c_last_name, customer.c_first_name, (substr((store.s_city)::text, 1, 30)), (sum(store_sales.ss_net_profit))
         Sort Method: top-N heapsort  Memory: 48kB
         Buffers: shared hit=596299
         ->  Nested Loop  (cost=883772.35..908524.93 rows=4967 width=152) (actual time=12074.479..12365.368 rows=19479 loops=1)
               Buffers: shared hit=596290
               ->  GroupAggregate  (cost=883771.93..883933.36 rows=4967 width=86) (actual time=12074.386..12253.363 rows=20749 loops=1)
                     Group Key: store_sales.ss_ticket_number, store_sales.ss_customer_sk, store_sales.ss_addr_sk, store.s_city
                     Buffers: shared hit=518374
                     ->  Sort  (cost=883771.93..883784.35 rows=4967 width=31) (actual time=12074.350..12091.877 rows=209155 loops=1)
                           Sort Key: store_sales.ss_ticket_number, store_sales.ss_customer_sk, store_sales.ss_addr_sk, store.s_city
                           Sort Method: quicksort  Memory: 22479kB
                           Buffers: shared hit=518374
                           ->  Hash Join  (cost=2771.71..883467.00 rows=4967 width=31) (actual time=22.051..11893.102 rows=209155 loops=1)
                                 Hash Cond: (store_sales.ss_store_sk = store.s_store_sk)
                                 Buffers: shared hit=518371
                                 ->  Hash Join  (cost=2764.01..883443.91 rows=5639 width=25) (actual time=21.905..11793.304 rows=229663 loops=1)
                                       Hash Cond: (store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk)
                                       Buffers: shared hit=518366
                                       ->  Hash Join  (cost=2594.01..883118.72 rows=59086 width=29) (actual time=19.695..11282.316 rows=2355816 loops=1)
                                             Hash Cond: (store_sales.ss_sold_date_sk = date_dim.d_date_sk)
                                             Buffers: shared hit=518313
                                             ->  Seq Scan on store_sales  (cost=0.00..804917.92 rows=28800992 width=33) (actual time=0.004..3810.957 rows=28800991 loops=1)
                                                   Buffers: shared hit=516908
                                             ->  Hash  (cost=2592.05..2592.05 rows=157 width=4) (actual time=19.676..19.677 rows=157 loops=1)
                                                   Buckets: 1024  Batches: 1  Memory Usage: 14kB
                                                   Buffers: shared hit=1405
                                                   ->  Seq Scan on date_dim  (cost=0.00..2592.05 rows=157 width=4) (actual time=9.842..19.624 rows=157 loops=1)
                                                         Filter: ((d_dow = 1) AND (d_year = ANY ('{1999,2000,2001}'::integer[])))
                                                         Rows Removed by Filter: 72892
                                                         Buffers: shared hit=1405
                                       ->  Hash  (cost=161.00..161.00 rows=720 width=4) (actual time=1.831..1.832 rows=720 loops=1)
                                             Buckets: 1024  Batches: 1  Memory Usage: 34kB
                                             Buffers: shared hit=53
                                             ->  Seq Scan on household_demographics  (cost=0.00..161.00 rows=720 width=4) (actual time=0.014..1.637 rows=720 loops=1)
                                                   Filter: ((hd_dep_count = 0) OR (hd_vehicle_count > 4))
                                                   Rows Removed by Filter: 6480
                                                   Buffers: shared hit=53
                                 ->  Hash  (cost=6.53..6.53 rows=94 width=14) (actual time=0.135..0.136 rows=94 loops=1)
                                       Buckets: 1024  Batches: 1  Memory Usage: 13kB
                                       Buffers: shared hit=5
                                       ->  Seq Scan on store  (cost=0.00..6.53 rows=94 width=14) (actual time=0.010..0.101 rows=94 loops=1)
                                             Filter: ((s_number_employees >= 200) AND (s_number_employees <= 295))
                                             Rows Removed by Filter: 8
                                             Buffers: shared hit=5
               ->  Index Scan using customer_pkey on customer  (cost=0.42..4.94 rows=1 width=56) (actual time=0.004..0.004 rows=1 loops=20749)
                     Index Cond: (c_customer_sk = store_sales.ss_customer_sk)
                     Buffers: shared hit=77916
 Planning:
   Buffers: shared hit=600
 Planning Time: 3.029 ms
 Execution Time: 12383.438 ms
(54 rows)

