BEGIN; BEGIN create or replace view revenue2 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-09-01' and l_shipdate < date'1994-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, revenue2 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue2 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2368726.92..2373824.27 rows=3726 width=79) (actual time=48645.553..48645.560 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue2.supplier_no) Buffers: shared hit=370763 read=954715 written=410 InitPlan 1 (returns $0) -> Aggregate (cost=1175809.46..1175809.47 rows=1 width=8) (actual time=24088.413..24088.414 rows=1 loops=1) Buffers: shared hit=145679 read=516404 written=297 -> HashAggregate (cost=1175725.62..1175762.88 rows=3726 width=12) (actual time=23989.359..24072.272 rows=100000 loops=1) Buffers: shared hit=145679 read=516404 written=297 -> Bitmap Heap Scan on lineitem (cost=47637.70..1153209.65 rows=2251597 width=12) (actual time=1789.976..19520.228 rows=2244870 loops=1) Recheck Cond: ((l_shipdate >= '1994-09-01'::date) AND (l_shipdate < '1994-11-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=145679 read=516404 written=297 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47074.80 rows=2251597 width=0) (actual time=1500.437..1500.437 rows=2256375 loops=1) Index Cond: ((l_shipdate >= '1994-09-01'::date) AND (l_shipdate < '1994-11-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6132 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.174..23.488 rows=47970 loops=1) Buffers: shared hit=1310 read=1 -> Sort (cost=1192917.45..1192926.77 rows=3726 width=12) (actual time=48616.813..48616.816 rows=1 loops=1) Sort Key: revenue2.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=369453 read=954714 written=410 -> Subquery Scan on revenue2 (cost=1192612.60..1192696.44 rows=3726 width=12) (actual time=48613.863..48616.744 rows=1 loops=1) Buffers: shared hit=369453 read=954714 written=410 -> HashAggregate (cost=1192612.60..1192659.18 rows=3726 width=12) (actual time=48613.858..48616.738 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=369453 read=954714 written=410 -> Bitmap Heap Scan on lineitem (cost=47637.70..1153209.65 rows=2251597 width=12) (actual time=2416.127..20129.965 rows=2244870 loops=1) Recheck Cond: ((l_shipdate >= '1994-09-01'::date) AND (l_shipdate < '1994-11-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=223774 read=438310 written=113 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47074.80 rows=2251597 width=0) (actual time=2014.831..2014.831 rows=2256375 loops=1) Index Cond: ((l_shipdate >= '1994-09-01'::date) AND (l_shipdate < '1994-11-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6133 Total runtime: 48660.590 ms (33 rows) drop view revenue2; DROP VIEW COMMIT; COMMIT