                                                                                                     QUERY PLAN                                                                                                      
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=1769881.86..1769881.89 rows=13 width=126)
   ->  Sort  (cost=1769881.86..1769881.89 rows=13 width=126)
         Sort Key: ((GROUPING(store.s_state) + GROUPING(store.s_county))) DESC, (CASE WHEN (((GROUPING(store.s_state) + GROUPING(store.s_county))) = 0) THEN store.s_state ELSE NULL::bpchar END), (rank() OVER (?))
         ->  WindowAgg  (cost=1769881.20..1769881.62 rows=13 width=126)
               ->  Sort  (cost=1769881.20..1769881.23 rows=13 width=94)
                     Sort Key: ((GROUPING(store.s_state) + GROUPING(store.s_county))), (CASE WHEN (GROUPING(store.s_county) = 0) THEN store.s_state ELSE NULL::bpchar END), (sum(store_sales.ss_net_profit)) DESC
                     ->  MixedAggregate  (cost=886609.91..1769880.96 rows=13 width=94)
                           Hash Key: store.s_state, store.s_county
                           Hash Key: store.s_state
                           Group Key: ()
                           ->  Nested Loop  (cost=886609.91..1769206.21 rows=44968 width=24)
                                 Join Filter: (store.s_state = tmp1.s_state)
                                 ->  Subquery Scan on tmp1  (cost=884097.19..884097.29 rows=1 width=3)
                                       Filter: (tmp1.ranking <= 5)
                                       ->  WindowAgg  (cost=884097.19..884097.25 rows=3 width=43)
                                             ->  Sort  (cost=884097.19..884097.20 rows=3 width=35)
                                                   Sort Key: store_1.s_state, (sum(store_sales_1.ss_net_profit)) DESC
                                                   ->  HashAggregate  (cost=884097.13..884097.17 rows=3 width=35)
                                                         Group Key: store_1.s_state
                                                         ->  Hash Join  (cost=2512.72..883422.61 rows=134905 width=9)
                                                               Hash Cond: (store_sales_1.ss_store_sk = store_1.s_store_sk)
                                                               ->  Hash Join  (cost=2505.42..883030.13 rows=141129 width=10)
                                                                     Hash Cond: (store_sales_1.ss_sold_date_sk = date_dim.d_date_sk)
                                                                     ->  Seq Scan on store_sales store_sales_1  (cost=0.00..804917.92 rows=28800992 width=14)
                                                                     ->  Hash  (cost=2500.73..2500.73 rows=375 width=4)
                                                                           ->  Seq Scan on date_dim  (cost=0.00..2500.73 rows=375 width=4)
                                                                                 Filter: ((d_month_seq >= 1180) AND (d_month_seq <= 1191))
                                                               ->  Hash  (cost=6.02..6.02 rows=102 width=7)
                                                                     ->  Seq Scan on store store_1  (cost=0.00..6.02 rows=102 width=7)
                                 ->  Hash Join  (cost=2512.72..883422.61 rows=134905 width=24)
                                       Hash Cond: (store_sales.ss_store_sk = store.s_store_sk)
                                       ->  Hash Join  (cost=2505.42..883030.13 rows=141129 width=10)
                                             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=14)
                                             ->  Hash  (cost=2500.73..2500.73 rows=375 width=4)
                                                   ->  Seq Scan on date_dim d1  (cost=0.00..2500.73 rows=375 width=4)
                                                         Filter: ((d_month_seq >= 1180) AND (d_month_seq <= 1191))
                                       ->  Hash  (cost=6.02..6.02 rows=102 width=22)
                                             ->  Seq Scan on store  (cost=0.00..6.02 rows=102 width=22)
(39 rows)

