BEGIN; BEGIN create or replace view revenue15 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-02-01' and l_shipdate < date'1994-02-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, revenue15 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue15 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2379417.33..2384515.03 rows=3749 width=79) (actual time=35678.735..35678.737 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue15.supplier_no) Buffers: shared hit=378751 read=948447 written=8044 InitPlan 1 (returns $0) -> Aggregate (cost=1181063.91..1181063.92 rows=1 width=8) (actual time=20289.005..20289.005 rows=1 loops=1) Buffers: shared hit=65275 read=598211 written=16 -> HashAggregate (cost=1180979.55..1181017.04 rows=3749 width=12) (actual time=20189.021..20272.051 rows=100000 loops=1) Buffers: shared hit=65275 read=598211 written=16 -> Bitmap Heap Scan on lineitem (cost=48043.68..1158223.60 rows=2275595 width=12) (actual time=2497.352..16015.529 rows=2244961 loops=1) Recheck Cond: ((l_shipdate >= '1994-02-01'::date) AND (l_shipdate < '1994-05-02 00:00:00'::timestamp without time zone)) Buffers: shared hit=65275 read=598211 written=16 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47474.78 rows=2275595 width=0) (actual time=2024.765..2024.765 rows=2265162 loops=1) Index Cond: ((l_shipdate >= '1994-02-01'::date) AND (l_shipdate < '1994-05-02 00:00:00'::timestamp without time zone)) Buffers: shared hit=2 read=6129 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.076..5.427 rows=8001 loops=1) Buffers: shared hit=224 read=1 -> Sort (cost=1198353.41..1198362.79 rows=3749 width=12) (actual time=35671.957..35671.957 rows=1 loops=1) Sort Key: revenue15.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=378527 read=948446 written=8044 -> Subquery Scan on revenue15 (cost=1198046.52..1198130.87 rows=3749 width=12) (actual time=35655.483..35671.920 rows=1 loops=1) Buffers: shared hit=378527 read=948446 written=8044 -> HashAggregate (cost=1198046.52..1198093.38 rows=3749 width=12) (actual time=35655.481..35671.916 rows=1 loops=1) Filter: (sum((public.lineitem.l_extendedprice * (1::double precision - public.lineitem.l_discount))) = $0) Rows Removed by Filter: 99999 Buffers: shared hit=378527 read=948446 written=8044 -> Bitmap Heap Scan on lineitem (cost=48043.68..1158223.60 rows=2275595 width=12) (actual time=1640.530..11568.661 rows=2244961 loops=1) Recheck Cond: ((l_shipdate >= '1994-02-01'::date) AND (l_shipdate < '1994-05-02 00:00:00'::timestamp without time zone)) Buffers: shared hit=313252 read=350235 written=8028 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47474.78 rows=2275595 width=0) (actual time=1252.595..1252.595 rows=2265162 loops=1) Index Cond: ((l_shipdate >= '1994-02-01'::date) AND (l_shipdate < '1994-05-02 00:00:00'::timestamp without time zone)) Buffers: shared hit=947 read=5185 written=3152 Total runtime: 35698.144 ms (33 rows) drop view revenue15; DROP VIEW COMMIT; COMMIT