BEGIN; BEGIN create or replace view revenue3 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-08-01' and l_shipdate < date'1994-08-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, revenue3 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue3 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2381316.25..2386414.27 rows=3770 width=79) (actual time=73029.374..73029.376 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue3.supplier_no) Buffers: shared hit=408861 read=921861 written=11689 InitPlan 1 (returns $0) -> Aggregate (cost=1181980.91..1181980.92 rows=1 width=8) (actual time=31597.224..31597.224 rows=1 loops=1) Buffers: shared hit=256396 read=408309 written=37 -> HashAggregate (cost=1181896.09..1181933.79 rows=3770 width=12) (actual time=31515.680..31584.587 rows=100000 loops=1) Buffers: shared hit=256396 read=408309 written=37 -> Bitmap Heap Scan on lineitem (cost=48210.49..1159055.45 rows=2284064 width=12) (actual time=2559.793..26979.230 rows=2245331 loops=1) Recheck Cond: ((l_shipdate >= '1994-08-01'::date) AND (l_shipdate < '1994-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=256396 read=408309 written=37 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47639.47 rows=2284064 width=0) (actual time=2175.093..2175.093 rows=2270203 loops=1) Index Cond: ((l_shipdate >= '1994-08-01'::date) AND (l_shipdate < '1994-10-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6140 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.075..56.601 rows=47970 loops=1) Buffers: shared hit=1311 -> Sort (cost=1199335.33..1199344.76 rows=3770 width=12) (actual time=72964.442..72964.443 rows=1 loops=1) Sort Key: revenue3.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=407550 read=921861 written=11689 -> Subquery Scan on revenue3 (cost=1199026.57..1199111.39 rows=3770 width=12) (actual time=72961.778..72964.408 rows=1 loops=1) Buffers: shared hit=407550 read=921861 written=11689 -> HashAggregate (cost=1199026.57..1199073.69 rows=3770 width=12) (actual time=72961.775..72964.403 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=407550 read=921861 written=11689 -> Bitmap Heap Scan on lineitem (cost=48210.49..1159055.45 rows=2284064 width=12) (actual time=2800.189..36404.310 rows=2245331 loops=1) Recheck Cond: ((l_shipdate >= '1994-08-01'::date) AND (l_shipdate < '1994-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=151154 read=513552 written=11652 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47639.47 rows=2284064 width=0) (actual time=2372.443..2372.443 rows=2269206 loops=1) Index Cond: ((l_shipdate >= '1994-08-01'::date) AND (l_shipdate < '1994-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=514 read=5627 written=426 Total runtime: 73042.417 ms (33 rows) drop view revenue3; DROP VIEW COMMIT; COMMIT