                                                                                           QUERY PLAN                                                                                            
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=912021.61..912021.86 rows=100 width=152) (actual time=14575.487..14575.514 rows=100 loops=1)
   Buffers: shared hit=617846
   ->  Sort  (cost=912021.61..912034.03 rows=4967 width=152) (actual time=14575.485..14575.500 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=617846
         ->  Nested Loop  (cost=887079.21..911831.78 rows=4967 width=152) (actual time=14267.630..14559.671 rows=19479 loops=1)
               Buffers: shared hit=617837
               ->  GroupAggregate  (cost=887078.78..887240.21 rows=4967 width=86) (actual time=14267.532..14446.558 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=539921
                     ->  Sort  (cost=887078.78..887091.20 rows=4967 width=31) (actual time=14267.499..14285.104 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=539921
                           ->  Nested Loop  (cost=2602.01..886773.86 rows=4967 width=31) (actual time=21.400..14085.097 rows=209155 loops=1)
                                 Buffers: shared hit=539918
                                 ->  Hash Join  (cost=2601.71..883287.68 rows=52050 width=35) (actual time=20.916..12574.407 rows=2119993 loops=1)
                                       Hash Cond: (store_sales.ss_store_sk = store.s_store_sk)
                                       Buffers: shared hit=518318
                                       ->  Hash Join  (cost=2594.01..883118.72 rows=59086 width=29) (actual time=20.764..11576.142 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.005..3901.142 rows=28800991 loops=1)
                                                   Buffers: shared hit=516908
                                             ->  Hash  (cost=2592.05..2592.05 rows=157 width=4) (actual time=20.744..20.745 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=10.547..20.693 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=6.53..6.53 rows=94 width=14) (actual time=0.140..0.141 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.009..0.108 rows=94 loops=1)
                                                   Filter: ((s_number_employees >= 200) AND (s_number_employees <= 295))
                                                   Rows Removed by Filter: 8
                                                   Buffers: shared hit=5
                                 ->  Result Cache  (cost=0.29..0.32 rows=1 width=4) (actual time=0.000..0.000 rows=0 loops=2119993)
                                       Cache Key: store_sales.ss_hdemo_sk
                                       Hits: 2112792  Misses: 7201  Evictions: 0  Overflows: 0  Memory Usage: 504kB
                                       Buffers: shared hit=21600
                                       ->  Index Scan using household_demographics_pkey on household_demographics  (cost=0.28..0.31 rows=1 width=4) (actual time=0.004..0.004 rows=0 loops=7201)
                                             Index Cond: (hd_demo_sk = store_sales.ss_hdemo_sk)
                                             Filter: ((hd_dep_count = 0) OR (hd_vehicle_count > 4))
                                             Rows Removed by Filter: 1
                                             Buffers: shared hit=21600
               ->  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.257 ms
 Execution Time: 14580.337 ms
(55 rows)

