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 >= '1995-04-01' and l_shipdate < date'1995-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=2359714.10..2364811.63 rows=3755 width=79) (actual time=16371.198..16371.207 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue20.supplier_no) Buffers: shared hit=1017581 read=302516 dirtied=1 written=2547 InitPlan 1 (returns $0) -> Aggregate (cost=1171288.18..1171288.19 rows=1 width=8) (actual time=8121.445..8121.445 rows=1 loops=1) Buffers: shared hit=418026 read=240895 written=134 -> HashAggregate (cost=1171203.69..1171241.24 rows=3755 width=12) (actual time=8071.733..8111.225 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=418026 read=240895 written=134 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47817.04..1148651.03 rows=2255266 width=12) (actual time=1191.675..6083.605 rows=2246122 loops=1) Recheck Cond: ((l_shipdate >= '1995-04-01'::date) AND (l_shipdate < '1995-06-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=652780 Buffers: shared hit=418026 read=240895 written=134 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47253.23 rows=2255266 width=0) (actual time=930.541..930.541 rows=2250533 loops=1) Index Cond: ((l_shipdate >= '1995-04-01'::date) AND (l_shipdate < '1995-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=1 read=6140 written=32 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.042..32.466 rows=82932 loops=1) Buffers: shared hit=2255 -> Sort (cost=1188425.62..1188435.01 rows=3755 width=12) (actual time=16330.600..16330.603 rows=1 loops=1) Sort Key: revenue20.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=1015326 read=302516 dirtied=1 written=2547 -> Subquery Scan on revenue20 (cost=1188118.19..1188202.67 rows=3755 width=12) (actual time=16325.772..16330.567 rows=1 loops=1) Buffers: shared hit=1015326 read=302516 dirtied=1 written=2547 -> HashAggregate (cost=1188118.19..1188165.12 rows=3755 width=12) (actual time=16325.770..16330.562 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=1015326 read=302516 dirtied=1 written=2547 -> Bitmap Heap Scan on lineitem (cost=47817.04..1148651.03 rows=2255266 width=12) (actual time=1991.115..6378.550 rows=2246122 loops=1) Recheck Cond: ((l_shipdate >= '1995-04-01'::date) AND (l_shipdate < '1995-06-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=652780 Buffers: shared hit=597300 read=61621 dirtied=1 written=2413 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47253.23 rows=2255266 width=0) (actual time=1630.654..1630.654 rows=2249652 loops=1) Index Cond: ((l_shipdate >= '1995-04-01'::date) AND (l_shipdate < '1995-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=386 read=5755 written=165 Planning time: 2.797 ms Execution time: 16380.287 ms (38 rows) drop view revenue20; DROP VIEW COMMIT; COMMIT