BEGIN; BEGIN create or replace view revenue4 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1997-05-01' and l_shipdate < date'1997-05-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, revenue4 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue4 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2365223.38..2370321.45 rows=3791 width=79) (actual time=23713.137..23713.144 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue4.supplier_no) Buffers: shared hit=775961 read=545483 dirtied=372 written=1496 InitPlan 1 (returns $0) -> Aggregate (cost=1173938.39..1173938.40 rows=1 width=8) (actual time=12737.964..12737.964 rows=1 loops=1) Buffers: shared hit=300161 read=360080 written=63 -> HashAggregate (cost=1173853.09..1173891.00 rows=3791 width=12) (actual time=12647.426..12727.293 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=300161 read=360080 written=63 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=48367.21..1151025.14 rows=2282795 width=12) (actual time=1211.961..9117.444 rows=2245771 loops=1) Recheck Cond: ((l_shipdate >= '1997-05-01'::date) AND (l_shipdate < '1997-07-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=654101 Buffers: shared hit=300161 read=360080 written=63 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47796.51 rows=2282795 width=0) (actual time=945.356..945.356 rows=2252515 loops=1) Index Cond: ((l_shipdate >= '1997-05-01'::date) AND (l_shipdate < '1997-07-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6140 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.039..15.027 rows=34927 loops=1) Buffers: shared hit=962 -> Sort (cost=1191284.69..1191294.17 rows=3791 width=12) (actual time=23694.472..23694.475 rows=1 loops=1) Sort Key: revenue4.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=774999 read=545483 dirtied=372 written=1496 -> Subquery Scan on revenue4 (cost=1190974.05..1191059.35 rows=3791 width=12) (actual time=23665.719..23694.435 rows=1 loops=1) Buffers: shared hit=774999 read=545483 dirtied=372 written=1496 -> HashAggregate (cost=1190974.05..1191021.44 rows=3791 width=12) (actual time=23665.717..23694.430 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=774999 read=545483 dirtied=372 written=1496 -> Bitmap Heap Scan on lineitem (cost=48367.21..1151025.14 rows=2282795 width=12) (actual time=1896.300..8770.069 rows=2245771 loops=1) Recheck Cond: ((l_shipdate >= '1997-05-01'::date) AND (l_shipdate < '1997-07-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=654101 Buffers: shared hit=474838 read=185403 dirtied=372 written=1433 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47796.51 rows=2282795 width=0) (actual time=1235.073..1235.073 rows=2252225 loops=1) Index Cond: ((l_shipdate >= '1997-05-01'::date) AND (l_shipdate < '1997-07-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=283 read=5857 written=169 Planning time: 3.134 ms Execution time: 23727.908 ms (38 rows) drop view revenue4; DROP VIEW COMMIT; COMMIT