BEGIN; BEGIN create or replace view revenue5 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1996-03-01' and l_shipdate < date'1996-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, revenue5 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue5 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2363459.13..2368556.95 rows=3757 width=79) (actual time=34888.104..34888.108 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue5.supplier_no) Buffers: shared hit=578266 read=741562 InitPlan 1 (returns $0) -> Aggregate (cost=1173138.15..1173138.16 rows=1 width=8) (actual time=15869.404..15869.404 rows=1 loops=1) Buffers: shared hit=326527 read=332811 -> HashAggregate (cost=1173053.62..1173091.19 rows=3757 width=12) (actual time=15771.140..15852.862 rows=100000 loops=1) Buffers: shared hit=326527 read=332811 -> Bitmap Heap Scan on lineitem (cost=47913.14..1150440.63 rows=2261299 width=12) (actual time=2218.788..12001.265 rows=2244694 loops=1) Recheck Cond: ((l_shipdate >= '1996-03-01'::date) AND (l_shipdate < '1996-05-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=326527 read=332811 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47347.82 rows=2261299 width=0) (actual time=1439.501..1439.501 rows=2249030 loops=1) Index Cond: ((l_shipdate >= '1996-03-01'::date) AND (l_shipdate < '1996-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.054..18.388 rows=41964 loops=1) Buffers: shared hit=1150 read=1 -> Sort (cost=1190320.97..1190330.37 rows=3757 width=12) (actual time=34865.302..34865.302 rows=1 loops=1) Sort Key: revenue5.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=577116 read=741561 -> Subquery Scan on revenue5 (cost=1190013.36..1190097.89 rows=3757 width=12) (actual time=34837.597..34865.269 rows=1 loops=1) Buffers: shared hit=577116 read=741561 -> HashAggregate (cost=1190013.36..1190060.32 rows=3757 width=12) (actual time=34837.595..34865.265 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=577116 read=741561 -> Bitmap Heap Scan on lineitem (cost=47913.14..1150440.63 rows=2261299 width=12) (actual time=2859.563..14853.874 rows=2244694 loops=1) Recheck Cond: ((l_shipdate >= '1996-03-01'::date) AND (l_shipdate < '1996-05-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=250589 read=408750 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47347.82 rows=2261299 width=0) (actual time=2197.168..2197.168 rows=2249030 loops=1) Index Cond: ((l_shipdate >= '1996-03-01'::date) AND (l_shipdate < '1996-05-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6132 Total runtime: 34904.650 ms (33 rows) drop view revenue5; DROP VIEW COMMIT; COMMIT