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 >= '1993-09-01' and l_shipdate < date'1993-09-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=2366871.15..2371969.28 rows=3778 width=79) (actual time=94439.872..94439.876 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue4.supplier_no) Buffers: shared hit=596080 read=727004 written=17559 InitPlan 1 (returns $0) -> Aggregate (cost=1174793.19..1174793.20 rows=1 width=8) (actual time=38822.905..38822.905 rows=1 loops=1) Buffers: shared hit=405011 read=255538 written=15065 -> HashAggregate (cost=1174708.18..1174745.96 rows=3778 width=12) (actual time=38767.817..38810.716 rows=100000 loops=1) Buffers: shared hit=405011 read=255538 written=15065 -> Bitmap Heap Scan on lineitem (cost=48174.56..1151961.13 rows=2274705 width=12) (actual time=2330.357..34091.363 rows=2248873 loops=1) Recheck Cond: ((l_shipdate >= '1993-09-01'::date) AND (l_shipdate < '1993-11-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=405011 read=255538 written=15065 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47605.88 rows=2274705 width=0) (actual time=1883.063..1883.063 rows=2256439 loops=1) Index Cond: ((l_shipdate >= '1993-09-01'::date) AND (l_shipdate < '1993-11-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=4296 read=1845 written=104 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.141..94.905 rows=72980 loops=1) Buffers: shared hit=1984 read=1 -> Sort (cost=1192077.95..1192087.40 rows=3778 width=12) (actual time=94333.385..94333.386 rows=1 loops=1) Sort Key: revenue4.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=594096 read=727003 written=17559 -> Subquery Scan on revenue4 (cost=1191768.47..1191853.47 rows=3778 width=12) (actual time=94302.261..94333.344 rows=1 loops=1) Buffers: shared hit=594096 read=727003 written=17559 -> HashAggregate (cost=1191768.47..1191815.69 rows=3778 width=12) (actual time=94302.259..94333.339 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=594096 read=727003 written=17559 -> Bitmap Heap Scan on lineitem (cost=48174.56..1151961.13 rows=2274705 width=12) (actual time=5254.888..50347.104 rows=2248873 loops=1) Recheck Cond: ((l_shipdate >= '1993-09-01'::date) AND (l_shipdate < '1993-11-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=189085 read=471465 written=2494 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47605.88 rows=2274705 width=0) (actual time=4806.517..4806.517 rows=2255361 loops=1) Index Cond: ((l_shipdate >= '1993-09-01'::date) AND (l_shipdate < '1993-11-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6142 Total runtime: 94464.653 ms (33 rows) drop view revenue4; DROP VIEW COMMIT; COMMIT