BEGIN; BEGIN create or replace view revenue7 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1995-03-01' and l_shipdate < date'1995-03-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, revenue7 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue7 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2391339.76..2396437.68 rows=3764 width=79) (actual time=68800.517..68800.521 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue7.supplier_no) Buffers: shared hit=345733 read=992667 dirtied=504 written=28697 InitPlan 1 (returns $0) -> Aggregate (cost=1186968.43..1186968.44 rows=1 width=8) (actual time=35745.571..35745.571 rows=1 loops=1) Buffers: shared hit=280678 read=387163 written=22 -> HashAggregate (cost=1186883.74..1186921.38 rows=3764 width=12) (actual time=35666.106..35733.764 rows=100000 loops=1) Buffers: shared hit=280678 read=387163 written=22 -> Bitmap Heap Scan on lineitem (cost=48237.26..1163977.95 rows=2290579 width=12) (actual time=2416.980..30959.501 rows=2249613 loops=1) Recheck Cond: ((l_shipdate >= '1995-03-01'::date) AND (l_shipdate < '1995-05-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=280678 read=387163 written=22 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47664.62 rows=2290579 width=0) (actual time=2046.901..2046.901 rows=2281299 loops=1) Index Cond: ((l_shipdate >= '1995-03-01'::date) AND (l_shipdate < '1995-05-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=1 read=6145 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.149..117.836 rows=99913 loops=1) Buffers: shared hit=2717 -> Sort (cost=1204371.32..1204380.73 rows=3764 width=12) (actual time=68666.085..68666.086 rows=1 loops=1) Sort Key: revenue7.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=343016 read=992667 dirtied=504 written=28697 -> Subquery Scan on revenue7 (cost=1204063.08..1204147.77 rows=3764 width=12) (actual time=68657.268..68666.053 rows=1 loops=1) Buffers: shared hit=343016 read=992667 dirtied=504 written=28697 -> HashAggregate (cost=1204063.08..1204110.13 rows=3764 width=12) (actual time=68657.266..68666.050 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=343016 read=992667 dirtied=504 written=28697 -> Bitmap Heap Scan on lineitem (cost=48237.26..1163977.95 rows=2290579 width=12) (actual time=2616.279..27825.921 rows=2249613 loops=1) Recheck Cond: ((l_shipdate >= '1995-03-01'::date) AND (l_shipdate < '1995-05-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=62338 read=605504 dirtied=504 written=28675 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47664.62 rows=2290579 width=0) (actual time=2265.100..2265.100 rows=2281299 loops=1) Index Cond: ((l_shipdate >= '1995-03-01'::date) AND (l_shipdate < '1995-05-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=1150 read=4997 written=1411 Total runtime: 68816.236 ms (33 rows) drop view revenue7; DROP VIEW COMMIT; COMMIT