BEGIN; BEGIN create or replace view revenue9 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1993-04-01' and l_shipdate < date'1993-04-01' + interval '90 days' group by l_suppkey; CREATE VIEW EXPLAIN (ANALYZE, BUFFERS) select s_suppkey, s_name, s_address, s_phone, total_revenue from supplier, revenue9 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue9 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2373269.64..2378367.56 rows=3764 width=79) (actual time=48564.037..48564.039 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue9.supplier_no) Buffers: shared hit=465738 read=861003 written=22533 InitPlan 1 (returns $0) -> Aggregate (cost=1177986.55..1177986.56 rows=1 width=8) (actual time=23554.196..23554.196 rows=1 loops=1) Buffers: shared hit=239225 read=423894 written=22457 -> HashAggregate (cost=1177901.86..1177939.50 rows=3764 width=12) (actual time=23494.327..23542.907 rows=100000 loops=1) Buffers: shared hit=239225 read=423894 written=22457 -> Bitmap Heap Scan on lineitem (cost=48135.91..1155137.88 rows=2276398 width=12) (actual time=2562.455..19063.328 rows=2250107 loops=1) Recheck Cond: ((l_shipdate >= '1993-04-01'::date) AND (l_shipdate < '1993-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=239225 read=423894 written=22457 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47566.81 rows=2276398 width=0) (actual time=2049.491..2049.491 rows=2263738 loops=1) Index Cond: ((l_shipdate >= '1993-04-01'::date) AND (l_shipdate < '1993-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=304 read=5841 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.070..8.414 rows=17858 loops=1) Buffers: shared hit=502 -> Sort (cost=1195283.08..1195292.49 rows=3764 width=12) (actual time=48553.689..48553.689 rows=1 loops=1) Sort Key: revenue9.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=465236 read=861003 written=22533 -> Subquery Scan on revenue9 (cost=1194974.84..1195059.53 rows=3764 width=12) (actual time=48547.059..48553.655 rows=1 loops=1) Buffers: shared hit=465236 read=861003 written=22533 -> HashAggregate (cost=1194974.84..1195021.89 rows=3764 width=12) (actual time=48547.057..48553.651 rows=1 loops=1) Filter: (sum((public.lineitem.l_extendedprice * (1::double precision - public.lineitem.l_discount))) = $0) Rows Removed by Filter: 99999 Buffers: shared hit=465236 read=861003 written=22533 -> Bitmap Heap Scan on lineitem (cost=48135.91..1155137.88 rows=2276398 width=12) (actual time=2446.625..20798.087 rows=2250107 loops=1) Recheck Cond: ((l_shipdate >= '1993-04-01'::date) AND (l_shipdate < '1993-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=226011 read=437109 written=76 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47566.81 rows=2276398 width=0) (actual time=2084.897..2084.897 rows=2263423 loops=1) Index Cond: ((l_shipdate >= '1993-04-01'::date) AND (l_shipdate < '1993-06-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6146 Total runtime: 48575.578 ms (33 rows) drop view revenue9; DROP VIEW COMMIT; COMMIT