BEGIN; BEGIN create or replace view revenue15 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1996-04-01' and l_shipdate < date'1996-04-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, revenue15 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue15 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2376975.93..2382073.15 rows=3717 width=79) (actual time=81480.593..81480.600 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue15.supplier_no) Buffers: shared hit=302671 read=1026668 dirtied=415 written=21978 InitPlan 1 (returns $0) -> Aggregate (cost=1179936.09..1179936.10 rows=1 width=8) (actual time=38630.376..38630.376 rows=1 loops=1) Buffers: shared hit=199392 read=464716 written=376 -> HashAggregate (cost=1179852.46..1179889.63 rows=3717 width=12) (actual time=38552.589..38615.633 rows=100000 loops=1) Buffers: shared hit=199392 read=464716 written=376 -> Bitmap Heap Scan on lineitem (cost=47528.71..1157341.36 rows=2251110 width=12) (actual time=2158.737..33714.112 rows=2246666 loops=1) Recheck Cond: ((l_shipdate >= '1996-04-01'::date) AND (l_shipdate < '1996-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=199392 read=464716 written=376 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46965.93 rows=2251110 width=0) (actual time=1724.811..1724.811 rows=2268788 loops=1) Index Cond: ((l_shipdate >= '1996-04-01'::date) AND (l_shipdate < '1996-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=6135 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.088..30.570 rows=40980 loops=1) Buffers: shared hit=1122 -> Sort (cost=1197039.83..1197049.12 rows=3717 width=12) (actual time=81443.674..81443.676 rows=1 loops=1) Sort Key: revenue15.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=301549 read=1026668 dirtied=415 written=21978 -> Subquery Scan on revenue15 (cost=1196735.78..1196819.41 rows=3717 width=12) (actual time=81438.403..81443.642 rows=1 loops=1) Buffers: shared hit=301549 read=1026668 dirtied=415 written=21978 -> HashAggregate (cost=1196735.78..1196782.24 rows=3717 width=12) (actual time=81438.401..81443.638 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=301549 read=1026668 dirtied=415 written=21978 -> Bitmap Heap Scan on lineitem (cost=47528.71..1157341.36 rows=2251110 width=12) (actual time=2239.357..37855.878 rows=2246666 loops=1) Recheck Cond: ((l_shipdate >= '1996-04-01'::date) AND (l_shipdate < '1996-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=102157 read=561952 dirtied=415 written=21602 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46965.93 rows=2251110 width=0) (actual time=1781.853..1781.853 rows=2266479 loops=1) Index Cond: ((l_shipdate >= '1996-04-01'::date) AND (l_shipdate < '1996-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=6132 read=4 Total runtime: 81494.864 ms (33 rows) drop view revenue15; DROP VIEW COMMIT; COMMIT