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 >= '1997-06-01' and l_shipdate < date'1997-06-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=2367138.58..2372237.05 rows=3818 width=79) (actual time=19592.581..19592.586 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue8.supplier_no) Buffers: shared hit=837983 read=483793 written=2 InitPlan 1 (returns $0) -> Aggregate (cost=1174837.39..1174837.40 rows=1 width=8) (actual time=8899.387..8899.387 rows=1 loops=1) Buffers: shared hit=410344 read=249955 -> HashAggregate (cost=1174751.48..1174789.66 rows=3818 width=12) (actual time=8852.778..8888.563 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=410344 read=249955 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=48688.93..1151769.66 rows=2298182 width=12) (actual time=1209.709..6896.565 rows=2246170 loops=1) Recheck Cond: ((l_shipdate >= '1997-06-01'::date) AND (l_shipdate < '1997-08-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=654165 Buffers: shared hit=410344 read=249955 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..48114.39 rows=2298182 width=0) (actual time=935.944..935.944 rows=2250638 loops=1) Index Cond: ((l_shipdate >= '1997-06-01'::date) AND (l_shipdate < '1997-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=2 read=6132 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.032..14.407 rows=42993 loops=1) Buffers: shared hit=1178 -> Sort (cost=1192300.89..1192310.44 rows=3818 width=12) (actual time=19573.764..19573.766 rows=1 loops=1) Sort Key: revenue8.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=836805 read=483793 written=2 -> Subquery Scan on revenue8 (cost=1191987.85..1192073.75 rows=3818 width=12) (actual time=19560.549..19573.730 rows=1 loops=1) Buffers: shared hit=836805 read=483793 written=2 -> HashAggregate (cost=1191987.85..1192035.57 rows=3818 width=12) (actual time=19560.547..19573.724 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=836805 read=483793 written=2 -> Bitmap Heap Scan on lineitem (cost=48688.93..1151769.66 rows=2298182 width=12) (actual time=1804.705..8230.309 rows=2246170 loops=1) Recheck Cond: ((l_shipdate >= '1997-06-01'::date) AND (l_shipdate < '1997-08-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=654165 Buffers: shared hit=426461 read=233838 written=2 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..48114.39 rows=2298182 width=0) (actual time=1407.585..1407.585 rows=2250638 loops=1) Index Cond: ((l_shipdate >= '1997-06-01'::date) AND (l_shipdate < '1997-08-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6134 Planning time: 2.796 ms Execution time: 19603.874 ms (38 rows) drop view revenue8; DROP VIEW COMMIT; COMMIT