BEGIN; BEGIN create or replace view revenue17 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1993-03-01' and l_shipdate < date'1993-03-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, revenue17 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue17 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2377591.42..2382689.36 rows=3765 width=79) (actual time=112234.863..112234.865 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue17.supplier_no) Buffers: shared hit=391162 read=939904 written=17776 InitPlan 1 (returns $0) -> Aggregate (cost=1180140.79..1180140.80 rows=1 width=8) (actual time=56674.513..56674.514 rows=1 loops=1) Buffers: shared hit=193966 read=470681 written=17348 -> HashAggregate (cost=1180056.07..1180093.72 rows=3765 width=12) (actual time=56602.615..56662.261 rows=100000 loops=1) Buffers: shared hit=193966 read=470681 written=17348 -> Bitmap Heap Scan on lineitem (cost=48126.00..1157274.44 rows=2278163 width=12) (actual time=2756.421..51567.597 rows=2250196 loops=1) Recheck Cond: ((l_shipdate >= '1993-03-01'::date) AND (l_shipdate < '1993-05-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=193966 read=470681 written=17348 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47556.46 rows=2278163 width=0) (actual time=2413.171..2413.171 rows=2268475 loops=1) Index Cond: ((l_shipdate >= '1993-03-01'::date) AND (l_shipdate < '1993-05-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=527 read=5617 written=354 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.092..73.771 rows=64983 loops=1) Buffers: shared hit=1771 -> Sort (cost=1197450.62..1197460.03 rows=3765 width=12) (actual time=112150.369..112150.370 rows=1 loops=1) Sort Key: revenue17.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=389391 read=939904 written=17776 -> Subquery Scan on revenue17 (cost=1197142.30..1197227.01 rows=3765 width=12) (actual time=112115.597..112150.329 rows=1 loops=1) Buffers: shared hit=389391 read=939904 written=17776 -> HashAggregate (cost=1197142.30..1197189.36 rows=3765 width=12) (actual time=112115.595..112150.325 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=389391 read=939904 written=17776 -> Bitmap Heap Scan on lineitem (cost=48126.00..1157274.44 rows=2278163 width=12) (actual time=3136.410..50222.779 rows=2250196 loops=1) Recheck Cond: ((l_shipdate >= '1993-03-01'::date) AND (l_shipdate < '1993-05-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=195425 read=469223 written=428 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47556.46 rows=2278163 width=0) (actual time=2626.911..2626.911 rows=2267835 loops=1) Index Cond: ((l_shipdate >= '1993-03-01'::date) AND (l_shipdate < '1993-05-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6145 Total runtime: 112247.862 ms (33 rows) drop view revenue17; DROP VIEW COMMIT; COMMIT