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 >= '1994-01-01' and l_shipdate < date'1994-01-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=2367451.35..2372547.71 rows=3677 width=79) (actual time=20929.632..20929.636 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue9.supplier_no) Buffers: shared hit=700680 read=623237 dirtied=481 written=12764 InitPlan 1 (returns $0) -> Aggregate (cost=1175298.06..1175298.07 rows=1 width=8) (actual time=11484.916..11484.916 rows=1 loops=1) Buffers: shared hit=382411 read=279241 written=12598 -> HashAggregate (cost=1175215.32..1175252.09 rows=3677 width=12) (actual time=11443.098..11474.508 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=382411 read=279241 written=12598 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=46902.05..1153032.41 rows=2218291 width=12) (actual time=3413.454..9625.521 rows=2242078 loops=1) Recheck Cond: ((l_shipdate >= '1994-01-01'::date) AND (l_shipdate < '1994-04-01 00:00:00'::timestamp without time zone)) Heap Blocks: exact=655522 Buffers: shared hit=382411 read=279241 written=12598 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46347.48 rows=2218291 width=0) (actual time=2915.704..2915.704 rows=2258823 loops=1) Index Cond: ((l_shipdate >= '1994-01-01'::date) AND (l_shipdate < '1994-04-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=762 read=5368 written=434 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.035..9.034 rows=21986 loops=1) Buffers: shared hit=613 -> Sort (cost=1192153.00..1192162.19 rows=3677 width=12) (actual time=20918.278..20918.280 rows=1 loops=1) Sort Key: revenue9.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=700067 read=623237 dirtied=481 written=12764 -> Subquery Scan on revenue9 (cost=1191852.51..1191935.24 rows=3677 width=12) (actual time=20895.464..20918.238 rows=1 loops=1) Buffers: shared hit=700067 read=623237 dirtied=481 written=12764 -> HashAggregate (cost=1191852.51..1191898.47 rows=3677 width=12) (actual time=20895.463..20918.235 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=700067 read=623237 dirtied=481 written=12764 -> Bitmap Heap Scan on lineitem (cost=46902.05..1153032.41 rows=2218291 width=12) (actual time=1329.168..7510.774 rows=2242078 loops=1) Recheck Cond: ((l_shipdate >= '1994-01-01'::date) AND (l_shipdate < '1994-04-01 00:00:00'::timestamp without time zone)) Heap Blocks: exact=655522 Buffers: shared hit=317656 read=343996 dirtied=481 written=166 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46347.48 rows=2218291 width=0) (actual time=1013.973..1013.973 rows=2257759 loops=1) Index Cond: ((l_shipdate >= '1994-01-01'::date) AND (l_shipdate < '1994-04-01 00:00:00'::timestamp without time zone)) Buffers: shared read=6130 Planning time: 2.363 ms Execution time: 20954.347 ms (38 rows) drop view revenue9; DROP VIEW COMMIT; COMMIT