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-08-01' and l_shipdate < date'1996-08-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=2360468.76..2365565.93 rows=3714 width=79) (actual time=30013.134..30013.140 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue5.supplier_no) Buffers: shared hit=625655 read=695240 written=28 InitPlan 1 (returns $0) -> Aggregate (cost=1171756.78..1171756.79 rows=1 width=8) (actual time=15238.217..15238.217 rows=1 loops=1) Buffers: shared hit=281895 read=377706 written=12 -> HashAggregate (cost=1171673.21..1171710.35 rows=3714 width=12) (actual time=15139.425..15217.769 rows=100000 loops=1) Buffers: shared hit=281895 read=377706 written=12 -> Bitmap Heap Scan on lineitem (cost=47281.96..1149359.91 rows=2231330 width=12) (actual time=1694.634..11091.929 rows=2247146 loops=1) Recheck Cond: ((l_shipdate >= '1996-08-01'::date) AND (l_shipdate < '1996-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=281895 read=377706 written=12 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46724.13 rows=2231330 width=0) (actual time=1293.146..1293.146 rows=2251561 loops=1) Index Cond: ((l_shipdate >= '1996-08-01'::date) AND (l_shipdate < '1996-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=6135 read=3 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.088..27.498 rows=61965 loops=1) Buffers: shared hit=1691 read=1 -> Sort (cost=1188711.97..1188721.25 rows=3714 width=12) (actual time=29978.788..29978.790 rows=1 loops=1) Sort Key: revenue5.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=623964 read=695239 written=28 -> Subquery Scan on revenue5 (cost=1188408.19..1188491.75 rows=3714 width=12) (actual time=29934.319..29978.751 rows=1 loops=1) Buffers: shared hit=623964 read=695239 written=28 -> HashAggregate (cost=1188408.19..1188454.61 rows=3714 width=12) (actual time=29934.317..29978.746 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=623964 read=695239 written=28 -> Bitmap Heap Scan on lineitem (cost=47281.96..1149359.91 rows=2231330 width=12) (actual time=2095.565..11097.349 rows=2247146 loops=1) Recheck Cond: ((l_shipdate >= '1996-08-01'::date) AND (l_shipdate < '1996-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=342069 read=317533 written=16 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46724.13 rows=2231330 width=0) (actual time=1739.292..1739.292 rows=2251561 loops=1) Index Cond: ((l_shipdate >= '1996-08-01'::date) AND (l_shipdate < '1996-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=1 read=6138 Total runtime: 30023.786 ms (33 rows) drop view revenue5; DROP VIEW COMMIT; COMMIT