BEGIN; BEGIN create or replace view revenue16 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1995-06-01' and l_shipdate < date'1995-06-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, revenue16 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue16 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2378148.26..2383245.19 rows=3698 width=79) (actual time=101426.963..101426.965 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue16.supplier_no) Buffers: shared hit=441567 read=890545 written=2361 InitPlan 1 (returns $0) -> Aggregate (cost=1180557.77..1180557.78 rows=1 width=8) (actual time=51712.344..51712.344 rows=1 loops=1) Buffers: shared hit=206792 read=458302 written=83 -> HashAggregate (cost=1180474.56..1180511.54 rows=3698 width=12) (actual time=51646.021..51700.290 rows=100000 loops=1) Buffers: shared hit=206792 read=458302 written=83 -> Bitmap Heap Scan on lineitem (cost=47309.36..1158056.48 rows=2241808 width=12) (actual time=2582.404..46770.446 rows=2246035 loops=1) Recheck Cond: ((l_shipdate >= '1995-06-01'::date) AND (l_shipdate < '1995-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=206792 read=458302 written=83 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46748.91 rows=2241808 width=0) (actual time=2144.680..2144.680 rows=2268791 loops=1) Index Cond: ((l_shipdate >= '1995-06-01'::date) AND (l_shipdate < '1995-08-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6135 written=1 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.076..90.605 rows=70652 loops=1) Buffers: shared hit=1923 -> Sort (cost=1197590.48..1197599.72 rows=3698 width=12) (actual time=101324.678..101324.679 rows=1 loops=1) Sort Key: revenue16.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=439644 read=890545 written=2361 -> Subquery Scan on revenue16 (cost=1197288.12..1197371.33 rows=3698 width=12) (actual time=101278.246..101324.626 rows=1 loops=1) Buffers: shared hit=439644 read=890545 written=2361 -> HashAggregate (cost=1197288.12..1197334.35 rows=3698 width=12) (actual time=101278.242..101324.616 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=439644 read=890545 written=2361 -> Bitmap Heap Scan on lineitem (cost=47309.36..1158056.48 rows=2241808 width=12) (actual time=2268.790..44460.750 rows=2246035 loops=1) Recheck Cond: ((l_shipdate >= '1995-06-01'::date) AND (l_shipdate < '1995-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=232852 read=432243 written=2278 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46748.91 rows=2241808 width=0) (actual time=1843.835..1843.835 rows=2268791 loops=1) Index Cond: ((l_shipdate >= '1995-06-01'::date) AND (l_shipdate < '1995-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=6136 Total runtime: 101443.325 ms (33 rows) drop view revenue16; DROP VIEW COMMIT; COMMIT