BEGIN; BEGIN create or replace view revenue16 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-01-01' and l_shipdate < date'1994-01-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, revenue16 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue16 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2378311.70..2383409.26 rows=3740 width=79) (actual time=48356.400..48356.404 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue16.supplier_no) Buffers: shared hit=273974 read=1053863 written=188 InitPlan 1 (returns $0) -> Aggregate (cost=1180552.96..1180552.97 rows=1 width=8) (actual time=25544.985..25544.985 rows=1 loops=1) Buffers: shared hit=137834 read=525777 written=13 -> HashAggregate (cost=1180468.81..1180506.21 rows=3740 width=12) (actual time=25466.256..25525.979 rows=100000 loops=1) Buffers: shared hit=137834 read=525777 written=13 -> Bitmap Heap Scan on lineitem (cost=47810.06..1157823.71 rows=2264510 width=12) (actual time=1927.653..21529.949 rows=2244469 loops=1) Recheck Cond: ((l_shipdate >= '1994-01-01'::date) AND (l_shipdate < '1994-04-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=137834 read=525777 written=13 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47243.93 rows=2264510 width=0) (actual time=1432.118..1432.118 rows=2264645 loops=1) Index Cond: ((l_shipdate >= '1994-01-01'::date) AND (l_shipdate < '1994-04-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=2 read=6128 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.059..14.304 rows=21986 loops=1) Buffers: shared hit=614 -> Sort (cost=1197758.73..1197768.08 rows=3740 width=12) (actual time=48338.189..48338.189 rows=1 loops=1) Sort Key: revenue16.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=273360 read=1053863 written=188 -> Subquery Scan on revenue16 (cost=1197452.63..1197536.78 rows=3740 width=12) (actual time=48319.699..48338.145 rows=1 loops=1) Buffers: shared hit=273360 read=1053863 written=188 -> HashAggregate (cost=1197452.63..1197499.38 rows=3740 width=12) (actual time=48319.696..48338.137 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=273360 read=1053863 written=188 -> Bitmap Heap Scan on lineitem (cost=47810.06..1157823.71 rows=2264510 width=12) (actual time=2410.197..19116.129 rows=2244469 loops=1) Recheck Cond: ((l_shipdate >= '1994-01-01'::date) AND (l_shipdate < '1994-04-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=135526 read=528086 written=175 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47243.93 rows=2264510 width=0) (actual time=2001.884..2001.884 rows=2264645 loops=1) Index Cond: ((l_shipdate >= '1994-01-01'::date) AND (l_shipdate < '1994-04-01 00:00:00'::timestamp without time zone)) Buffers: shared read=6131 written=2 Total runtime: 48374.279 ms (33 rows) drop view revenue16; DROP VIEW COMMIT; COMMIT