BEGIN; BEGIN create or replace view revenue5 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1996-04-01' and l_shipdate < date'1996-04-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, revenue5 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue5 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2358078.52..2363175.03 rows=3670 width=79) (actual time=105267.267..105267.270 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue5.supplier_no) Buffers: shared hit=616549 read=703622 dirtied=1 written=10889 InitPlan 1 (returns $0) -> Aggregate (cost=1170652.41..1170652.42 rows=1 width=8) (actual time=44594.870..44594.870 rows=1 loops=1) Buffers: shared hit=419713 read=239811 dirtied=1 written=3910 -> HashAggregate (cost=1170569.84..1170606.54 rows=3670 width=12) (actual time=44515.908..44583.198 rows=100000 loops=1) Buffers: shared hit=419713 read=239811 dirtied=1 written=3910 -> Bitmap Heap Scan on lineitem (cost=46773.89..1148494.66 rows=2207518 width=12) (actual time=3211.634..39496.104 rows=2246466 loops=1) Recheck Cond: ((l_shipdate >= '1996-04-01'::date) AND (l_shipdate < '1996-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=419713 read=239811 dirtied=1 written=3910 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46222.01 rows=2207518 width=0) (actual time=2633.010..2633.010 rows=2252538 loops=1) Index Cond: ((l_shipdate >= '1996-04-01'::date) AND (l_shipdate < '1996-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=433 read=5702 written=215 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=3.070..48.168 rows=40980 loops=1) Buffers: shared hit=1121 read=1 -> Sort (cost=1187426.09..1187435.27 rows=3670 width=12) (actual time=105213.434..105213.435 rows=1 loops=1) Sort Key: revenue5.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=615428 read=703621 dirtied=1 written=10889 -> Subquery Scan on revenue5 (cost=1187126.22..1187208.80 rows=3670 width=12) (actual time=105204.492..105213.375 rows=1 loops=1) Buffers: shared hit=615428 read=703621 dirtied=1 written=10889 -> HashAggregate (cost=1187126.22..1187172.10 rows=3670 width=12) (actual time=105204.489..105213.370 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=615428 read=703621 dirtied=1 written=10889 -> Bitmap Heap Scan on lineitem (cost=46773.89..1148494.66 rows=2207518 width=12) (actual time=3075.504..55407.349 rows=2246466 loops=1) Recheck Cond: ((l_shipdate >= '1996-04-01'::date) AND (l_shipdate < '1996-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=195715 read=463810 written=6979 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46222.01 rows=2207518 width=0) (actual time=2717.174..2717.174 rows=2250787 loops=1) Index Cond: ((l_shipdate >= '1996-04-01'::date) AND (l_shipdate < '1996-06-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6136 Total runtime: 105284.781 ms (33 rows) drop view revenue5; DROP VIEW COMMIT; COMMIT