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-01-01' and l_shipdate < date'1996-01-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=2377294.13..2382392.64 rows=3803 width=79) (actual time=33322.207..33322.210 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue1.supplier_no) Buffers: shared hit=282886 read=1044760 dirtied=681 written=14103 InitPlan 1 (returns $0) -> Aggregate (cost=1179924.41..1179924.42 rows=1 width=8) (actual time=15021.248..15021.248 rows=1 loops=1) Buffers: shared hit=176169 read=486700 dirtied=681 written=13902 -> HashAggregate (cost=1179838.85..1179876.88 rows=3803 width=12) (actual time=14940.463..15009.746 rows=100000 loops=1) Buffers: shared hit=176169 read=486700 dirtied=681 written=13902 -> Bitmap Heap Scan on lineitem (cost=48523.67..1156879.98 rows=2295887 width=12) (actual time=1608.196..11226.316 rows=2242956 loops=1) Recheck Cond: ((l_shipdate >= '1996-01-01'::date) AND (l_shipdate < '1996-03-31 00:00:00'::timestamp without time zone)) Buffers: shared hit=176169 read=486700 dirtied=681 written=13902 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47949.70 rows=2295887 width=0) (actual time=1184.081..1184.081 rows=2258483 loops=1) Index Cond: ((l_shipdate >= '1996-01-01'::date) AND (l_shipdate < '1996-03-31 00:00:00'::timestamp without time zone)) Buffers: shared read=6127 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.078..29.231 rows=69999 loops=1) Buffers: shared hit=1906 read=1 -> Sort (cost=1197369.71..1197379.22 rows=3803 width=12) (actual time=33285.639..33285.640 rows=1 loops=1) Sort Key: revenue1.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=280980 read=1044759 dirtied=681 written=14103 -> Subquery Scan on revenue1 (cost=1197058.00..1197143.57 rows=3803 width=12) (actual time=33257.018..33285.605 rows=1 loops=1) Buffers: shared hit=280980 read=1044759 dirtied=681 written=14103 -> HashAggregate (cost=1197058.00..1197105.54 rows=3803 width=12) (actual time=33257.016..33285.600 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=280980 read=1044759 dirtied=681 written=14103 -> Bitmap Heap Scan on lineitem (cost=48523.67..1156879.98 rows=2295887 width=12) (actual time=2243.928..14171.349 rows=2242956 loops=1) Recheck Cond: ((l_shipdate >= '1996-01-01'::date) AND (l_shipdate < '1996-03-31 00:00:00'::timestamp without time zone)) Buffers: shared hit=104811 read=558059 written=201 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47949.70 rows=2295887 width=0) (actual time=1831.459..1831.459 rows=2258483 loops=1) Index Cond: ((l_shipdate >= '1996-01-01'::date) AND (l_shipdate < '1996-03-31 00:00:00'::timestamp without time zone)) Buffers: shared read=6128 Total runtime: 33334.056 ms (33 rows) drop view revenue1; DROP VIEW COMMIT; COMMIT