                                                                                                                                 QUERY PLAN                                                                                                                                  
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Sort  (cost=887417.31..887417.67 rows=143 width=77)
   Sort Key: (count(*)) DESC, customer.c_last_name
   ->  Nested Loop  (cost=886200.17..887412.19 rows=143 width=77)
         ->  GroupAggregate  (cost=886199.74..886231.84 rows=143 width=16)
               Group Key: store_sales.ss_ticket_number, store_sales.ss_customer_sk
               Filter: ((count(*) >= 1) AND (count(*) <= 5))
               ->  Sort  (cost=886199.74..886202.95 rows=1284 width=8)
                     Sort Key: store_sales.ss_ticket_number, store_sales.ss_customer_sk
                     ->  Nested Loop  (cost=2783.37..886133.45 rows=1284 width=8)
                           ->  Hash Join  (cost=2783.07..883381.74 rows=19807 width=12)
                                 Hash Cond: (store_sales.ss_store_sk = store.s_store_sk)
                                 ->  Hash Join  (cost=2775.57..883300.28 rows=27097 width=16)
                                       Hash Cond: (store_sales.ss_sold_date_sk = date_dim.d_date_sk)
                                       ->  Seq Scan on store_sales  (cost=0.00..804917.92 rows=28800992 width=20)
                                       ->  Hash  (cost=2774.67..2774.67 rows=72 width=4)
                                             ->  Seq Scan on date_dim  (cost=0.00..2774.67 rows=72 width=4)
                                                   Filter: ((d_dom >= 1) AND (d_dom <= 2) AND (d_year = ANY ('{1999,2000,2001}'::integer[])))
                                 ->  Hash  (cost=6.53..6.53 rows=78 width=4)
                                       ->  Seq Scan on store  (cost=0.00..6.53 rows=78 width=4)
                                             Filter: ((s_county)::text = ANY ('{"Williamson County","Williamson County","Williamson County","Williamson County"}'::text[]))
                           ->  Result Cache  (cost=0.29..0.33 rows=1 width=4)
                                 Cache Key: store_sales.ss_hdemo_sk
                                 ->  Index Scan using household_demographics_pkey on household_demographics  (cost=0.28..0.32 rows=1 width=4)
                                       Index Cond: (hd_demo_sk = store_sales.ss_hdemo_sk)
                                       Filter: ((hd_vehicle_count > 0) AND ((hd_buy_potential = '1001-5000'::bpchar) OR (hd_buy_potential = '5001-10000'::bpchar)) AND (CASE WHEN (hd_vehicle_count > 0) THEN (hd_dep_count / hd_vehicle_count) ELSE NULL::integer END > 1))
         ->  Index Scan using customer_pkey on customer  (cost=0.42..8.24 rows=1 width=69)
               Index Cond: (c_customer_sk = store_sales.ss_customer_sk)
(27 rows)

