BEGIN; BEGIN create or replace view revenue3 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1995-11-01' and l_shipdate < date'1995-11-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, revenue3 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue3 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2381658.27..2386756.03 rows=3753 width=79) (actual time=35472.950..35472.953 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue3.supplier_no) Buffers: shared hit=467540 read=864019 written=1627 InitPlan 1 (returns $0) -> Aggregate (cost=1182179.03..1182179.04 rows=1 width=8) (actual time=15942.848..15942.848 rows=1 loops=1) Buffers: shared hit=327589 read=337062 written=1 -> HashAggregate (cost=1182094.59..1182132.12 rows=3753 width=12) (actual time=15843.168..15925.437 rows=100000 loops=1) Buffers: shared hit=327589 read=337062 written=1 -> Bitmap Heap Scan on lineitem (cost=48049.94..1159324.73 rows=2276986 width=12) (actual time=2135.685..11826.626 rows=2243664 loops=1) Recheck Cond: ((l_shipdate >= '1995-11-01'::date) AND (l_shipdate < '1996-01-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=327589 read=337062 written=1 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47480.69 rows=2276986 width=0) (actual time=1765.185..1765.185 rows=2266492 loops=1) Index Cond: ((l_shipdate >= '1995-11-01'::date) AND (l_shipdate < '1996-01-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6128 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.108..52.612 rows=82975 loops=1) Buffers: shared hit=2255 read=1 -> Sort (cost=1199479.24..1199488.62 rows=3753 width=12) (actual time=35406.726..35406.727 rows=1 loops=1) Sort Key: revenue3.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=465285 read=864018 written=1627 -> Subquery Scan on revenue3 (cost=1199171.98..1199256.42 rows=3753 width=12) (actual time=35398.982..35406.692 rows=1 loops=1) Buffers: shared hit=465285 read=864018 written=1627 -> HashAggregate (cost=1199171.98..1199218.89 rows=3753 width=12) (actual time=35398.979..35406.686 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=465285 read=864018 written=1627 -> Bitmap Heap Scan on lineitem (cost=48049.94..1159324.73 rows=2276986 width=12) (actual time=2285.077..15272.652 rows=2243664 loops=1) Recheck Cond: ((l_shipdate >= '1995-11-01'::date) AND (l_shipdate < '1996-01-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=137696 read=526956 written=1626 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47480.69 rows=2276986 width=0) (actual time=1755.184..1755.184 rows=2266492 loops=1) Index Cond: ((l_shipdate >= '1995-11-01'::date) AND (l_shipdate < '1996-01-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=69 read=6060 written=420 Total runtime: 35489.074 ms (33 rows) drop view revenue3; DROP VIEW COMMIT; COMMIT