BEGIN; BEGIN create or replace view revenue5 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-10-01' and l_shipdate < date'1994-10-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, revenue5 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue5 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2363124.62..2368222.45 rows=3758 width=79) (actual time=24874.382..24874.386 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue5.supplier_no) Buffers: shared hit=736484 read=584280 written=159 InitPlan 1 (returns $0) -> Aggregate (cost=1172983.49..1172983.50 rows=1 width=8) (actual time=11971.993..11971.993 rows=1 loops=1) Buffers: shared hit=313558 read=346626 written=43 -> HashAggregate (cost=1172898.93..1172936.51 rows=3758 width=12) (actual time=11892.743..11961.069 rows=100000 loops=1) Buffers: shared hit=313558 read=346626 written=43 -> Bitmap Heap Scan on lineitem (cost=47842.63..1150319.61 rows=2257932 width=12) (actual time=1891.979..8640.370 rows=2243920 loops=1) Recheck Cond: ((l_shipdate >= '1994-10-01'::date) AND (l_shipdate < '1994-12-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=313558 read=346626 written=43 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47278.15 rows=2257932 width=0) (actual time=1513.110..1513.110 rows=2248402 loops=1) Index Cond: ((l_shipdate >= '1994-10-01'::date) AND (l_shipdate < '1994-12-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6129 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.095..5.653 rows=13954 loops=1) Buffers: shared hit=394 read=1 -> Sort (cost=1190141.12..1190150.52 rows=3758 width=12) (actual time=24867.234..24867.236 rows=1 loops=1) Sort Key: revenue5.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=736090 read=584279 written=159 -> Subquery Scan on revenue5 (cost=1189833.42..1189917.98 rows=3758 width=12) (actual time=24820.659..24867.196 rows=1 loops=1) Buffers: shared hit=736090 read=584279 written=159 -> HashAggregate (cost=1189833.42..1189880.40 rows=3758 width=12) (actual time=24820.657..24867.192 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=736090 read=584279 written=159 -> Bitmap Heap Scan on lineitem (cost=47842.63..1150319.61 rows=2257932 width=12) (actual time=2281.215..9393.329 rows=2243920 loops=1) Recheck Cond: ((l_shipdate >= '1994-10-01'::date) AND (l_shipdate < '1994-12-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=422532 read=237653 written=116 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47278.15 rows=2257932 width=0) (actual time=1881.376..1881.376 rows=2248402 loops=1) Index Cond: ((l_shipdate >= '1994-10-01'::date) AND (l_shipdate < '1994-12-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6130 Total runtime: 24889.118 ms (33 rows) drop view revenue5; DROP VIEW COMMIT; COMMIT