BEGIN; BEGIN create or replace view revenue19 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1996-11-01' and l_shipdate < date'1996-11-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, revenue19 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue19 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2366954.37..2372052.53 rows=3780 width=79) (actual time=73870.090..73870.093 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue19.supplier_no) Buffers: shared hit=579088 read=743589 written=63 InitPlan 1 (returns $0) -> Aggregate (cost=1174831.51..1174831.52 rows=1 width=8) (actual time=32997.358..32997.358 rows=1 loops=1) Buffers: shared hit=288016 read=372640 written=31 -> HashAggregate (cost=1174746.46..1174784.26 rows=3780 width=12) (actual time=32906.521..32978.571 rows=100000 loops=1) Buffers: shared hit=288016 read=372640 written=31 -> Bitmap Heap Scan on lineitem (cost=48191.36..1151990.82 rows=2275564 width=12) (actual time=2943.024..28325.035 rows=2246079 loops=1) Recheck Cond: ((l_shipdate >= '1996-11-01'::date) AND (l_shipdate < '1997-01-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=288016 read=372640 written=31 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47622.47 rows=2275564 width=0) (actual time=2491.777..2491.777 rows=2253051 loops=1) Index Cond: ((l_shipdate >= '1996-11-01'::date) AND (l_shipdate < '1997-01-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6138 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.077..68.605 rows=49906 loops=1) Buffers: shared hit=1364 -> Sort (cost=1192122.85..1192132.30 rows=3780 width=12) (actual time=73793.030..73793.031 rows=1 loops=1) Sort Key: revenue19.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=577724 read=743589 written=63 -> Subquery Scan on revenue19 (cost=1191813.19..1191898.24 rows=3780 width=12) (actual time=73771.146..73792.992 rows=1 loops=1) Buffers: shared hit=577724 read=743589 written=63 -> HashAggregate (cost=1191813.19..1191860.44 rows=3780 width=12) (actual time=73771.144..73792.988 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=577724 read=743589 written=63 -> Bitmap Heap Scan on lineitem (cost=48191.36..1151990.82 rows=2275564 width=12) (actual time=2605.368..35525.183 rows=2246079 loops=1) Recheck Cond: ((l_shipdate >= '1996-11-01'::date) AND (l_shipdate < '1997-01-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=289708 read=370949 written=32 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47622.47 rows=2275564 width=0) (actual time=2243.216..2243.216 rows=2253051 loops=1) Index Cond: ((l_shipdate >= '1996-11-01'::date) AND (l_shipdate < '1997-01-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6139 Total runtime: 73883.486 ms (33 rows) drop view revenue19; DROP VIEW COMMIT; COMMIT