BEGIN; BEGIN create or replace view revenue7 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1997-04-01' and l_shipdate < date'1997-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, revenue7 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue7 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2387206.99..2392305.25 rows=3804 width=79) (actual time=18323.257..18323.262 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue7.supplier_no) Buffers: shared hit=623740 read=709679 written=11912 InitPlan 1 (returns $0) -> Aggregate (cost=1184821.00..1184821.01 rows=1 width=8) (actual time=8927.447..8927.447 rows=1 loops=1) Buffers: shared hit=273950 read=392467 written=7227 -> HashAggregate (cost=1184735.41..1184773.45 rows=3804 width=12) (actual time=8881.181..8917.015 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=273950 read=392467 written=7227 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=48752.48..1161617.44 rows=2311797 width=12) (actual time=1229.100..7032.018 rows=2247859 loops=1) Recheck Cond: ((l_shipdate >= '1997-04-01'::date) AND (l_shipdate < '1997-06-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=660274 Buffers: shared hit=273950 read=392467 written=7227 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..48174.54 rows=2311797 width=0) (actual time=949.851..949.851 rows=2276210 loops=1) Index Cond: ((l_shipdate >= '1997-04-01'::date) AND (l_shipdate < '1997-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=785 read=5358 written=424 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.027..8.363 rows=20927 loops=1) Buffers: shared hit=585 -> Sort (cost=1202385.69..1202395.20 rows=3804 width=12) (actual time=18312.803..18312.805 rows=1 loops=1) Sort Key: revenue7.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=623155 read=709679 written=11912 -> Subquery Scan on revenue7 (cost=1202073.89..1202159.48 rows=3804 width=12) (actual time=18307.983..18312.773 rows=1 loops=1) Buffers: shared hit=623155 read=709679 written=11912 -> HashAggregate (cost=1202073.89..1202121.44 rows=3804 width=12) (actual time=18307.982..18312.771 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=623155 read=709679 written=11912 -> Bitmap Heap Scan on lineitem (cost=48752.48..1161617.44 rows=2311797 width=12) (actual time=1332.469..7467.059 rows=2247859 loops=1) Recheck Cond: ((l_shipdate >= '1997-04-01'::date) AND (l_shipdate < '1997-06-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=660274 Buffers: shared hit=349205 read=317212 written=4685 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..48174.54 rows=2311797 width=0) (actual time=1016.684..1016.684 rows=2274260 loops=1) Index Cond: ((l_shipdate >= '1997-04-01'::date) AND (l_shipdate < '1997-06-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6143 Planning time: 2.611 ms Execution time: 18335.216 ms (38 rows) drop view revenue7; DROP VIEW COMMIT; COMMIT