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-09-01' and l_shipdate < date'1997-09-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=2362118.00..2367215.68 rows=3748 width=79) (actual time=48892.626..48892.629 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue8.supplier_no) Buffers: shared hit=755618 read=565170 dirtied=270 written=5222 InitPlan 1 (returns $0) -> Aggregate (cost=1172496.74..1172496.75 rows=1 width=8) (actual time=22110.538..22110.538 rows=1 loops=1) Buffers: shared hit=355805 read=304173 written=46 -> HashAggregate (cost=1172412.41..1172449.89 rows=3748 width=12) (actual time=22033.179..22098.970 rows=100000 loops=1) Buffers: shared hit=355805 read=304173 written=46 -> Bitmap Heap Scan on lineitem (cost=47758.28..1149876.36 rows=2253605 width=12) (actual time=2532.745..17717.289 rows=2243246 loops=1) Recheck Cond: ((l_shipdate >= '1997-09-01'::date) AND (l_shipdate < '1997-11-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=355805 read=304173 written=46 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47194.88 rows=2253605 width=0) (actual time=2075.426..2075.426 rows=2249932 loops=1) Index Cond: ((l_shipdate >= '1997-09-01'::date) AND (l_shipdate < '1997-11-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6133 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.059..12.100 rows=29990 loops=1) Buffers: shared hit=831 -> Sort (cost=1189621.25..1189630.62 rows=3748 width=12) (actual time=48877.461..48877.462 rows=1 loops=1) Sort Key: revenue8.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=754787 read=565170 dirtied=270 written=5222 -> Subquery Scan on revenue8 (cost=1189314.44..1189398.77 rows=3748 width=12) (actual time=48856.857..48877.431 rows=1 loops=1) Buffers: shared hit=754787 read=565170 dirtied=270 written=5222 -> HashAggregate (cost=1189314.44..1189361.29 rows=3748 width=12) (actual time=48856.854..48877.426 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=754787 read=565170 dirtied=270 written=5222 -> Bitmap Heap Scan on lineitem (cost=47758.28..1149876.36 rows=2253605 width=12) (actual time=3752.948..22357.591 rows=2243246 loops=1) Recheck Cond: ((l_shipdate >= '1997-09-01'::date) AND (l_shipdate < '1997-11-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=398982 read=260997 dirtied=270 written=5176 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47194.88 rows=2253605 width=0) (actual time=3347.082..3347.082 rows=2249603 loops=1) Index Cond: ((l_shipdate >= '1997-09-01'::date) AND (l_shipdate < '1997-11-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=1543 read=4591 written=223 Total runtime: 48920.081 ms (33 rows) drop view revenue8; DROP VIEW COMMIT; COMMIT