BEGIN; BEGIN create or replace view revenue12 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-10-01' and l_shipdate < date'1994-10-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, revenue12 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue12 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2391584.44..2396682.36 rows=3764 width=79) (actual time=31778.119..31778.124 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue12.supplier_no) Buffers: shared hit=555116 read=781086 InitPlan 1 (returns $0) -> Aggregate (cost=1187081.70..1187081.71 rows=1 width=8) (actual time=14153.109..14153.109 rows=1 loops=1) Buffers: shared hit=249126 read=418777 -> HashAggregate (cost=1186997.01..1187034.65 rows=3764 width=12) (actual time=14077.220..14142.206 rows=100000 loops=1) Buffers: shared hit=249126 read=418777 -> Bitmap Heap Scan on lineitem (cost=48290.06..1164067.03 rows=2292998 width=12) (actual time=2005.737..10564.891 rows=2243588 loops=1) Recheck Cond: ((l_shipdate >= '1994-10-01'::date) AND (l_shipdate < '1994-12-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=249126 read=418777 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47716.81 rows=2292998 width=0) (actual time=1657.342..1657.342 rows=2275024 loops=1) Index Cond: ((l_shipdate >= '1994-10-01'::date) AND (l_shipdate < '1994-12-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6129 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.114..7.398 rows=13954 loops=1) Buffers: shared hit=394 read=1 -> Sort (cost=1204502.73..1204512.14 rows=3764 width=12) (actual time=31769.173..31769.175 rows=1 loops=1) Sort Key: revenue12.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=554722 read=781085 -> Subquery Scan on revenue12 (cost=1204194.49..1204279.18 rows=3764 width=12) (actual time=31734.969..31769.140 rows=1 loops=1) Buffers: shared hit=554722 read=781085 -> HashAggregate (cost=1204194.49..1204241.54 rows=3764 width=12) (actual time=31734.967..31769.135 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=554722 read=781085 -> Bitmap Heap Scan on lineitem (cost=48290.06..1164067.03 rows=2292998 width=12) (actual time=2562.433..13599.401 rows=2243588 loops=1) Recheck Cond: ((l_shipdate >= '1994-10-01'::date) AND (l_shipdate < '1994-12-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=305596 read=362308 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47716.81 rows=2292998 width=0) (actual time=2163.204..2163.204 rows=2275024 loops=1) Index Cond: ((l_shipdate >= '1994-10-01'::date) AND (l_shipdate < '1994-12-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6130 Total runtime: 31795.492 ms (33 rows) drop view revenue12; DROP VIEW COMMIT; COMMIT