BEGIN; BEGIN create or replace view revenue24 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1996-08-01' and l_shipdate < date'1996-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, revenue24 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue24 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2388786.96..2393885.38 rows=3797 width=79) (actual time=98521.392..98521.395 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue24.supplier_no) Buffers: shared hit=691515 read=642464 dirtied=665 written=9143 InitPlan 1 (returns $0) -> Aggregate (cost=1185631.53..1185631.54 rows=1 width=8) (actual time=52144.540..52144.540 rows=1 loops=1) Buffers: shared hit=313698 read=352445 written=9014 -> HashAggregate (cost=1185546.10..1185584.07 rows=3797 width=12) (actual time=52050.739..52128.433 rows=100000 loops=1) Buffers: shared hit=313698 read=352445 written=9014 -> Bitmap Heap Scan on lineitem (cost=48623.62..1162481.91 rows=2306419 width=12) (actual time=2948.913..47005.698 rows=2247415 loops=1) Recheck Cond: ((l_shipdate >= '1996-08-01'::date) AND (l_shipdate < '1996-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=313698 read=352445 written=9014 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..48047.02 rows=2306419 width=0) (actual time=2511.309..2511.309 rows=2274343 loops=1) Index Cond: ((l_shipdate >= '1996-08-01'::date) AND (l_shipdate < '1996-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=1 read=6137 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.060..69.264 rows=61965 loops=1) Buffers: shared hit=1692 -> Sort (cost=1203155.42..1203164.91 rows=3797 width=12) (actual time=98441.145..98441.146 rows=1 loops=1) Sort Key: revenue24.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=689823 read=642464 dirtied=665 written=9143 -> Subquery Scan on revenue24 (cost=1202844.24..1202929.67 rows=3797 width=12) (actual time=98398.332..98441.105 rows=1 loops=1) Buffers: shared hit=689823 read=642464 dirtied=665 written=9143 -> HashAggregate (cost=1202844.24..1202891.70 rows=3797 width=12) (actual time=98398.331..98441.102 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=689823 read=642464 dirtied=665 written=9143 -> Bitmap Heap Scan on lineitem (cost=48623.62..1162481.91 rows=2306419 width=12) (actual time=2988.696..41592.866 rows=2247415 loops=1) Recheck Cond: ((l_shipdate >= '1996-08-01'::date) AND (l_shipdate < '1996-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=376125 read=290019 dirtied=665 written=129 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..48047.02 rows=2306419 width=0) (actual time=2575.625..2575.625 rows=2274343 loops=1) Index Cond: ((l_shipdate >= '1996-08-01'::date) AND (l_shipdate < '1996-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=2 read=6137 Total runtime: 98535.178 ms (33 rows) drop view revenue24; DROP VIEW COMMIT; COMMIT