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 >= '1996-07-01' and l_shipdate < date'1996-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, revenue7 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue7 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2374433.01..2379529.84 rows=3709 width=79) (actual time=16967.736..16967.739 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue7.supplier_no) Buffers: shared hit=617051 read=711080 written=461 InitPlan 1 (returns $0) -> Aggregate (cost=1178681.18..1178681.19 rows=1 width=8) (actual time=8138.488..8138.488 rows=1 loops=1) Buffers: shared hit=284228 read=379006 -> HashAggregate (cost=1178597.73..1178634.82 rows=3709 width=12) (actual time=8103.528..8129.114 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=284228 read=379006 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47453.53..1156130.45 rows=2246728 width=12) (actual time=1072.775..6499.702 rows=2243666 loops=1) Recheck Cond: ((l_shipdate >= '1996-07-01'::date) AND (l_shipdate < '1996-09-29 00:00:00'::timestamp without time zone)) Heap Blocks: exact=657100 Buffers: shared hit=284228 read=379006 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46891.85 rows=2246728 width=0) (actual time=797.156..797.156 rows=2263668 loops=1) Index Cond: ((l_shipdate >= '1996-07-01'::date) AND (l_shipdate < '1996-09-29 00:00:00'::timestamp without time zone)) Buffers: shared read=6134 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.039..23.689 rows=60982 loops=1) Buffers: shared hit=1663 -> Sort (cost=1195751.52..1195760.80 rows=3709 width=12) (actual time=16938.401..16938.402 rows=1 loops=1) Sort Key: revenue7.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=615388 read=711080 written=461 -> Subquery Scan on revenue7 (cost=1195448.19..1195531.64 rows=3709 width=12) (actual time=16921.068..16938.374 rows=1 loops=1) Buffers: shared hit=615388 read=711080 written=461 -> HashAggregate (cost=1195448.19..1195494.55 rows=3709 width=12) (actual time=16921.066..16938.370 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=615388 read=711080 written=461 -> Bitmap Heap Scan on lineitem (cost=47453.53..1156130.45 rows=2246728 width=12) (actual time=1060.475..7120.892 rows=2243666 loops=1) Recheck Cond: ((l_shipdate >= '1996-07-01'::date) AND (l_shipdate < '1996-09-29 00:00:00'::timestamp without time zone)) Heap Blocks: exact=657100 Buffers: shared hit=331160 read=332074 written=461 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46891.85 rows=2246728 width=0) (actual time=815.481..815.481 rows=2263668 loops=1) Index Cond: ((l_shipdate >= '1996-07-01'::date) AND (l_shipdate < '1996-09-29 00:00:00'::timestamp without time zone)) Buffers: shared read=6134 written=19 Planning time: 2.659 ms Execution time: 16981.556 ms (38 rows) drop view revenue7; DROP VIEW COMMIT; COMMIT