BEGIN; BEGIN create or replace view revenue3 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-07-01' and l_shipdate < date'1994-07-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, revenue3 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue3 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2379810.10..2384907.50 rows=3729 width=79) (actual time=25799.280..25799.281 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue3.supplier_no) Buffers: shared hit=56150 read=1274856 dirtied=102 written=721 InitPlan 1 (returns $0) -> Aggregate (cost=1181325.24..1181325.25 rows=1 width=8) (actual time=12794.885..12794.885 rows=1 loops=1) Buffers: shared hit=14448 read=650942 -> HashAggregate (cost=1181241.33..1181278.62 rows=3729 width=12) (actual time=12727.840..12784.188 rows=100000 loops=1) Buffers: shared hit=14448 read=650942 -> Bitmap Heap Scan on lineitem (cost=47659.98..1158656.79 rows=2258454 width=12) (actual time=1658.507..9630.402 rows=2247450 loops=1) Recheck Cond: ((l_shipdate >= '1994-07-01'::date) AND (l_shipdate < '1994-09-29 00:00:00'::timestamp without time zone)) Buffers: shared hit=14448 read=650942 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47095.37 rows=2258454 width=0) (actual time=1351.019..1351.019 rows=2272582 loops=1) Index Cond: ((l_shipdate >= '1994-07-01'::date) AND (l_shipdate < '1994-09-29 00:00:00'::timestamp without time zone)) Buffers: shared hit=6145 read=1 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.074..3.653 rows=7995 loops=1) Buffers: shared hit=225 -> Sort (cost=1198484.86..1198494.18 rows=3729 width=12) (actual time=25794.794..25794.794 rows=1 loops=1) Sort Key: revenue3.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=55925 read=1274856 dirtied=102 written=721 -> Subquery Scan on revenue3 (cost=1198179.74..1198263.64 rows=3729 width=12) (actual time=25793.884..25794.762 rows=1 loops=1) Buffers: shared hit=55925 read=1274856 dirtied=102 written=721 -> HashAggregate (cost=1198179.74..1198226.35 rows=3729 width=12) (actual time=25793.882..25794.758 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=55925 read=1274856 dirtied=102 written=721 -> Bitmap Heap Scan on lineitem (cost=47659.98..1158656.79 rows=2258454 width=12) (actual time=1682.193..9961.288 rows=2247450 loops=1) Recheck Cond: ((l_shipdate >= '1994-07-01'::date) AND (l_shipdate < '1994-09-29 00:00:00'::timestamp without time zone)) Buffers: shared hit=41477 read=623914 dirtied=102 written=721 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47095.37 rows=2258454 width=0) (actual time=1302.560..1302.560 rows=2272582 loops=1) Index Cond: ((l_shipdate >= '1994-07-01'::date) AND (l_shipdate < '1994-09-29 00:00:00'::timestamp without time zone)) Buffers: shared read=6147 Total runtime: 25814.370 ms (33 rows) drop view revenue3; DROP VIEW COMMIT; COMMIT