BEGIN; BEGIN create or replace view revenue8 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-03-01' and l_shipdate < date'1994-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, revenue8 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue8 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2363368.58..2368466.37 rows=3755 width=79) (actual time=34569.980..34569.984 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue8.supplier_no) Buffers: shared hit=703149 read=616316 dirtied=352 written=40 InitPlan 1 (returns $0) -> Aggregate (cost=1173096.51..1173096.52 rows=1 width=8) (actual time=16214.841..16214.842 rows=1 loops=1) Buffers: shared hit=377297 read=281697 -> HashAggregate (cost=1173012.03..1173049.58 rows=3755 width=12) (actual time=16127.100..16200.062 rows=100000 loops=1) Buffers: shared hit=377297 read=281697 -> Bitmap Heap Scan on lineitem (cost=47895.38..1150408.57 rows=2260346 width=12) (actual time=2106.651..12009.109 rows=2244801 loops=1) Recheck Cond: ((l_shipdate >= '1994-03-01'::date) AND (l_shipdate < '1994-05-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=377297 read=281697 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47330.29 rows=2260346 width=0) (actual time=1614.313..1614.313 rows=2249540 loops=1) Index Cond: ((l_shipdate >= '1994-03-01'::date) AND (l_shipdate < '1994-05-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6131 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.042..23.396 rows=53995 loops=1) Buffers: shared hit=1476 -> Sort (cost=1190272.05..1190281.44 rows=3755 width=12) (actual time=34540.936..34540.937 rows=1 loops=1) Sort Key: revenue8.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=701673 read=616316 dirtied=352 written=40 -> Subquery Scan on revenue8 (cost=1189964.62..1190049.11 rows=3755 width=12) (actual time=34533.328..34540.905 rows=1 loops=1) Buffers: shared hit=701673 read=616316 dirtied=352 written=40 -> HashAggregate (cost=1189964.62..1190011.56 rows=3755 width=12) (actual time=34533.324..34540.901 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=701673 read=616316 dirtied=352 written=40 -> Bitmap Heap Scan on lineitem (cost=47895.38..1150408.57 rows=2260346 width=12) (actual time=2868.146..14348.904 rows=2244801 loops=1) Recheck Cond: ((l_shipdate >= '1994-03-01'::date) AND (l_shipdate < '1994-05-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=324376 read=334619 dirtied=352 written=40 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47330.29 rows=2260346 width=0) (actual time=2473.815..2473.815 rows=2249540 loops=1) Index Cond: ((l_shipdate >= '1994-03-01'::date) AND (l_shipdate < '1994-05-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=4 read=6128 written=15 Total runtime: 34590.631 ms (33 rows) drop view revenue8; DROP VIEW COMMIT; COMMIT