BEGIN; BEGIN create or replace view revenue4 (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, revenue4 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue4 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2366446.95..2371544.89 rows=3765 width=79) (actual time=48972.490..48972.493 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue4.supplier_no) Buffers: shared hit=172521 read=1150863 dirtied=1 written=34126 InitPlan 1 (returns $0) -> Aggregate (cost=1174597.23..1174597.24 rows=1 width=8) (actual time=26976.623..26976.623 rows=1 loops=1) Buffers: shared hit=118285 read=542899 dirtied=1 written=34126 -> HashAggregate (cost=1174512.52..1174550.17 rows=3765 width=12) (actual time=26871.667..26959.290 rows=100000 loops=1) Buffers: shared hit=118285 read=542899 dirtied=1 written=34126 -> Bitmap Heap Scan on lineitem (cost=48083.62..1151807.36 rows=2270516 width=12) (actual time=2304.524..22198.071 rows=2248280 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=118285 read=542899 dirtied=1 written=34126 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47515.99 rows=2270516 width=0) (actual time=1885.994..1885.994 rows=2255106 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=1 read=6140 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.077..17.362 rows=37000 loops=1) Buffers: shared hit=1015 -> Sort (cost=1191849.71..1191859.12 rows=3765 width=12) (actual time=48951.057..48951.058 rows=1 loops=1) Sort Key: revenue4.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=171506 read=1150863 dirtied=1 written=34126 -> Subquery Scan on revenue4 (cost=1191541.39..1191626.10 rows=3765 width=12) (actual time=48950.890..48951.029 rows=1 loops=1) Buffers: shared hit=171506 read=1150863 dirtied=1 written=34126 -> HashAggregate (cost=1191541.39..1191588.45 rows=3765 width=12) (actual time=48950.889..48951.027 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=171506 read=1150863 dirtied=1 written=34126 -> Bitmap Heap Scan on lineitem (cost=48083.62..1151807.36 rows=2270516 width=12) (actual time=2576.107..17975.740 rows=2248280 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=53221 read=607964 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47515.99 rows=2270516 width=0) (actual time=2105.120..2105.120 rows=2255105 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 read=6142 Total runtime: 48991.534 ms (33 rows) drop view revenue4; DROP VIEW COMMIT; COMMIT