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 >= '1996-07-01' and l_shipdate < date'1996-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, revenue8 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue8 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2361128.36..2366225.68 rows=3724 width=79) (actual time=31182.696..31182.700 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue8.supplier_no) Buffers: shared hit=861322 read=459085 dirtied=330 written=937 InitPlan 1 (returns $0) -> Aggregate (cost=1172061.51..1172061.52 rows=1 width=8) (actual time=13957.260..13957.260 rows=1 loops=1) Buffers: shared hit=471718 read=187653 -> HashAggregate (cost=1171977.72..1172014.96 rows=3724 width=12) (actual time=13880.966..13938.982 rows=100000 loops=1) Buffers: shared hit=471718 read=187653 -> Bitmap Heap Scan on lineitem (cost=47421.57..1149598.46 rows=2237926 width=12) (actual time=3505.304..10600.112 rows=2245790 loops=1) Recheck Cond: ((l_shipdate >= '1996-07-01'::date) AND (l_shipdate < '1996-09-29 00:00:00'::timestamp without time zone)) Buffers: shared hit=471718 read=187653 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46862.09 rows=2237926 width=0) (actual time=3017.453..3017.453 rows=2250224 loops=1) Index Cond: ((l_shipdate >= '1996-07-01'::date) AND (l_shipdate < '1996-09-29 00:00:00'::timestamp without time zone)) Buffers: shared hit=6131 read=3 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.070..28.840 rows=60982 loops=1) Buffers: shared hit=169 read=1495 -> Sort (cost=1189066.84..1189076.15 rows=3724 width=12) (actual time=31146.689..31146.690 rows=1 loops=1) Sort Key: revenue8.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=861153 read=457590 dirtied=330 written=937 -> Subquery Scan on revenue8 (cost=1188762.17..1188845.96 rows=3724 width=12) (actual time=31091.091..31146.655 rows=1 loops=1) Buffers: shared hit=861153 read=457590 dirtied=330 written=937 -> HashAggregate (cost=1188762.17..1188808.72 rows=3724 width=12) (actual time=31091.089..31146.652 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=861153 read=457590 dirtied=330 written=937 -> Bitmap Heap Scan on lineitem (cost=47421.57..1149598.46 rows=2237926 width=12) (actual time=4240.646..13326.663 rows=2245790 loops=1) Recheck Cond: ((l_shipdate >= '1996-07-01'::date) AND (l_shipdate < '1996-09-29 00:00:00'::timestamp without time zone)) Buffers: shared hit=389435 read=269937 dirtied=330 written=937 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46862.09 rows=2237926 width=0) (actual time=3767.467..3767.467 rows=2250224 loops=1) Index Cond: ((l_shipdate >= '1996-07-01'::date) AND (l_shipdate < '1996-09-29 00:00:00'::timestamp without time zone)) Buffers: shared hit=130 read=6005 written=400 Total runtime: 31206.199 ms (33 rows) drop view revenue8; DROP VIEW COMMIT; COMMIT