BEGIN; BEGIN create or replace view revenue14 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1995-07-01' and l_shipdate < date'1995-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, revenue14 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue14 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2377123.53..2382221.42 rows=3762 width=79) (actual time=31030.734..31030.739 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue14.supplier_no) Buffers: shared hit=440564 read=888348 dirtied=647 written=299 InitPlan 1 (returns $0) -> Aggregate (cost=1179924.42..1179924.43 rows=1 width=8) (actual time=16041.959..16041.959 rows=1 loops=1) Buffers: shared hit=131233 read=532662 -> HashAggregate (cost=1179839.77..1179877.39 rows=3762 width=12) (actual time=15970.089..16030.985 rows=100000 loops=1) Buffers: shared hit=131233 read=532662 -> Bitmap Heap Scan on lineitem (cost=48026.22..1157104.75 rows=2273502 width=12) (actual time=1795.890..12044.838 rows=2247668 loops=1) Recheck Cond: ((l_shipdate >= '1995-07-01'::date) AND (l_shipdate < '1995-09-29 00:00:00'::timestamp without time zone)) Buffers: shared hit=131233 read=532662 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47457.85 rows=2273502 width=0) (actual time=1424.127..1424.127 rows=2265848 loops=1) Index Cond: ((l_shipdate >= '1995-07-01'::date) AND (l_shipdate < '1995-09-29 00:00:00'::timestamp without time zone)) Buffers: shared read=6139 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.099..17.220 rows=40959 loops=1) Buffers: shared hit=1120 read=1 -> Sort (cost=1197199.10..1197208.50 rows=3762 width=12) (actual time=31009.092..31009.093 rows=1 loops=1) Sort Key: revenue14.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=439444 read=888347 dirtied=647 written=299 -> Subquery Scan on revenue14 (cost=1196891.04..1196975.68 rows=3762 width=12) (actual time=31003.146..31009.059 rows=1 loops=1) Buffers: shared hit=439444 read=888347 dirtied=647 written=299 -> HashAggregate (cost=1196891.04..1196938.06 rows=3762 width=12) (actual time=31003.143..31009.054 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=439444 read=888347 dirtied=647 written=299 -> Bitmap Heap Scan on lineitem (cost=48026.22..1157104.75 rows=2273502 width=12) (actual time=1751.380..11086.266 rows=2247668 loops=1) Recheck Cond: ((l_shipdate >= '1995-07-01'::date) AND (l_shipdate < '1995-09-29 00:00:00'::timestamp without time zone)) Buffers: shared hit=308211 read=355685 dirtied=647 written=299 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47457.85 rows=2273502 width=0) (actual time=1378.359..1378.359 rows=2265848 loops=1) Index Cond: ((l_shipdate >= '1995-07-01'::date) AND (l_shipdate < '1995-09-29 00:00:00'::timestamp without time zone)) Buffers: shared read=6140 Total runtime: 31045.749 ms (33 rows) drop view revenue14; DROP VIEW COMMIT; COMMIT