BEGIN; BEGIN create or replace view revenue5 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1993-09-01' and l_shipdate < date'1993-09-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, revenue5 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue5 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2360748.75..2365845.98 rows=3718 width=79) (actual time=27152.063..27152.067 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue5.supplier_no) Buffers: shared hit=579506 read=742290 written=303 InitPlan 1 (returns $0) -> Aggregate (cost=1171885.89..1171885.90 rows=1 width=8) (actual time=11983.938..11983.938 rows=1 loops=1) Buffers: shared hit=361135 read=298770 written=99 -> HashAggregate (cost=1171802.24..1171839.42 rows=3718 width=12) (actual time=11932.290..11972.996 rows=100000 loops=1) Buffers: shared hit=361135 read=298770 written=99 -> Bitmap Heap Scan on lineitem (cost=47339.34..1149460.28 rows=2234196 width=12) (actual time=1467.714..8593.679 rows=2248874 loops=1) Recheck Cond: ((l_shipdate >= '1993-09-01'::date) AND (l_shipdate < '1993-11-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=361135 read=298770 written=99 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46780.79 rows=2234196 width=0) (actual time=993.124..993.124 rows=2253113 loops=1) Index Cond: ((l_shipdate >= '1993-09-01'::date) AND (l_shipdate < '1993-11-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6141 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.080..30.374 rows=72980 loops=1) Buffers: shared hit=1604 read=381 -> Sort (cost=1188862.85..1188872.14 rows=3718 width=12) (actual time=27114.137..27114.139 rows=1 loops=1) Sort Key: revenue5.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=577902 read=741909 written=303 -> Subquery Scan on revenue5 (cost=1188558.71..1188642.36 rows=3718 width=12) (actual time=27086.556..27114.106 rows=1 loops=1) Buffers: shared hit=577902 read=741909 written=303 -> HashAggregate (cost=1188558.71..1188605.18 rows=3718 width=12) (actual time=27086.553..27114.101 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=577902 read=741909 written=303 -> Bitmap Heap Scan on lineitem (cost=47339.34..1149460.28 rows=2234196 width=12) (actual time=2183.972..11534.367 rows=2248874 loops=1) Recheck Cond: ((l_shipdate >= '1993-09-01'::date) AND (l_shipdate < '1993-11-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=216767 read=443139 written=204 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46780.79 rows=2234196 width=0) (actual time=1721.605..1721.605 rows=2253113 loops=1) Index Cond: ((l_shipdate >= '1993-09-01'::date) AND (l_shipdate < '1993-11-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6142 Total runtime: 27164.909 ms (33 rows) drop view revenue5; DROP VIEW COMMIT; COMMIT