                                                                          QUERY PLAN                                                                           
---------------------------------------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=27350973.98..27350973.98 rows=1 width=72)
   CTE ws_wh
     ->  Hash Join  (cost=377817.50..7260666.23 rows=426765799 width=12)
           Hash Cond: (ws1_1.ws_order_number = ws2.ws_order_number)
           Join Filter: (ws1_1.ws_warehouse_sk <> ws2.ws_warehouse_sk)
           ->  Seq Scan on web_sales ws1_1  (cost=0.00..259726.89 rows=7197889 width=8)
           ->  Hash  (cost=259726.89..259726.89 rows=7197889 width=8)
                 ->  Seq Scan on web_sales ws2  (cost=0.00..259726.89 rows=7197889 width=8)
   ->  Sort  (cost=20090307.74..20090307.75 rows=1 width=72)
         Sort Key: (count(DISTINCT ws1.ws_order_number))
         ->  Aggregate  (cost=20090307.72..20090307.73 rows=1 width=72)
               ->  Hash Join  (cost=9607633.92..20090307.70 rows=2 width=16)
                     Hash Cond: (ws1.ws_order_number = ws_wh.ws_order_number)
                     ->  Nested Loop Semi Join  (cost=5398.95..10488072.69 rows=5 width=24)
                           ->  Nested Loop  (cost=4.35..315955.32 rows=5 width=16)
                                 ->  Nested Loop  (cost=3.93..315406.38 rows=1238 width=20)
                                       ->  Hash Join  (cost=3.62..280530.99 rows=1370615 width=24)
                                             Hash Cond: (ws1.ws_web_site_sk = web_site.web_site_sk)
                                             ->  Seq Scan on web_sales ws1  (cost=0.00..259726.89 rows=7197889 width=28)
                                             ->  Hash  (cost=3.52..3.52 rows=8 width=4)
                                                   ->  Seq Scan on web_site  (cost=0.00..3.52 rows=8 width=4)
                                                         Filter: (web_company_name = 'pri'::bpchar)
                                       ->  Result Cache  (cost=0.30..0.33 rows=1 width=4)
                                             Cache Key: ws1.ws_ship_date_sk
                                             ->  Index Scan using date_dim_pkey on date_dim  (cost=0.29..0.32 rows=1 width=4)
                                                   Index Cond: (d_date_sk = ws1.ws_ship_date_sk)
                                                   Filter: ((d_date >= '2002-05-01'::date) AND (d_date <= '2002-06-30 00:00:00'::timestamp without time zone))
                                 ->  Index Scan using customer_address_pkey on customer_address  (cost=0.42..0.44 rows=1 width=4)
                                       Index Cond: (ca_address_sk = ws1.ws_ship_addr_sk)
                                       Filter: (ca_state = 'MA'::bpchar)
                           ->  Hash Join  (cost=5394.60..10141113.46 rows=2491 width=8)
                                 Hash Cond: (ws_wh_1.ws_order_number = web_returns.wr_order_number)
                                 Join Filter: (ws1.ws_order_number = ws_wh_1.ws_order_number)
                                 ->  CTE Scan on ws_wh ws_wh_1  (cost=0.00..8535315.98 rows=426765799 width=4)
                                 ->  Hash  (cost=5394.57..5394.57 rows=2 width=4)
                                       ->  Index Only Scan using web_returns_pkey on web_returns  (cost=0.42..5394.57 rows=2 width=4)
                                             Index Cond: (wr_order_number = ws1.ws_order_number)
                     ->  Hash  (cost=9602232.48..9602232.48 rows=200 width=4)
                           ->  HashAggregate  (cost=9602230.48..9602232.48 rows=200 width=4)
                                 Group Key: ws_wh.ws_order_number
                                 ->  CTE Scan on ws_wh  (cost=0.00..8535315.98 rows=426765799 width=4)
(41 rows)

