BEGIN; BEGIN create or replace view revenue9 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1997-03-01' and l_shipdate < date'1997-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, revenue9 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue9 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2369217.03..2374314.09 rows=3707 width=79) (actual time=30768.146..30768.148 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue9.supplier_no) Buffers: shared hit=599890 read=726614 dirtied=1054 written=459 InitPlan 1 (returns $0) -> Aggregate (cost=1176114.36..1176114.37 rows=1 width=8) (actual time=15606.619..15606.619 rows=1 loops=1) Buffers: shared hit=267871 read=395241 written=9 -> HashAggregate (cost=1176030.96..1176068.03 rows=3707 width=12) (actual time=15533.134..15595.128 rows=100000 loops=1) Buffers: shared hit=267871 read=395241 written=9 -> Bitmap Heap Scan on lineitem (cost=47279.83..1153672.91 rows=2235805 width=12) (actual time=2171.610..11527.512 rows=2250161 loops=1) Recheck Cond: ((l_shipdate >= '1997-03-01'::date) AND (l_shipdate < '1997-05-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=267871 read=395241 written=9 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46720.88 rows=2235805 width=0) (actual time=1732.504..1732.504 rows=2263501 loops=1) Index Cond: ((l_shipdate >= '1997-03-01'::date) AND (l_shipdate < '1997-05-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6145 written=6 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.086..4.122 rows=9914 loops=1) Buffers: shared hit=279 -> Sort (cost=1193102.65..1193111.92 rows=3707 width=12) (actual time=30762.973..30762.973 rows=1 loops=1) Sort Key: revenue9.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=599611 read=726614 dirtied=1054 written=459 -> Subquery Scan on revenue9 (cost=1192799.49..1192882.90 rows=3707 width=12) (actual time=30741.869..30762.918 rows=1 loops=1) Buffers: shared hit=599611 read=726614 dirtied=1054 written=459 -> HashAggregate (cost=1192799.49..1192845.83 rows=3707 width=12) (actual time=30741.868..30762.916 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=599611 read=726614 dirtied=1054 written=459 -> Bitmap Heap Scan on lineitem (cost=47279.83..1153672.91 rows=2235805 width=12) (actual time=1613.915..11278.460 rows=2250161 loops=1) Recheck Cond: ((l_shipdate >= '1997-03-01'::date) AND (l_shipdate < '1997-05-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=331740 read=331373 dirtied=1054 written=450 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46720.88 rows=2235805 width=0) (actual time=1316.446..1316.446 rows=2263501 loops=1) Index Cond: ((l_shipdate >= '1997-03-01'::date) AND (l_shipdate < '1997-05-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6146 Total runtime: 30780.473 ms (33 rows) drop view revenue9; DROP VIEW COMMIT; COMMIT