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 >= '1994-11-01' and l_shipdate < date'1994-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, revenue5 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue5 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2360054.73..2365151.75 rows=3704 width=79) (actual time=52578.817..52578.821 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue5.supplier_no) Buffers: shared hit=574963 read=746990 InitPlan 1 (returns $0) -> Aggregate (cost=1171565.33..1171565.34 rows=1 width=8) (actual time=24441.903..24441.903 rows=1 loops=1) Buffers: shared hit=249815 read=410437 -> HashAggregate (cost=1171481.99..1171519.03 rows=3704 width=12) (actual time=24373.581..24429.049 rows=100000 loops=1) Buffers: shared hit=249815 read=410437 -> Bitmap Heap Scan on lineitem (cost=47192.32..1149209.32 rows=2227267 width=12) (actual time=1570.944..20195.529 rows=2247161 loops=1) Recheck Cond: ((l_shipdate >= '1994-11-01'::date) AND (l_shipdate < '1995-01-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=249815 read=410437 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46635.50 rows=2227267 width=0) (actual time=1201.933..1201.933 rows=2251759 loops=1) Index Cond: ((l_shipdate >= '1994-11-01'::date) AND (l_shipdate < '1995-01-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6137 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.103..38.833 rows=52960 loops=1) Buffers: shared hit=1447 read=1 -> Sort (cost=1188489.39..1188498.65 rows=3704 width=12) (actual time=52532.929..52532.929 rows=1 loops=1) Sort Key: revenue5.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=573516 read=746989 -> Subquery Scan on revenue5 (cost=1188186.49..1188269.83 rows=3704 width=12) (actual time=52518.525..52532.891 rows=1 loops=1) Buffers: shared hit=573516 read=746989 -> HashAggregate (cost=1188186.49..1188232.79 rows=3704 width=12) (actual time=52518.523..52532.888 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=573516 read=746989 -> Bitmap Heap Scan on lineitem (cost=47192.32..1149209.32 rows=2227267 width=12) (actual time=2700.937..23704.287 rows=2247161 loops=1) Recheck Cond: ((l_shipdate >= '1994-11-01'::date) AND (l_shipdate < '1995-01-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=323701 read=336552 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46635.50 rows=2227267 width=0) (actual time=2255.895..2255.895 rows=2251759 loops=1) Index Cond: ((l_shipdate >= '1994-11-01'::date) AND (l_shipdate < '1995-01-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6138 Total runtime: 52598.342 ms (33 rows) drop view revenue5; DROP VIEW COMMIT; COMMIT