BEGIN; BEGIN create or replace view revenue7 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1996-06-01' and l_shipdate < date'1996-06-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, revenue7 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue7 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2389000.71..2394098.58 rows=3760 width=79) (actual time=35245.209..35245.212 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue7.supplier_no) Buffers: shared hit=527738 read=806146 written=35795 InitPlan 1 (returns $0) -> Aggregate (cost=1185808.88..1185808.89 rows=1 width=8) (actual time=14080.705..14080.705 rows=1 loops=1) Buffers: shared hit=374968 read=291808 written=109 -> HashAggregate (cost=1185724.28..1185761.88 rows=3760 width=12) (actual time=13999.135..14068.294 rows=100000 loops=1) Buffers: shared hit=374968 read=291808 written=109 -> Bitmap Heap Scan on lineitem (cost=48206.38..1162844.72 rows=2287956 width=12) (actual time=2040.265..10452.063 rows=2243929 loops=1) Recheck Cond: ((l_shipdate >= '1996-06-01'::date) AND (l_shipdate < '1996-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=374968 read=291808 written=109 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47634.39 rows=2287956 width=0) (actual time=1620.540..1620.540 rows=2276824 loops=1) Index Cond: ((l_shipdate >= '1996-06-01'::date) AND (l_shipdate < '1996-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=6 read=6126 written=5 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.087..7.865 rows=11829 loops=1) Buffers: shared hit=330 read=1 -> Sort (cost=1203191.83..1203201.23 rows=3760 width=12) (actual time=35235.417..35235.418 rows=1 loops=1) Sort Key: revenue7.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=527408 read=806145 written=35795 -> Subquery Scan on revenue7 (cost=1202883.95..1202968.55 rows=3760 width=12) (actual time=35193.322..35235.385 rows=1 loops=1) Buffers: shared hit=527408 read=806145 written=35795 -> HashAggregate (cost=1202883.95..1202930.95 rows=3760 width=12) (actual time=35193.320..35235.379 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=527408 read=806145 written=35795 -> Bitmap Heap Scan on lineitem (cost=48206.38..1162844.72 rows=2287956 width=12) (actual time=2244.260..16908.535 rows=2243929 loops=1) Recheck Cond: ((l_shipdate >= '1996-06-01'::date) AND (l_shipdate < '1996-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=152440 read=514337 written=35686 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47634.39 rows=2287956 width=0) (actual time=1770.266..1770.266 rows=2274804 loops=1) Index Cond: ((l_shipdate >= '1996-06-01'::date) AND (l_shipdate < '1996-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=158 read=5975 written=14 Total runtime: 35271.054 ms (33 rows) drop view revenue7; DROP VIEW COMMIT; COMMIT