BEGIN; BEGIN create or replace view revenue18 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-05-01' and l_shipdate < date'1994-05-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, revenue18 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue18 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2386083.76..2391180.94 rows=3715 width=79) (actual time=60542.495..60542.501 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue18.supplier_no) Buffers: shared hit=753055 read=583483 written=205 InitPlan 1 (returns $0) -> Aggregate (cost=1184461.51..1184461.52 rows=1 width=8) (actual time=32550.562..32550.562 rows=1 loops=1) Buffers: shared hit=352492 read=314797 written=47 -> HashAggregate (cost=1184377.92..1184415.07 rows=3715 width=12) (actual time=32474.877..32538.032 rows=100000 loops=1) Buffers: shared hit=352492 read=314797 written=47 -> Bitmap Heap Scan on lineitem (cost=47590.77..1161790.66 rows=2258726 width=12) (actual time=2488.220..27921.373 rows=2247373 loops=1) Recheck Cond: ((l_shipdate >= '1994-05-01'::date) AND (l_shipdate < '1994-07-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=352492 read=314797 written=47 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47026.09 rows=2258726 width=0) (actual time=1976.157..1976.157 rows=2276624 loops=1) Index Cond: ((l_shipdate >= '1994-05-01'::date) AND (l_shipdate < '1994-07-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=3727 read=2411 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.093..32.997 rows=71902 loops=1) Buffers: shared hit=1958 read=1 -> Sort (cost=1201622.24..1201631.52 rows=3715 width=12) (actual time=60501.175..60501.178 rows=1 loops=1) Sort Key: revenue18.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=751097 read=583482 written=205 -> Subquery Scan on revenue18 (cost=1201318.37..1201401.95 rows=3715 width=12) (actual time=60484.603..60501.131 rows=1 loops=1) Buffers: shared hit=751097 read=583482 written=205 -> HashAggregate (cost=1201318.37..1201364.80 rows=3715 width=12) (actual time=60484.601..60501.127 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=751097 read=583482 written=205 -> Bitmap Heap Scan on lineitem (cost=47590.77..1161790.66 rows=2258726 width=12) (actual time=2584.025..23597.051 rows=2247373 loops=1) Recheck Cond: ((l_shipdate >= '1994-05-01'::date) AND (l_shipdate < '1994-07-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=398605 read=268685 written=158 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47026.09 rows=2258726 width=0) (actual time=2183.162..2183.162 rows=2276624 loops=1) Index Cond: ((l_shipdate >= '1994-05-01'::date) AND (l_shipdate < '1994-07-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6139 Total runtime: 60556.986 ms (33 rows) drop view revenue18; DROP VIEW COMMIT; COMMIT