BEGIN; BEGIN create or replace view revenue23 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1997-08-01' and l_shipdate < date'1997-08-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, revenue23 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue23 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2361054.82..2366151.74 rows=3715 width=79) (actual time=22389.160..22389.162 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue23.supplier_no) Buffers: shared hit=807967 read=512481 written=50 InitPlan 1 (returns $0) -> Aggregate (cost=1172027.02..1172027.03 rows=1 width=8) (actual time=10709.812..10709.812 rows=1 loops=1) Buffers: shared hit=431395 read=228814 -> HashAggregate (cost=1171943.43..1171980.58 rows=3715 width=12) (actual time=10664.421..10698.757 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=431395 read=228814 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47401.48..1149569.85 rows=2237358 width=12) (actual time=1547.449..8267.582 rows=2245417 loops=1) Recheck Cond: ((l_shipdate >= '1997-08-01'::date) AND (l_shipdate < '1997-10-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=654076 Buffers: shared hit=431395 read=228814 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46842.15 rows=2237358 width=0) (actual time=1166.735..1166.735 rows=2249914 loops=1) Index Cond: ((l_shipdate >= '1997-08-01'::date) AND (l_shipdate < '1997-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=1 read=6132 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.047..0.440 rows=973 loops=1) Buffers: shared hit=30 -> Sort (cost=1189027.49..1189036.78 rows=3715 width=12) (actual time=22388.587..22388.587 rows=1 loops=1) Sort Key: revenue23.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=807937 read=512481 written=50 -> Subquery Scan on revenue23 (cost=1188723.62..1188807.21 rows=3715 width=12) (actual time=22378.382..22388.551 rows=1 loops=1) Buffers: shared hit=807937 read=512481 written=50 -> HashAggregate (cost=1188723.62..1188770.06 rows=3715 width=12) (actual time=22378.381..22388.549 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=807937 read=512481 written=50 -> Bitmap Heap Scan on lineitem (cost=47401.48..1149569.85 rows=2237358 width=12) (actual time=1644.200..9519.684 rows=2245417 loops=1) Recheck Cond: ((l_shipdate >= '1997-08-01'::date) AND (l_shipdate < '1997-10-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=654076 Buffers: shared hit=376542 read=283667 written=50 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46842.15 rows=2237358 width=0) (actual time=1250.713..1250.713 rows=2249914 loops=1) Index Cond: ((l_shipdate >= '1997-08-01'::date) AND (l_shipdate < '1997-10-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6133 Planning time: 4.129 ms Execution time: 22397.671 ms (38 rows) drop view revenue23; DROP VIEW COMMIT; COMMIT