BEGIN; BEGIN create or replace view revenue4 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1995-12-01' and l_shipdate < date'1995-12-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, revenue4 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue4 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2365076.85..2370174.59 rows=3752 width=79) (actual time=27822.879..27822.882 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue4.supplier_no) Buffers: shared hit=431033 read=889285 dirtied=378 written=137 InitPlan 1 (returns $0) -> Aggregate (cost=1173964.18..1173964.19 rows=1 width=8) (actual time=12550.637..12550.637 rows=1 loops=1) Buffers: shared hit=242381 read=417527 written=46 -> HashAggregate (cost=1173879.76..1173917.28 rows=3752 width=12) (actual time=12459.622..12532.248 rows=100000 loops=1) Buffers: shared hit=242381 read=417527 written=46 -> Bitmap Heap Scan on lineitem (cost=47794.66..1151312.12 rows=2256764 width=12) (actual time=1748.517..9027.373 rows=2242320 loops=1) Recheck Cond: ((l_shipdate >= '1995-12-01'::date) AND (l_shipdate < '1996-02-29 00:00:00'::timestamp without time zone)) Buffers: shared hit=242381 read=417527 written=46 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47230.47 rows=2256764 width=0) (actual time=1316.346..1316.346 rows=2249074 loops=1) Index Cond: ((l_shipdate >= '1995-12-01'::date) AND (l_shipdate < '1996-02-29 00:00:00'::timestamp without time zone)) Buffers: shared read=6125 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.054..7.514 rows=17822 loops=1) Buffers: shared hit=501 -> Sort (cost=1191112.66..1191122.04 rows=3752 width=12) (actual time=27813.499..27813.501 rows=1 loops=1) Sort Key: revenue4.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=430532 read=889285 dirtied=378 written=137 -> Subquery Scan on revenue4 (cost=1190805.49..1190889.91 rows=3752 width=12) (actual time=27791.778..27813.463 rows=1 loops=1) Buffers: shared hit=430532 read=889285 dirtied=378 written=137 -> HashAggregate (cost=1190805.49..1190852.39 rows=3752 width=12) (actual time=27791.775..27813.458 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=430532 read=889285 dirtied=378 written=137 -> Bitmap Heap Scan on lineitem (cost=47794.66..1151312.12 rows=2256764 width=12) (actual time=2382.763..11701.649 rows=2242320 loops=1) Recheck Cond: ((l_shipdate >= '1995-12-01'::date) AND (l_shipdate < '1996-02-29 00:00:00'::timestamp without time zone)) Buffers: shared hit=188151 read=471758 dirtied=378 written=91 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47230.47 rows=2256764 width=0) (actual time=1813.918..1813.918 rows=2249074 loops=1) Index Cond: ((l_shipdate >= '1995-12-01'::date) AND (l_shipdate < '1996-02-29 00:00:00'::timestamp without time zone)) Buffers: shared read=6126 written=9 Total runtime: 27841.057 ms (33 rows) drop view revenue4; DROP VIEW COMMIT; COMMIT