BEGIN; BEGIN create or replace view revenue5 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1995-07-01' and l_shipdate < date'1995-07-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, revenue5 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue5 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2358272.65..2363369.51 rows=3711 width=79) (actual time=22597.458..22597.463 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue5.supplier_no) Buffers: shared hit=629679 read=690189 written=8005 InitPlan 1 (returns $0) -> Aggregate (cost=1170662.69..1170662.70 rows=1 width=8) (actual time=10806.928..10806.928 rows=1 loops=1) Buffers: shared hit=277709 read=381665 written=7983 -> HashAggregate (cost=1170579.19..1170616.30 rows=3711 width=12) (actual time=10751.295..10796.363 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=277709 read=381665 written=7983 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47276.72..1148276.60 rows=2230259 width=12) (actual time=1397.846..8423.633 rows=2247994 loops=1) Recheck Cond: ((l_shipdate >= '1995-07-01'::date) AND (l_shipdate < '1995-09-29 00:00:00'::timestamp without time zone)) Heap Blocks: exact=653235 Buffers: shared hit=277709 read=381665 written=7983 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46719.15 rows=2230259 width=0) (actual time=1073.303..1073.303 rows=2250248 loops=1) Index Cond: ((l_shipdate >= '1995-07-01'::date) AND (l_shipdate < '1995-09-29 00:00:00'::timestamp without time zone)) Buffers: shared read=6139 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.033..17.535 rows=40959 loops=1) Buffers: shared hit=1120 -> Sort (cost=1187609.65..1187618.93 rows=3711 width=12) (actual time=22575.974..22575.976 rows=1 loops=1) Sort Key: revenue5.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=628559 read=690189 written=8005 -> Subquery Scan on revenue5 (cost=1187306.14..1187389.63 rows=3711 width=12) (actual time=22566.611..22575.940 rows=1 loops=1) Buffers: shared hit=628559 read=690189 written=8005 -> HashAggregate (cost=1187306.14..1187352.52 rows=3711 width=12) (actual time=22566.609..22575.935 rows=1 loops=1) Group Key: lineitem.l_suppkey Filter: (sum((lineitem.l_extendedprice * (1::double precision - lineitem.l_discount))) = $0) Rows Removed by Filter: 99999 Buffers: shared hit=628559 read=690189 written=8005 -> Bitmap Heap Scan on lineitem (cost=47276.72..1148276.60 rows=2230259 width=12) (actual time=1966.760..9134.394 rows=2247994 loops=1) Recheck Cond: ((l_shipdate >= '1995-07-01'::date) AND (l_shipdate < '1995-09-29 00:00:00'::timestamp without time zone)) Heap Blocks: exact=653235 Buffers: shared hit=350850 read=308524 written=22 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46719.15 rows=2230259 width=0) (actual time=1585.676..1585.676 rows=2250248 loops=1) Index Cond: ((l_shipdate >= '1995-07-01'::date) AND (l_shipdate < '1995-09-29 00:00:00'::timestamp without time zone)) Buffers: shared read=6139 Planning time: 2.689 ms Execution time: 22617.002 ms (38 rows) drop view revenue5; DROP VIEW COMMIT; COMMIT