BEGIN; BEGIN create or replace view revenue20 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-04-01' and l_shipdate < date'1994-04-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, revenue20 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue20 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2358316.87..2363413.92 rows=3723 width=79) (actual time=15169.339..15169.343 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue20.supplier_no) Buffers: shared hit=971469 read=347166 written=3033 InitPlan 1 (returns $0) -> Aggregate (cost=1170655.61..1170655.62 rows=1 width=8) (actual time=7906.170..7906.170 rows=1 loops=1) Buffers: shared hit=396604 read=262153 written=28 -> HashAggregate (cost=1170571.84..1170609.07 rows=3723 width=12) (actual time=7863.331..7895.942 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=396604 read=262153 written=28 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47447.42..1148192.47 rows=2237937 width=12) (actual time=1153.126..5989.939 rows=2243279 loops=1) Recheck Cond: ((l_shipdate >= '1994-04-01'::date) AND (l_shipdate < '1994-06-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=652623 Buffers: shared hit=396604 read=262153 written=28 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46887.93 rows=2237937 width=0) (actual time=898.329..898.329 rows=2247936 loops=1) Index Cond: ((l_shipdate >= '1994-04-01'::date) AND (l_shipdate < '1994-06-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6134 written=2 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.028..14.169 rows=40970 loops=1) Buffers: shared hit=1121 -> Sort (cost=1187660.96..1187670.26 rows=3723 width=12) (actual time=15151.246..15151.249 rows=1 loops=1) Sort Key: revenue20.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=970348 read=347166 written=3033 -> Subquery Scan on revenue20 (cost=1187356.37..1187440.14 rows=3723 width=12) (actual time=15143.856..15151.213 rows=1 loops=1) Buffers: shared hit=970348 read=347166 written=3033 -> HashAggregate (cost=1187356.37..1187402.91 rows=3723 width=12) (actual time=15143.854..15151.209 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=970348 read=347166 written=3033 -> Bitmap Heap Scan on lineitem (cost=47447.42..1148192.47 rows=2237937 width=12) (actual time=1227.161..5397.739 rows=2243279 loops=1) Recheck Cond: ((l_shipdate >= '1994-04-01'::date) AND (l_shipdate < '1994-06-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=652623 Buffers: shared hit=573744 read=85013 written=3005 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46887.93 rows=2237937 width=0) (actual time=963.208..963.208 rows=2247265 loops=1) Index Cond: ((l_shipdate >= '1994-04-01'::date) AND (l_shipdate < '1994-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=383 read=5751 written=194 Planning time: 2.615 ms Execution time: 15175.363 ms (38 rows) drop view revenue20; DROP VIEW COMMIT; COMMIT