BEGIN; BEGIN create or replace view revenue19 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1997-07-01' and l_shipdate < date'1997-07-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, revenue19 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue19 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2363258.98..2368356.52 rows=3756 width=79) (actual time=18731.521..18731.526 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue19.supplier_no) Buffers: shared hit=1024650 read=297699 written=20 InitPlan 1 (returns $0) -> Aggregate (cost=1173045.07..1173045.08 rows=1 width=8) (actual time=9516.715..9516.715 rows=1 loops=1) Buffers: shared hit=486643 read=174038 -> HashAggregate (cost=1172960.56..1172998.12 rows=3756 width=12) (actual time=9432.817..9506.063 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=486643 read=174038 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47867.46..1150366.52 rows=2259404 width=12) (actual time=1788.348..7180.456 rows=2247022 loops=1) Recheck Cond: ((l_shipdate >= '1997-07-01'::date) AND (l_shipdate < '1997-09-29 00:00:00'::timestamp without time zone)) Heap Blocks: exact=654544 Buffers: shared hit=486643 read=174038 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47302.61 rows=2259404 width=0) (actual time=1387.975..1387.975 rows=2251572 loops=1) Index Cond: ((l_shipdate >= '1997-07-01'::date) AND (l_shipdate < '1997-09-29 00:00:00'::timestamp without time zone)) Buffers: shared hit=2 read=6135 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.048..16.280 rows=35977 loops=1) Buffers: shared hit=987 -> Sort (cost=1190213.61..1190223.00 rows=3756 width=12) (actual time=18711.542..18711.545 rows=1 loops=1) Sort Key: revenue19.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=1023663 read=297699 written=20 -> Subquery Scan on revenue19 (cost=1189906.09..1189990.60 rows=3756 width=12) (actual time=18678.483..18711.504 rows=1 loops=1) Buffers: shared hit=1023663 read=297699 written=20 -> HashAggregate (cost=1189906.09..1189953.04 rows=3756 width=12) (actual time=18678.482..18711.502 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=1023663 read=297699 written=20 -> Bitmap Heap Scan on lineitem (cost=47867.46..1150366.52 rows=2259404 width=12) (actual time=1961.453..7282.292 rows=2247022 loops=1) Recheck Cond: ((l_shipdate >= '1997-07-01'::date) AND (l_shipdate < '1997-09-29 00:00:00'::timestamp without time zone)) Heap Blocks: exact=654544 Buffers: shared hit=537020 read=123661 written=20 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47302.61 rows=2259404 width=0) (actual time=1549.462..1549.462 rows=2251572 loops=1) Index Cond: ((l_shipdate >= '1997-07-01'::date) AND (l_shipdate < '1997-09-29 00:00:00'::timestamp without time zone)) Buffers: shared hit=2 read=6135 Planning time: 2.922 ms Execution time: 18748.458 ms (38 rows) drop view revenue19; DROP VIEW COMMIT; COMMIT