BEGIN; BEGIN create or replace view revenue1 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1996-12-01' and l_shipdate < date'1996-12-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, revenue1 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue1 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2375813.93..2380911.87 rows=3765 width=79) (actual time=37314.647..37314.648 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue1.supplier_no) Buffers: shared hit=577911 read=749044 written=44441 InitPlan 1 (returns $0) -> Aggregate (cost=1179241.15..1179241.16 rows=1 width=8) (actual time=17524.236..17524.236 rows=1 loops=1) Buffers: shared hit=297234 read=366091 written=527 -> HashAggregate (cost=1179156.44..1179194.09 rows=3765 width=12) (actual time=17468.461..17512.905 rows=100000 loops=1) Buffers: shared hit=297234 read=366091 written=527 -> Bitmap Heap Scan on lineitem (cost=48211.77..1156345.77 rows=2281067 width=12) (actual time=1980.265..13351.289 rows=2243711 loops=1) Recheck Cond: ((l_shipdate >= '1996-12-01'::date) AND (l_shipdate < '1997-03-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=297234 read=366091 written=527 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47641.50 rows=2281067 width=0) (actual time=1501.916..1501.916 rows=2263846 loops=1) Index Cond: ((l_shipdate >= '1996-12-01'::date) AND (l_shipdate < '1997-03-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=72 read=6064 written=84 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.097..6.601 rows=10906 loops=1) Buffers: shared hit=303 read=1 -> Sort (cost=1196572.77..1196582.18 rows=3765 width=12) (actual time=37306.657..37306.657 rows=1 loops=1) Sort Key: revenue1.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=577608 read=749043 written=44441 -> Subquery Scan on revenue1 (cost=1196264.44..1196349.16 rows=3765 width=12) (actual time=37279.300..37306.627 rows=1 loops=1) Buffers: shared hit=577608 read=749043 written=44441 -> HashAggregate (cost=1196264.44..1196311.51 rows=3765 width=12) (actual time=37279.298..37306.624 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=577608 read=749043 written=44441 -> Bitmap Heap Scan on lineitem (cost=48211.77..1156345.77 rows=2281067 width=12) (actual time=3185.146..15663.172 rows=2243711 loops=1) Recheck Cond: ((l_shipdate >= '1996-12-01'::date) AND (l_shipdate < '1997-03-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=280374 read=382952 written=43914 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47641.50 rows=2281067 width=0) (actual time=1632.685..1632.685 rows=2261649 loops=1) Index Cond: ((l_shipdate >= '1996-12-01'::date) AND (l_shipdate < '1997-03-01 00:00:00'::timestamp without time zone)) Buffers: shared read=6137 Total runtime: 37332.997 ms (33 rows) drop view revenue1; DROP VIEW COMMIT; COMMIT