BEGIN; BEGIN create or replace view revenue14 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1993-10-01' and l_shipdate < date'1993-10-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, revenue14 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue14 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2374503.25..2379600.44 rows=3715 width=79) (actual time=48096.995..48096.999 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue14.supplier_no) Buffers: shared hit=475651 read=851765 written=5079 InitPlan 1 (returns $0) -> Aggregate (cost=1178714.26..1178714.27 rows=1 width=8) (actual time=22173.196..22173.196 rows=1 loops=1) Buffers: shared hit=216255 read=447159 written=5079 -> HashAggregate (cost=1178630.67..1178667.82 rows=3715 width=12) (actual time=22092.731..22154.024 rows=100000 loops=1) Buffers: shared hit=216255 read=447159 written=5079 -> Bitmap Heap Scan on lineitem (cost=47473.22..1156158.09 rows=2247258 width=12) (actual time=2631.994..18235.133 rows=2246324 loops=1) Recheck Cond: ((l_shipdate >= '1993-10-01'::date) AND (l_shipdate < '1993-12-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=216255 read=447159 written=5079 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46911.41 rows=2247258 width=0) (actual time=2223.973..2223.973 rows=2263757 loops=1) Index Cond: ((l_shipdate >= '1993-10-01'::date) AND (l_shipdate < '1993-12-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6134 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.234..13.874 rows=20959 loops=1) Buffers: shared hit=587 -> Sort (cost=1195788.98..1195798.27 rows=3715 width=12) (actual time=48079.387..48079.388 rows=1 loops=1) Sort Key: revenue14.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=475064 read=851765 written=5079 -> Subquery Scan on revenue14 (cost=1195485.11..1195568.70 rows=3715 width=12) (actual time=48044.895..48079.342 rows=1 loops=1) Buffers: shared hit=475064 read=851765 written=5079 -> HashAggregate (cost=1195485.11..1195531.55 rows=3715 width=12) (actual time=48044.892..48079.336 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=475064 read=851765 written=5079 -> Bitmap Heap Scan on lineitem (cost=47473.22..1156158.09 rows=2247258 width=12) (actual time=2382.262..21496.151 rows=2246324 loops=1) Recheck Cond: ((l_shipdate >= '1993-10-01'::date) AND (l_shipdate < '1993-12-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=258809 read=404606 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46911.41 rows=2247258 width=0) (actual time=2035.908..2035.908 rows=2263757 loops=1) Index Cond: ((l_shipdate >= '1993-10-01'::date) AND (l_shipdate < '1993-12-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6135 Total runtime: 48114.831 ms (33 rows) drop view revenue14; DROP VIEW COMMIT; COMMIT