BEGIN; BEGIN create or replace view revenue4 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1997-02-01' and l_shipdate < date'1997-02-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, revenue4 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue4 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2367103.71..2372201.91 rows=3783 width=79) (actual time=68857.824..68857.826 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue4.supplier_no) Buffers: shared hit=190186 read=1133392 written=36455 InitPlan 1 (returns $0) -> Aggregate (cost=1174900.45..1174900.46 rows=1 width=8) (actual time=33536.831..33536.831 rows=1 loops=1) Buffers: shared hit=69932 read=590837 written=36341 -> HashAggregate (cost=1174815.34..1174853.17 rows=3783 width=12) (actual time=33455.517..33518.949 rows=100000 loops=1) Buffers: shared hit=69932 read=590837 written=36341 -> Bitmap Heap Scan on lineitem (cost=48222.74..1152044.70 rows=2277064 width=12) (actual time=3011.392..29017.032 rows=2249672 loops=1) Recheck Cond: ((l_shipdate >= '1997-02-01'::date) AND (l_shipdate < '1997-05-02 00:00:00'::timestamp without time zone)) Buffers: shared hit=69932 read=590837 written=36341 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47653.47 rows=2277064 width=0) (actual time=2566.831..2566.831 rows=2257752 loops=1) Index Cond: ((l_shipdate >= '1997-02-01'::date) AND (l_shipdate < '1997-05-02 00:00:00'::timestamp without time zone)) Buffers: shared hit=1075 read=5069 written=402 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.106..50.950 rows=74945 loops=1) Buffers: shared hit=2039 -> Sort (cost=1192203.24..1192212.70 rows=3783 width=12) (actual time=68795.036..68795.037 rows=1 loops=1) Sort Key: revenue4.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=188147 read=1133392 written=36455 -> Subquery Scan on revenue4 (cost=1191893.32..1191978.43 rows=3783 width=12) (actual time=68764.843..68795.000 rows=1 loops=1) Buffers: shared hit=188147 read=1133392 written=36455 -> HashAggregate (cost=1191893.32..1191940.60 rows=3783 width=12) (actual time=68764.841..68794.995 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=188147 read=1133392 written=36455 -> Bitmap Heap Scan on lineitem (cost=48222.74..1152044.70 rows=2277064 width=12) (actual time=2648.180..30354.931 rows=2249672 loops=1) Recheck Cond: ((l_shipdate >= '1997-02-01'::date) AND (l_shipdate < '1997-05-02 00:00:00'::timestamp without time zone)) Buffers: shared hit=118215 read=542555 written=114 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47653.47 rows=2277064 width=0) (actual time=2136.902..2136.902 rows=2256459 loops=1) Index Cond: ((l_shipdate >= '1997-02-01'::date) AND (l_shipdate < '1997-05-02 00:00:00'::timestamp without time zone)) Buffers: shared hit=2 read=6143 Total runtime: 68888.441 ms (33 rows) drop view revenue4; DROP VIEW COMMIT; COMMIT