BEGIN; BEGIN create or replace view revenue29 (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, revenue29 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue29 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2380974.93..2386071.66 rows=3702 width=79) (actual time=20904.664..20904.668 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue29.supplier_no) Buffers: shared hit=797676 read=535942 written=533 InitPlan 1 (returns $0) -> Aggregate (cost=1181942.43..1181942.44 rows=1 width=8) (actual time=10093.918..10093.918 rows=1 loops=1) Buffers: shared hit=400191 read=265626 written=170 -> HashAggregate (cost=1181859.14..1181896.16 rows=3702 width=12) (actual time=10048.137..10083.056 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=400191 read=265626 written=170 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47436.69..1159365.36 rows=2249378 width=12) (actual time=2195.182..8126.338 rows=2249421 loops=1) Recheck Cond: ((l_shipdate >= '1993-09-01'::date) AND (l_shipdate < '1993-11-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=659676 Buffers: shared hit=400191 read=265626 written=170 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46874.35 rows=2249378 width=0) (actual time=1830.388..1830.388 rows=2273484 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=6141 written=4 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.051..29.794 rows=72980 loops=1) Buffers: shared hit=1984 -> Sort (cost=1199032.19..1199041.44 rows=3702 width=12) (actual time=20867.420..20867.422 rows=1 loops=1) Sort Key: revenue29.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=795692 read=535942 written=533 -> Subquery Scan on revenue29 (cost=1198729.47..1198812.77 rows=3702 width=12) (actual time=20850.562..20867.386 rows=1 loops=1) Buffers: shared hit=795692 read=535942 written=533 -> HashAggregate (cost=1198729.47..1198775.75 rows=3702 width=12) (actual time=20850.560..20867.382 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=795692 read=535942 written=533 -> Bitmap Heap Scan on lineitem (cost=47436.69..1159365.36 rows=2249378 width=12) (actual time=1348.376..8663.376 rows=2249421 loops=1) Recheck Cond: ((l_shipdate >= '1993-09-01'::date) AND (l_shipdate < '1993-11-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=659676 Buffers: shared hit=395501 read=270316 written=363 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46874.35 rows=2249378 width=0) (actual time=1049.388..1049.388 rows=2273484 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=6141 written=6 Planning time: 4.223 ms Execution time: 20918.585 ms (38 rows) drop view revenue29; DROP VIEW COMMIT; COMMIT