BEGIN; BEGIN create or replace view revenue10 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-12-01' and l_shipdate < date'1994-12-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, revenue10 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue10 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2361099.50..2366197.41 rows=3763 width=79) (actual time=23441.425..23441.430 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue10.supplier_no) Buffers: shared hit=841197 read=479607 dirtied=209 written=378 InitPlan 1 (returns $0) -> Aggregate (cost=1171969.11..1171969.12 rows=1 width=8) (actual time=11573.303..11573.303 rows=1 loops=1) Buffers: shared hit=380022 read=279872 written=3 -> HashAggregate (cost=1171884.44..1171922.07 rows=3763 width=12) (actual time=11490.722..11562.340 rows=100000 loops=1) Buffers: shared hit=380022 read=279872 written=3 -> Bitmap Heap Scan on lineitem (cost=47879.14..1149300.72 rows=2258372 width=12) (actual time=2133.037..8130.146 rows=2248357 loops=1) Recheck Cond: ((l_shipdate >= '1994-12-01'::date) AND (l_shipdate < '1995-03-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=380022 read=279872 written=3 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47314.55 rows=2258372 width=0) (actual time=1652.735..1652.735 rows=2250604 loops=1) Index Cond: ((l_shipdate >= '1994-12-01'::date) AND (l_shipdate < '1995-03-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=2 read=6139 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.040..16.381 rows=37000 loops=1) Buffers: shared hit=129 read=886 -> Sort (cost=1189130.38..1189139.79 rows=3763 width=12) (actual time=23421.174..23421.176 rows=1 loops=1) Sort Key: revenue10.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=841068 read=478721 dirtied=209 written=378 -> Subquery Scan on revenue10 (cost=1188822.23..1188906.90 rows=3763 width=12) (actual time=23420.933..23421.147 rows=1 loops=1) Buffers: shared hit=841068 read=478721 dirtied=209 written=378 -> HashAggregate (cost=1188822.23..1188869.27 rows=3763 width=12) (actual time=23420.932..23421.145 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=841068 read=478721 dirtied=209 written=378 -> Bitmap Heap Scan on lineitem (cost=47879.14..1149300.72 rows=2258372 width=12) (actual time=1986.093..8545.849 rows=2248357 loops=1) Recheck Cond: ((l_shipdate >= '1994-12-01'::date) AND (l_shipdate < '1995-03-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=461046 read=198849 dirtied=209 written=375 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47314.55 rows=2258372 width=0) (actual time=1654.829..1654.829 rows=2250604 loops=1) Index Cond: ((l_shipdate >= '1994-12-01'::date) AND (l_shipdate < '1995-03-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=17 read=6125 Total runtime: 23456.752 ms (33 rows) drop view revenue10; DROP VIEW COMMIT; COMMIT