BEGIN; BEGIN create or replace view revenue8 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1993-02-01' and l_shipdate < date'1993-02-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, revenue8 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue8 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2361387.61..2366484.63 rows=3721 width=79) (actual time=23814.471..23814.478 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue8.supplier_no) Buffers: shared hit=743601 read=578161 written=46 InitPlan 1 (returns $0) -> Aggregate (cost=1172180.72..1172180.73 rows=1 width=8) (actual time=10708.757..10708.757 rows=1 loops=1) Buffers: shared hit=392640 read=267505 -> HashAggregate (cost=1172096.99..1172134.20 rows=3721 width=12) (actual time=10664.393..10697.776 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=392640 read=267505 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47471.67..1149690.06 rows=2240693 width=12) (actual time=1231.373..8377.346 rows=2250345 loops=1) Recheck Cond: ((l_shipdate >= '1993-02-01'::date) AND (l_shipdate < '1993-05-02 00:00:00'::timestamp without time zone)) Heap Blocks: exact=653999 Buffers: shared hit=392640 read=267505 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46911.50 rows=2240693 width=0) (actual time=958.495..958.495 rows=2254695 loops=1) Index Cond: ((l_shipdate >= '1993-02-01'::date) AND (l_shipdate < '1993-05-02 00:00:00'::timestamp without time zone)) Buffers: shared read=6146 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.048..24.361 rows=53897 loops=1) Buffers: shared hit=1472 -> Sort (cost=1189206.60..1189215.90 rows=3721 width=12) (actual time=23784.011..23784.014 rows=1 loops=1) Sort Key: revenue8.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=742129 read=578161 written=46 -> Subquery Scan on revenue8 (cost=1188902.19..1188985.91 rows=3721 width=12) (actual time=23742.080..23783.975 rows=1 loops=1) Buffers: shared hit=742129 read=578161 written=46 -> HashAggregate (cost=1188902.19..1188948.70 rows=3721 width=12) (actual time=23742.078..23783.971 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=742129 read=578161 written=46 -> Bitmap Heap Scan on lineitem (cost=47471.67..1149690.06 rows=2240693 width=12) (actual time=1596.651..10075.171 rows=2250345 loops=1) Recheck Cond: ((l_shipdate >= '1993-02-01'::date) AND (l_shipdate < '1993-05-02 00:00:00'::timestamp without time zone)) Heap Blocks: exact=653999 Buffers: shared hit=349489 read=310656 written=46 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46911.50 rows=2240693 width=0) (actual time=1228.327..1228.327 rows=2254695 loops=1) Index Cond: ((l_shipdate >= '1993-02-01'::date) AND (l_shipdate < '1993-05-02 00:00:00'::timestamp without time zone)) Buffers: shared read=6146 Planning time: 4.986 ms Execution time: 23823.913 ms (38 rows) drop view revenue8; DROP VIEW COMMIT; COMMIT